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

Commit

Permalink
feat: empty grid (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbo authored Nov 5, 2024
1 parent 2435aad commit eeb67b5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
4 changes: 3 additions & 1 deletion components/ProfileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ watch(
[isConnected, gridsForDisplay, ownedCollectiblesCount],
() => {
// select best tab based for initial display
selectBestTab()
if (gridsForDisplay.value.length === 0) {
selectBestTab()
}
},
{ immediate: true }
)
Expand Down
16 changes: 12 additions & 4 deletions domains/grid/components/GridView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
updateSelectedGrid,
initSelectedGridId,
getGridById,
gridsForTabs,
} = useGrid()
const gridContainer = ref<HTMLElement | null>(null)
const { width } = useElementSize(gridContainer)
Expand Down Expand Up @@ -93,8 +94,15 @@ const handleResetGrid = async () => {
const userGrid = await getUserGrid(address.value)
const _grid = buildGrid(userGrid, isMobile.value, canEditGrid.value)
tempGrid.value = cloneObject(_grid)
viewedGrid.value = cloneObject(_grid)
// when user has no grids we re-create empty grids
if (gridsForTabs.value.length === 1) {
viewedGrid.value = cloneObject(EMPTY_GRID)
tempGrid.value = cloneObject(EMPTY_GRID)
} else {
tempGrid.value = cloneObject(_grid)
viewedGrid.value = cloneObject(_grid)
}
gridWidgets.value = getSelectedGridWidgets(cloneObject(_grid))
isSavingGrid.value = false
Expand Down Expand Up @@ -135,15 +143,15 @@ watch(
const updatedViewedGrid = buildGrid(
viewedGrid.value,
isMobile.value,
canEditGrid.value
canEditGrid.value || gridsForTabs.value.length === 1
)
// if user is in edit mode we use temp grid, otherwise viewed grid
if (canEditGrid.value) {
const updatedTempGrid = buildGrid(
tempGrid.value,
isMobile.value,
canEditGrid.value
canEditGrid.value || gridsForTabs.value.length === 1
)
gridWidgets.value = getSelectedGridWidgets(updatedTempGrid)
const changes = compareGrids(updatedViewedGrid, updatedTempGrid)
Expand Down
11 changes: 9 additions & 2 deletions domains/grid/components/GridWidgetAddContent.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<script setup lang="ts">
const { showModal } = useModal()
const { formatMessage } = useIntl()
const { isEditingGrid } = storeToRefs(useGridStore())
const { gridsForTabs } = useGrid()
const handleAddContent = () => {
showModal<Partial<GridWidget>>({
const handleAddContent = async () => {
// we enable editing mode in case user has no grids yet but see add content placeholder
if (gridsForTabs.value.length === 1) {
isEditingGrid.value = true
}
await showModal<Partial<GridWidget>>({
template: 'AddGridWidget',
})
}
Expand Down
9 changes: 1 addition & 8 deletions domains/grid/composables/useGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,7 @@ export const useGrid = () => {
grid = buildGrid(userGrid, isMobile.value, withAddContentPlaceholder)

if (grid.length === 0) {
grid = [
{
id: 'main',
title: 'Main',
grid: [],
gridColumns: GRID_COLUMNS_MIN,
},
]
grid = cloneObject(EMPTY_GRID)
}

if (gridLog.enabled) {
Expand Down
10 changes: 10 additions & 0 deletions domains/grid/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ export const DEFAULT_SMALL_COLUMN_NUMBER = 1
// minimum and maximum number of columns in the grid
export const GRID_COLUMNS_MIN = 2
export const GRID_COLUMNS_MAX = 4

// initial grid
export const EMPTY_GRID = [
{
id: DEFAULT_GRID_TITLE.toLowerCase(),
title: DEFAULT_GRID_TITLE,
grid: [],
gridColumns: GRID_COLUMNS_MIN,
},
]

0 comments on commit eeb67b5

Please sign in to comment.