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

Commit

Permalink
Fix clone
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbo committed Oct 30, 2024
1 parent fd3934a commit bfc9810
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
45 changes: 37 additions & 8 deletions domains/grid/components/GridWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ const widgetComponent = shallowRef<Component | undefined>()
const { canEditGrid, addGridWidget, getGridById } = useGrid()
const { formatMessage } = useIntl()
const { showModal } = useModal()
const { isConnected, isMobile, isConnectedUserViewingOwnProfile } =
storeToRefs(useAppStore())
const { isEditingGrid, tempGrid, selectedGridId } = storeToRefs(useGridStore())
const {
isConnected,
isMobile,
isConnectedUserViewingOwnProfile,
connectedProfileAddress,
} = storeToRefs(useAppStore())
const { isEditingGrid, tempGrid, selectedGridId, tempGrids } =
storeToRefs(useGridStore())
const { connect } = useBaseProvider()
const { browserSupportExtension } = useBrowser()
const dropdownId = `dropdown-${generateItemId()}`
Expand Down Expand Up @@ -129,20 +134,44 @@ const handleClone = async () => {
await connect()
}
const _connectedProfileAddress =
connectedProfileAddress.value?.toLowerCase() as Address
const clonedWidget = createWidgetObject({
type: props.widget.type,
properties: props.widget.properties,
w: props.widget.w,
h: props.widget.h,
})
addGridWidget(clonedWidget, getGridById(tempGrid.value, selectedGridId.value))
isEditingGrid.value = true // we enable edit mode so user is aware about unsaved state
if (!isConnectedUserViewingOwnProfile.value) {
showModal({
template: 'GridWidgetCloned',
})
// in case we are on own profile we do simply widget copy
if (isConnectedUserViewingOwnProfile.value) {
addGridWidget(
clonedWidget,
getGridById(tempGrid.value, selectedGridId.value)
)
return
}
// re-create temp grid if missing
if (!tempGrids.value[_connectedProfileAddress]) {
const userGrid = await getUserGrid(_connectedProfileAddress)
tempGrids.value[_connectedProfileAddress] = buildGrid(
userGrid,
isMobile.value
)
}
addGridWidget(
clonedWidget,
getGridById(
tempGrids.value[_connectedProfileAddress],
tempGrids.value[_connectedProfileAddress][0].id
)
)
showModal({
template: 'GridWidgetCloned',
})
}
const handleDropdownChange = (
Expand Down
24 changes: 12 additions & 12 deletions domains/grid/composables/useGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export const useGrid = () => {
},

addGridWidget: (widget: GridWidgetWithoutCords, grid?: Grid) => {
if (!canEditGrid.value) {
console.warn('User cannot edit grid')
if (!isConnected.value) {
console.warn('User not connected')
return
}

Expand All @@ -168,8 +168,8 @@ export const useGrid = () => {
},

updateGridWidget: (id?: string, widget?: Partial<GridWidget>) => {
if (!canEditGrid.value) {
console.warn('User cannot edit grid')
if (!isConnected.value) {
console.warn('User not connected')
return
}

Expand Down Expand Up @@ -199,8 +199,8 @@ export const useGrid = () => {
},

removeGridWidget: (id: string | number) => {
if (!canEditGrid.value) {
console.warn('User cannot edit grid')
if (!isConnected.value) {
console.warn('User not connected')
return
}

Expand Down Expand Up @@ -272,17 +272,17 @@ export const useGrid = () => {
},

addGrid: (grid: Grid) => {
if (!canEditGrid.value) {
console.warn('User cannot edit grid')
if (!isConnected.value) {
console.warn('User not connected')
return
}

tempGrid.value.push(grid)
},

updateGrid: (id?: string, grid?: Partial<Grid>) => {
if (!canEditGrid.value) {
console.warn('User cannot edit grid')
if (!isConnected.value) {
console.warn('User not connected')
return
}

Expand Down Expand Up @@ -312,8 +312,8 @@ export const useGrid = () => {
},

removeGrid: (id: string) => {
if (!canEditGrid.value) {
console.warn('User cannot edit grid')
if (!isConnected.value) {
console.warn('User not connected')
return
}

Expand Down

0 comments on commit bfc9810

Please sign in to comment.