Skip to content

Commit

Permalink
refactor: Allow to change icon on the context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Nov 17, 2024
1 parent f0ed969 commit 3b90d1f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
10 changes: 7 additions & 3 deletions xmcl-keystone-ui/src/components/AppChangeInstanceIconCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useVModel } from '@vueuse/core'
const { t } = useI18n()
const props = defineProps<{
icon: string
color?: string
}>()
const emit = defineEmits<{
Expand Down Expand Up @@ -33,8 +34,11 @@ function pickIconFile() {
</script>

<template>
<v-card>
<v-list>
<v-card
:color="color"
class="transition-colors"
>
<v-list color="transparent">
<v-list-item>
<v-list-item-content>
<v-list-item-title>
Expand All @@ -58,7 +62,7 @@ function pickIconFile() {

<v-divider />

<v-list>
<v-list color="transparent">
<v-list-item>
<v-text-field
v-model="iconModel"
Expand Down
16 changes: 16 additions & 0 deletions xmcl-keystone-ui/src/composables/instanceContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { Ref } from 'vue'
import { ContextMenuItem } from './contextMenu'
import { useDialog } from './dialog'
import { useService } from './service'
import { injection } from '@/util/inject'
import { kInstance } from './instance'

export function useInstanceContextMenuItems(instance: Ref<Instance | undefined>) {
const { show: showDeleteDialog } = useDialog('delete-instance')
const { duplicateInstance } = useService(InstanceServiceKey)
const { showItemInDirectory } = useService(BaseServiceKey)
const { t } = useI18n()
const { path } = injection(kInstance)
const { currentRoute, push } = useRouter()

return () => {
const inst = instance.value
Expand Down Expand Up @@ -36,6 +40,18 @@ export function useInstanceContextMenuItems(instance: Ref<Instance | undefined>)
duplicateInstance(inst.path)
},
},
{
text: t('instance.changeIcon'),
icon: 'image',
onClick() {
if (path.value !== inst.path) {
path.value = inst.path
}
if (currentRoute.fullPath !== '/base-setting') {
push('/base-setting?changeIcon=true')
}
},
},
]
return result
}
Expand Down
22 changes: 20 additions & 2 deletions xmcl-keystone-ui/src/views/BaseSettingGeneral.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
</v-icon>
</v-avatar>
</template>

<AppChangeInstanceIconCard :icon.sync="data.icon" />
<AppChangeInstanceIconCard
:color="highlighted ? 'info' : ''"
:icon.sync="data.icon"
/>
</v-menu>
</v-list-item-action>
<v-list-item-content>
Expand Down Expand Up @@ -181,6 +183,10 @@ import SettingItemCheckbox from '@/components/SettingItemCheckbox.vue'
import { kUserContext } from '@/composables/user'
import { AUTHORITY_MICROSOFT } from '@xmcl/runtime-api'
import AppChangeInstanceIconCard from '@/components/AppChangeInstanceIconCard.vue'
import { useQuery } from '@/composables/query'
import { useTimeout } from '@vueuse/core'
const changeIcon = useQuery('changeIcon')
const {
data,
Expand Down Expand Up @@ -221,6 +227,18 @@ const { t } = useI18n()
const changeIconModel = ref(false)
onMounted(() => {
if (changeIcon.value) {
nextTick().then(() => {
changeIconModel.value = true
start()
})
}
})
const { ready, start } = useTimeout(500, { controls: true })
const highlighted = computed(() => !ready.value && changeIconModel.value)
</script>

<style scoped=true>
Expand Down
4 changes: 2 additions & 2 deletions xmcl-keystone-ui/src/views/InstancesCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
hover
@click="emit('click', $event)"
>
<div
<!-- <div
class="absolute flex size-full items-center justify-center"
>
<v-progress-circular
Expand All @@ -21,7 +21,7 @@
:width="4"
indeterminate
/>
</div>
</div> -->
<v-img
class="white--text favicon grey en-2 min-h-34 max-h-34 flex items-center"
:src="image"
Expand Down

0 comments on commit 3b90d1f

Please sign in to comment.