11<script setup lang="ts">
22import type { SessionContext } from ' ~~/shared/types'
3+ import type { ClientSettings } from ' ~/state/settings'
34import { useRoute , useRouter } from ' #app/composables/router'
45import { clearUndefined , toArray } from ' @antfu/utils'
56import { computedWithControl , debouncedWatch } from ' @vueuse/core'
@@ -27,6 +28,23 @@ const filters = reactive<Filters>({
2728 file_types: (route .query .file_types ? toArray (route .query .file_types ) : null ) as string [] | null ,
2829 node_modules: (route .query .node_modules ? toArray (route .query .node_modules ) : null ) as string [] | null ,
2930})
31+ const moduleViewTypes = [
32+ {
33+ label: ' List' ,
34+ value: ' list' ,
35+ icon: ' i-ph-list-duotone' ,
36+ },
37+ {
38+ label: ' Graph' ,
39+ value: ' graph' ,
40+ icon: ' i-ph-graph-duotone' ,
41+ },
42+ {
43+ label: ' Folder' ,
44+ value: ' folder' ,
45+ icon: ' i-ph-folder-duotone' ,
46+ },
47+ ] as const
3048
3149debouncedWatch (
3250 filters ,
@@ -79,7 +97,7 @@ const filtered = computed(() => {
7997 if (filters .node_modules ) {
8098 modules = modules .filter (mod => mod .path .moduleName && filters .node_modules ! .includes (mod .path .moduleName ))
8199 }
82- return modules .map (mod => mod .mod )
100+ return modules .map (mod => ({ ... mod .mod , path: mod . path . path }) )
83101})
84102
85103function isFileTypeSelected(type : string ) {
@@ -119,11 +137,11 @@ const searched = computed(() => {
119137 .map (r => r .item )
120138})
121139
122- function toggleDisplay() {
140+ function toggleDisplay(type : ClientSettings [ ' flowModuleGraphView ' ] ) {
123141 if (route .query .module ) {
124142 router .replace ({ query: { ... route .query , module: undefined } })
125143 }
126- settings .value .flowModuleGraphView = settings . value . flowModuleGraphView === ' list ' ? ' graph ' : ' list '
144+ settings .value .flowModuleGraphView = type
127145}
128146 </script >
129147
@@ -161,12 +179,14 @@ function toggleDisplay() {
161179 <div flex =" ~ gap-2 items-center" p2 border =" t base" >
162180 <span op50 pl2 text-sm >View as</span >
163181 <button
182+ v-for =" viewType of moduleViewTypes"
183+ :key =" viewType.value"
164184 btn-action
165- @click =" toggleDisplay"
185+ :class =" settings.flowModuleGraphView === viewType.value ? 'bg-active' : 'grayscale op50'"
186+ @click =" toggleDisplay(viewType.value)"
166187 >
167- <div v-if =" settings.flowModuleGraphView === 'graph'" i-ph-graph-duotone />
168- <div v-else i-ph-list-duotone />
169- {{ settings.flowModuleGraphView === 'list' ? 'List' : 'Graph' }}
188+ <div :class =" viewType.icon" />
189+ {{ viewType.label }}
170190 </button >
171191 </div >
172192 <!-- TODO: should we add filters for node_modules? -->
@@ -184,11 +204,17 @@ function toggleDisplay() {
184204 </div >
185205 </div >
186206 </template >
187- <template v-else >
207+ <template v-else-if = " settings . flowModuleGraphView === ' graph ' " >
188208 <ModulesGraph
189209 :session =" session"
190210 :modules =" searched"
191211 />
192212 </template >
213+ <template v-else >
214+ <ModulesFolder
215+ :session =" session"
216+ :modules =" searched"
217+ />
218+ </template >
193219 </div >
194220</template >
0 commit comments