Skip to content

Commit

Permalink
Merge pull request #4325 from traPtitech/refactor/modal_container_con…
Browse files Browse the repository at this point in the history
…ditions

Modalの分岐にObjectを使うようにした
  • Loading branch information
ZOI-dayo authored Jul 8, 2024
2 parents b920602 + 0eeb3bf commit 3d9a711
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
60 changes: 25 additions & 35 deletions src/components/Modal/ModalContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import { type Component, computed } from 'vue'
import { useModalStore } from '/@/store/ui/modal'
import UserModal from './UserModal/UserModal.vue'
import NotificationModal from './NotificationModal/NotificationModal.vue'
Expand All @@ -64,45 +64,35 @@ import GroupMemberEditModal from './GroupMemberEditModal/GroupMemberEditModal.vu
import GroupAdminAddModal from './GroupAdminAddModal/GroupAdminAddModal.vue'
import GroupMemberAddModal from './GroupMemberAddModal/GroupMemberAddModal.vue'
import SettingsThemeEditModal from './SettingsThemeEditModal/SettingsThemeEditModal.vue'
import type { ModalStateType } from '/@/store/ui/modal/states'
const { shouldShowModal, currentState } = useModalStore()
const components: Record<ModalStateType, Component> = {
user: UserModal,
notification: NotificationModal,
tag: TagModal,
group: GroupModal,
'channel-create': ChannelCreateModal,
file: FileModal,
qrcode: QRCodeModal,
'clip-create': ClipCreateModal,
'clip-folder-create': ClipFolderCreateModal,
'channel-manage': ChannelManageModal,
'group-create': GroupCreateModal,
'group-member-edit': GroupMemberEditModal,
'group-admin-add': GroupAdminAddModal,
'group-member-add': GroupMemberAddModal,
'settings-theme-edit': SettingsThemeEditModal
}
const component = computed(() => {
switch (currentState.value?.type) {
case 'user':
return UserModal
case 'notification':
return NotificationModal
case 'tag':
return TagModal
case 'group':
return GroupModal
case 'channel-create':
return ChannelCreateModal
case 'file':
return FileModal
case 'qrcode':
return QRCodeModal
case 'clip-create':
return ClipCreateModal
case 'clip-folder-create':
return ClipFolderCreateModal
case 'channel-manage':
return ChannelManageModal
case 'group-create':
return GroupCreateModal
case 'group-member-edit':
return GroupMemberEditModal
case 'group-admin-add':
return GroupAdminAddModal
case 'group-member-add':
return GroupMemberAddModal
case 'settings-theme-edit':
return SettingsThemeEditModal
if (currentState.value) {
return components[currentState.value.type]
} else {
// eslint-disable-next-line no-console
console.error('Unexpected modal type:', currentState.value)
return undefined
}
// eslint-disable-next-line no-console
console.error('Unexpected modal type:', currentState.value)
return undefined
})
</script>

Expand Down
3 changes: 1 addition & 2 deletions src/store/ui/modal/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import type {
MessageId
} from '/@/types/entity-ids'

type ModalStateType =
export type ModalStateType =
| 'user'
| 'group'
| 'notification'
| 'file'
| 'tag'
| 'group'
| 'channel-create'
| 'qrcode'
| 'clip-create'
Expand Down

0 comments on commit 3d9a711

Please sign in to comment.