Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Refactor grid
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbo committed Oct 18, 2024
1 parent d4b34e0 commit cc640cc
Show file tree
Hide file tree
Showing 31 changed files with 459 additions and 462 deletions.
4 changes: 2 additions & 2 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const { cacheValue } = useCache()
const { currencyList } = storeToRefs(useCurrencyStore())
const { initProvider, reconnect } = useWalletConnectProvider()
const { formatMessage } = useIntl()
const { gridChainId, tempGridLayout } = storeToRefs(useGridStore())
const { gridChainId, tempGrid } = storeToRefs(useGridStore())
const setupTranslations = () => {
useIntl().setupIntl(defaultConfig)
Expand Down Expand Up @@ -117,7 +117,7 @@ const setupNetwork = async () => {
// reset temp grid layout if network is changed
if (gridChainId.value !== selectedChainId.value) {
tempGridLayout.value = []
tempGrid.value = []
}
gridChainId.value = selectedChainId.value
Expand Down
6 changes: 3 additions & 3 deletions components/ModalTemplateAddEditGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { SelectStringOption } from '@lukso/web-components'
const { modal, closeModal } = useModal()
const { formatMessage } = useIntl()
const { tempGridLayout, selectedLayoutId } = storeToRefs(useGridStore())
const { tempGrid, selectedGridId } = storeToRefs(useGridStore())
const { addGrid, updateGrid } = useGrid()
const INPUT_FOCUS_DELAY = 10 // small delay for focusing input after element render
Expand Down Expand Up @@ -73,13 +73,13 @@ const handleSave = () => {
})
} else {
const newGrid: Grid<GridWidget> = {
id: createGridId<GridWidget>(grid, tempGridLayout.value),
id: createGridId<GridWidget>(grid, tempGrid.value),
...grid,
grid: [],
}
addGrid(newGrid)
selectedLayoutId.value = newGrid.id
selectedGridId.value = newGrid.id
}
handleCancel()
Expand Down
4 changes: 2 additions & 2 deletions components/ModalTemplateDeleteGridWidget.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
const { closeModal, modal } = useModal()
const { formatMessage } = useIntl()
const { removeGridLayoutItem } = useGrid()
const { removeGridWidget } = useGrid()
const handleDelete = async () => {
removeGridLayoutItem(modal?.data?.id)
removeGridWidget(modal?.data?.id)
closeModal()
}
</script>
Expand Down
22 changes: 9 additions & 13 deletions components/ModalTemplateMoveGridWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@ import type { SelectStringOption } from '@lukso/web-components'
const { modal, closeModal } = useModal()
const { formatMessage } = useIntl()
const { tempGridLayout, selectedLayoutId } = storeToRefs(useGridStore())
const { addGridLayoutItem, removeGridLayoutItem, getGridById } = useGrid()
const { tempGrid, selectedGridId } = storeToRefs(useGridStore())
const { addGridWidget, removeGridWidget, getGridById } = useGrid()
const selectedOption = ref<string>()
const canSubmit = computed(
() => selectedOption.value !== selectedLayoutId.value
)
const canSubmit = computed(() => selectedOption.value !== selectedGridId.value)
const options = computed<SelectStringOption[]>(() => {
return tempGridLayout.value.map(grid => ({
return tempGrid.value.map(grid => ({
id: grid.id,
value: grid.title,
}))
})
const selectedOptionValue = computed(() => {
const grid = tempGridLayout.value.find(
grid => grid.id === selectedOption.value
)
const grid = tempGrid.value.find(grid => grid.id === selectedOption.value)
return {
id: grid?.id,
value: grid?.title,
Expand Down Expand Up @@ -50,16 +46,16 @@ const handleSave = () => {
h: modal?.data?.h,
})
removeGridLayoutItem(modal?.data?.id)
addGridLayoutItem(
removeGridWidget(modal?.data?.id)
addGridWidget(
duplicatedWidget,
getGridById(tempGridLayout.value, selectedOption.value)
getGridById(tempGrid.value, selectedOption.value)
)
handleCancel()
}
onMounted(() => {
selectedOption.value = selectedLayoutId.value
selectedOption.value = selectedGridId.value
})
</script>

Expand Down
11 changes: 4 additions & 7 deletions domains/grid/components/AddWidgetBasic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type Props = {
const props = defineProps<Props>()
const { formatMessage } = useIntl()
const { closeModal, showModal } = useModal()
const { addGridLayoutItem, updateGridLayoutItem, getGridById } = useGrid()
const { tempGridLayout, selectedLayoutId } = storeToRefs(useGridStore())
const { addGridWidget, updateGridWidget, getGridById } = useGrid()
const { tempGrid, selectedGridId } = storeToRefs(useGridStore())
const TEXTAREA_FOCUS_DELAY = 10 // small delay for focusing textarea after element render
const inputValue = ref('')
Expand All @@ -30,7 +30,7 @@ const handleSave = () => {
}
if (isEdit.value) {
updateGridLayoutItem(props.id, {
updateGridWidget(props.id, {
properties,
w: props.width,
h: props.height,
Expand All @@ -43,10 +43,7 @@ const handleSave = () => {
h: props.height,
})
addGridLayoutItem(
newWidget,
getGridById(tempGridLayout.value, selectedLayoutId.value)
)
addGridWidget(newWidget, getGridById(tempGrid.value, selectedGridId.value))
}
handleCancel()
Expand Down
10 changes: 5 additions & 5 deletions domains/grid/components/AddWidgetGenericPlatform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type Props = {
const props = defineProps<Props>()
const { formatMessage } = useIntl()
const { closeModal, showModal } = useModal()
const { addGridLayoutItem, updateGridLayoutItem, getGridById } = useGrid()
const { tempGridLayout, selectedLayoutId } = storeToRefs(useGridStore())
const { addGridWidget, updateGridWidget, getGridById } = useGrid()
const { tempGrid, selectedGridId } = storeToRefs(useGridStore())
const TEXTAREA_FOCUS_DELAY = 10 // small delay for focusing textarea after element render
const inputValue = ref('')
Expand All @@ -32,7 +32,7 @@ const handleSave = async () => {
)
if (isEdit.value) {
updateGridLayoutItem(props.id, {
updateGridWidget(props.id, {
properties,
w: props.width,
h: props.height,
Expand All @@ -45,9 +45,9 @@ const handleSave = async () => {
h: props.height,
})
addGridLayoutItem(
addGridWidget(
newWidget,
getGridById(tempGridLayout.value, selectedLayoutId.value)
getGridById(tempGrid.value, selectedGridId.value)
)
}
Expand Down
11 changes: 4 additions & 7 deletions domains/grid/components/AddWidgetText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type Props = {
const props = defineProps<Props>()
const { formatMessage } = useIntl()
const { closeModal, showModal } = useModal()
const { addGridLayoutItem, updateGridLayoutItem, getGridById } = useGrid()
const { tempGridLayout, selectedLayoutId } = storeToRefs(useGridStore())
const { addGridWidget, updateGridWidget, getGridById } = useGrid()
const { tempGrid, selectedGridId } = storeToRefs(useGridStore())
const INPUT_FOCUS_DELAY = 10 // small delay for focusing input after element render
const DEFAULT_PROPERTIES = {
Expand Down Expand Up @@ -41,7 +41,7 @@ const handleSave = () => {
const properties = toRaw(inputValues)
if (isEdit.value) {
updateGridLayoutItem(props.id, {
updateGridWidget(props.id, {
properties,
w: props.width,
h: props.height,
Expand All @@ -54,10 +54,7 @@ const handleSave = () => {
h: props.height,
})
addGridLayoutItem(
newWidget,
getGridById(tempGridLayout.value, selectedLayoutId.value)
)
addGridWidget(newWidget, getGridById(tempGrid.value, selectedGridId.value))
}
handleCancel()
Expand Down
4 changes: 2 additions & 2 deletions domains/grid/components/GridTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Props = {
}
const props = defineProps<Props>()
const { selectedLayoutId } = storeToRefs(useGridStore())
const { selectedGridId } = storeToRefs(useGridStore())
const { formatMessage } = useIntl()
const { showModal } = useModal()
const { canEditGrid } = useGrid()
Expand Down Expand Up @@ -40,7 +40,7 @@ const handleAddGrid = () => {
v-for="tab in tabs"
:key="tab.grid.id"
:grid="tab.grid"
:is-active="tab.grid.id === selectedLayoutId"
:is-active="tab.grid.id === selectedGridId"
/>
<li
v-if="canEditGrid"
Expand Down
8 changes: 4 additions & 4 deletions domains/grid/components/GridTabsItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const props = defineProps<Props>()
const { formatMessage } = useIntl()
const { canEditGrid, addGrid } = useGrid()
const { showModal } = useModal()
const { selectedLayoutId, tempGridLayout } = storeToRefs(useGridStore())
const { selectedGridId, tempGrid } = storeToRefs(useGridStore())
const dropdownId = `dropdown-${generateItemId()}`
const styleVariants = tv({
Expand Down Expand Up @@ -60,18 +60,18 @@ const handleDelete = () => {
const handleDuplicate = () => {
const newGrid: Grid<GridWidget> = {
id: createGridId<GridWidget>(props.grid, tempGridLayout.value),
id: createGridId<GridWidget>(props.grid, tempGrid.value),
title: formatMessage('grid_tabs_copy_of', { title: props.grid.title }),
grid: props.grid.grid,
gridColumns: props.grid.gridColumns,
}
addGrid(newGrid)
selectedLayoutId.value = newGrid.id
selectedGridId.value = newGrid.id
}
const handleSelectTab = (id: string) => {
selectedLayoutId.value = id
selectedGridId.value = id
}
</script>

Expand Down
Loading

0 comments on commit cc640cc

Please sign in to comment.