File size: 2,808 Bytes
4d70170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<script lang="ts">
import { computed, defineComponent, ref, watch } from 'vue'
import { BridgeEvents, SharedData } from '@vue-devtools/shared-utils'
import { pendingSelectAppId, scanLegacyApps, useApps } from '@front/features/apps'
import { useRouter } from 'vue-router'
import { useBridge } from '../bridge'
import AppSelectPaneItem from './AppSelectPaneItem.vue'

export default defineComponent({
  components: {
    AppSelectPaneItem,
  },

  setup() {
    const router = useRouter()
    const { bridge } = useBridge()

    const {
      apps,
      currentAppId,
      currentApp,
      selectApp,
    } = useApps()

    watch(currentAppId, (value) => {
      if (pendingSelectAppId.value !== value) {
        pendingSelectAppId.value = value
        bridge.send(BridgeEvents.TO_BACK_APP_SELECT, value)
      }
    }, {
      immediate: true,
    })

    let initDefaultAppId = false

    watch(apps, () => {
      if ((!currentApp.value || (SharedData.pageConfig?.defaultSelectedAppId && !initDefaultAppId)) && apps.value.length) {
        let targetId: string
        if (SharedData.pageConfig?.defaultSelectedAppId) {
          targetId = SharedData.pageConfig.defaultSelectedAppId
          initDefaultAppId = true
        }
        else if (currentAppId.value !== apps.value[0].id) {
          targetId = apps.value[0].id
        }
        if (targetId) {
          router.push({
            params: {
              appId: targetId,
              componentId: null,
            },
          })
        }
      }
    }, {
      immediate: true,
    })

    // Search
    const search = ref('')
    const filteredApps = computed(() => {
      if (!search.value) {
        return apps.value
      }
      const searchValue = search.value.toLowerCase()
      return apps.value.filter((app) => {
        return app.name.toLowerCase().includes(searchValue)
      })
    })

    return {
      currentApp,
      filteredApps,
      selectApp,
      search,
      scanLegacyApps,
    }
  },
})
</script>

<template>
  <div class="flex flex-col">
    <div class="flex-none border-b border-gray-200 dark:border-gray-700 flex items-center space-x-1 h-8 pr-1 box-content">
      <VueInput
        v-model="search"
        icon-left="search"
        placeholder="Find apps..."
        select-all
        class="search flat flex-1 !min-w-0"
      />

      <VueButton
        v-if="$shared.legacyApps"
        v-tooltip="'Scan apps'"
        class="flat icon-button"
        icon-left="cached"
        @click="scanLegacyApps()"
      />
    </div>

    <div class="overflow-y-auto flex-1">
      <AppSelectPaneItem
        v-for="item of filteredApps"
        :key="item.id"
        :app="item"
        :selected="item === currentApp"
        @select="selectApp(item.id)"
      />
    </div>
  </div>
</template>