|
| 1 | +<script lang="ts"> |
| 2 | +import AppSelectPaneItem from './AppSelectPaneItem.vue' |
| 3 | +
|
| 4 | +import { watch, defineComponent, ref, computed } from '@vue/composition-api' |
| 5 | +import { BridgeEvents, SharedData } from '@vue-devtools/shared-utils' |
| 6 | +import { useApps, pendingSelectAppId, scanLegacyApps } from '@front/features/apps' |
| 7 | +import { useRouter } from '@front/util/router' |
| 8 | +import { useBridge } from '../bridge' |
| 9 | +
|
| 10 | +export default defineComponent({ |
| 11 | + components: { |
| 12 | + AppSelectPaneItem, |
| 13 | + }, |
| 14 | +
|
| 15 | + setup () { |
| 16 | + const router = useRouter() |
| 17 | + const { bridge } = useBridge() |
| 18 | +
|
| 19 | + const { |
| 20 | + apps, |
| 21 | + currentAppId, |
| 22 | + currentApp, |
| 23 | + selectApp, |
| 24 | + } = useApps() |
| 25 | +
|
| 26 | + watch(currentAppId, value => { |
| 27 | + if (pendingSelectAppId.value !== value) { |
| 28 | + pendingSelectAppId.value = value |
| 29 | + bridge.send(BridgeEvents.TO_BACK_APP_SELECT, value) |
| 30 | + } |
| 31 | + }, { |
| 32 | + immediate: true, |
| 33 | + }) |
| 34 | +
|
| 35 | + let initDefaultAppId = false |
| 36 | +
|
| 37 | + watch(apps, () => { |
| 38 | + if ((!currentApp.value || (SharedData.pageConfig?.defaultSelectedAppId && !initDefaultAppId)) && apps.value.length) { |
| 39 | + let targetId: string |
| 40 | + if (SharedData.pageConfig?.defaultSelectedAppId) { |
| 41 | + targetId = SharedData.pageConfig.defaultSelectedAppId |
| 42 | + initDefaultAppId = true |
| 43 | + } else if (currentAppId.value !== apps.value[0].id) { |
| 44 | + targetId = apps.value[0].id |
| 45 | + } |
| 46 | + if (targetId) { |
| 47 | + router.push({ |
| 48 | + params: { |
| 49 | + appId: targetId, |
| 50 | + componentId: null, |
| 51 | + }, |
| 52 | + }) |
| 53 | + } |
| 54 | + } |
| 55 | + }, { |
| 56 | + immediate: true, |
| 57 | + }) |
| 58 | +
|
| 59 | + // Search |
| 60 | + const search = ref('') |
| 61 | + const filteredApps = computed(() => { |
| 62 | + if (!search.value) return apps.value |
| 63 | + const searchValue = search.value.toLowerCase() |
| 64 | + return apps.value.filter(app => { |
| 65 | + return app.name.toLowerCase().includes(searchValue) |
| 66 | + }) |
| 67 | + }) |
| 68 | +
|
| 69 | + return { |
| 70 | + currentApp, |
| 71 | + filteredApps, |
| 72 | + selectApp, |
| 73 | + search, |
| 74 | + scanLegacyApps, |
| 75 | + } |
| 76 | + }, |
| 77 | +}) |
| 78 | +</script> |
| 79 | + |
| 80 | +<template> |
| 81 | + <div class="flex flex-col"> |
| 82 | + <div class="flex-none border-b border-gray-200 dark:border-gray-800 flex items-center space-x-1 h-[40px] pr-1"> |
| 83 | + <VueInput |
| 84 | + v-model="search" |
| 85 | + icon-left="search" |
| 86 | + placeholder="Find apps..." |
| 87 | + select-all |
| 88 | + class="search flat flex-1" |
| 89 | + /> |
| 90 | + |
| 91 | + <VueButton |
| 92 | + v-if="$shared.legacyApps" |
| 93 | + v-tooltip="'Scan apps'" |
| 94 | + class="flat icon-button" |
| 95 | + icon-left="cached" |
| 96 | + @click="scanLegacyApps()" |
| 97 | + /> |
| 98 | + </div> |
| 99 | + |
| 100 | + <div class="overflow-y-auto flex-1"> |
| 101 | + <AppSelectPaneItem |
| 102 | + v-for="item of filteredApps" |
| 103 | + :key="item.id" |
| 104 | + :app="item" |
| 105 | + :selected="item === currentApp" |
| 106 | + @select="selectApp(item.id)" |
| 107 | + /> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | +</template> |
0 commit comments