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

Commit

Permalink
Type modals
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbo committed Oct 29, 2024
1 parent 3ce020b commit a8c66e8
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 52 deletions.
4 changes: 2 additions & 2 deletions components/ModalTemplateAddEditGrid.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { SelectStringOption } from '@lukso/web-components'
const { modal, closeModal } = useModal()
const { modal, closeModal } = useModal<Partial<Grid>>()
const { formatMessage } = useIntl()
const { tempGrid, selectedGridId } = storeToRefs(useGridStore())
const { addGrid, updateGrid } = useGrid()
Expand All @@ -15,7 +15,7 @@ const inputErrors = reactive({
title: '',
})
const id = computed(() => modal?.data?.grid?.id)
const id = computed(() => modal?.data?.id)
const canSubmit = ref(false)
const isEdit = computed(() => !!id.value)
Expand Down
8 changes: 4 additions & 4 deletions components/ModalTemplateAddGridWidget.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
const { modal } = useModal()
const { modal } = useModal<Partial<GridWidget>>()
</script>

<template>
<AddWidget
:properties="modal?.data?.properties"
:id="modal?.data?.id"
:width="modal?.data?.width"
:height="modal?.data?.height"
:id="modal?.data?.i"
:width="modal?.data?.w"
:height="modal?.data?.h"
:type="modal?.data?.type"
/>
</template>
6 changes: 3 additions & 3 deletions composables/useModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Modal } from '@/types/modal'
*
* @param data
*/
const showModal = async (modal: Modal) => {
const showModal = async <T = ModalData>(modal: Modal<T>) => {
const route = useRoute()
const { isModalOpen } = storeToRefs(useAppStore())

Expand Down Expand Up @@ -49,12 +49,12 @@ const closeModal = async () => {
})
}

export const useModal = () => {
export const useModal = <T = ModalData>() => {
const { modal } = useAppStore()

return {
showModal,
closeModal,
modal,
modal: modal as Modal<T>,
}
}
1 change: 1 addition & 0 deletions domains/grid/components/AddWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const loadComponent = (type?: string): Component | undefined => {
)
}
// when no type we display selection screen
return defineAsyncComponent(() => import('./AddWidgetSelection.vue'))
}
Expand Down
5 changes: 1 addition & 4 deletions domains/grid/components/AddWidgetBasic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ const handleCancel = () => {
}
const handleBackToSelection = () => {
showModal({
showModal<Partial<GridWidget>>({
template: 'AddGridWidget',
forceOpen: true,
data: {
type: undefined, // when no type we display selection screen
},
})
}
Expand Down
6 changes: 3 additions & 3 deletions domains/grid/components/AddWidgetSelection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ type Props = {
defineProps<Props>()
const handleSelectWidget = (widgetType: GridWidgetType) => {
showModal({
showModal<Partial<GridWidget>>({
template: 'AddGridWidget',
data: {
type: widgetType,
width: 1,
height: 1,
w: 1,
h: 1,
},
forceOpen: true,
})
Expand Down
5 changes: 1 addition & 4 deletions domains/grid/components/AddWidgetText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ const handleCancel = () => {
}
const handleBackToSelection = () => {
showModal({
showModal<Partial<GridWidget>>({
template: 'AddGridWidget',
forceOpen: true,
data: {
type: undefined, // when no type we display selection screen
},
})
}
</script>
Expand Down
14 changes: 2 additions & 12 deletions domains/grid/components/GridFloatingMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,14 @@ const handleToggleGridEditMode = async () => {
}
const handleAddContent = () => {
showModal({
showModal<Partial<GridWidget>>({
template: 'AddGridWidget',
data: {
type: undefined, // when no type we display selection screen
width: 1,
height: 1,
},
})
}
const handleAddGrid = () => {
showModal({
showModal<Partial<Grid>>({
template: 'AddEditGrid',
data: {
id: undefined,
grid: undefined,
gridColumns: undefined,
},
})
}
Expand Down
10 changes: 4 additions & 6 deletions domains/grid/components/GridTabsItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ const styles = computed(() => {
})
const handleEdit = () => {
showModal({
showModal<Partial<Grid>>({
template: 'AddEditGrid',
data: {
grid: {
id: props.grid.id,
title: props.grid.title,
gridColumns: props.grid.gridColumns,
},
id: props.grid.id,
title: props.grid.title,
gridColumns: props.grid.gridColumns,
},
})
}
Expand Down
8 changes: 4 additions & 4 deletions domains/grid/components/GridWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ const handleDelete = () => {
}
const handleEdit = () => {
showModal({
showModal<Partial<GridWidget>>({
template: 'AddGridWidget',
data: {
properties: props.widget.properties,
id: props.widget.i,
i: props.widget.i,
type: props.widget.type,
width: props.widget.w,
height: props.widget.h,
w: props.widget.w,
h: props.widget.h,
},
})
}
Expand Down
7 changes: 1 addition & 6 deletions domains/grid/components/GridWidgetAddContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ const { showModal } = useModal()
const { formatMessage } = useIntl()
const handleAddContent = () => {
showModal({
showModal<Partial<GridWidget>>({
template: 'AddGridWidget',
data: {
type: undefined, // when no type we display selection screen
width: 1,
height: 1,
},
})
}
</script>
Expand Down
10 changes: 6 additions & 4 deletions types/modal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { ModalSizes } from '@lukso/web-components'

export type Modal = {
export type Modal<T = ModalData> = {
template?: string
data?: {
[key: string]: any
}
data?: T
size?: ModalSizes
forceOpen?: boolean
}
Expand All @@ -14,3 +12,7 @@ export type ModalQueryParams = {
modalSize?: ModalSizes
modalData?: any
}

export type ModalData = {
[key: string]: any
}

0 comments on commit a8c66e8

Please sign in to comment.