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

fix: widget clone issue #516

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions domains/grid/components/GridFloatingMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const BOTTOM_MARGIN_MOBILE_PX = 16
const emits = defineEmits<Emits>()
const { isEditingGrid, hasUnsavedGrid, isSavingGrid } =
storeToRefs(useGridStore())
const { isConnected, isMobile } = storeToRefs(useAppStore())
const { isConnected, isMobile, isConnectedUserViewingOwnProfile } =
storeToRefs(useAppStore())
const { formatMessage } = useIntl()
const { showModal } = useModal()
const bottom = ref(
Expand Down Expand Up @@ -137,7 +138,7 @@ onUnmounted(() => {

<template>
<div
v-if="isConnected"
v-if="isConnected && isConnectedUserViewingOwnProfile"
class="fixed right-4 z-50 flex animate-fade-in gap-6 overflow-hidden rounded-full bg-neutral-100 p-3 shadow-neutral-drop-shadow duration-300 ease-in-out sm:bottom-10 sm:right-10 sm:flex-col sm:transition-height lg:right-[calc(50%-540px)]"
:class="{
'h-[64px] w-[320px] sm:h-[320px] sm:w-[64px]': isEditingGrid,
Expand Down
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
Loading