Skip to content

Commit 302e989

Browse files
committed
💄 fix folder tree UI bug.
1 parent 833780b commit 302e989

2 files changed

Lines changed: 54 additions & 26 deletions

File tree

components/FolderTree.vue

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const expand = ref(true)
1717
* get file type icon
1818
*
1919
*/
20-
const fileTypeMap: any = useFileTypeMap() // 🚨 maybe should fix this any type
20+
const fileTypeMap: any = useFileTypeMap() // 🚨 maybe should fix this "any" type
2121
2222
const getFileTypeIcon = (type:string) => {
2323
const fileType = fileTypeMap.value[type]
@@ -37,35 +37,40 @@ const getFileTypeIcon = (type:string) => {
3737
const folderNavArr = ref([
3838
{
3939
title: props.rootName,
40-
path: []
40+
path: [] as number[]
4141
}
4242
])
4343
44-
let folderNavPath = []
44+
let folderNavPath:number[] = []
4545
4646
const currentTree = ref<NavItem[]>([])
4747
4848
currentTree.value = props.rootTree
4949
50-
const setFolderNavPath = (path) => {
51-
folderNavPath = path
50+
const setFolderNavPath = (path:number[]) => {
51+
// path is a number array, which folder at nav been clicked
52+
folderNavPath = path // need to change the folder nav to this path
53+
// rebuild the folderNavArr
54+
// set the root folder (NavItem) as start
5255
let treeTemp = props.rootTree
5356
57+
// the start folderNavArr just contain the root folder
5458
const folderNavArrTemp = [{
5559
title: props.rootName,
56-
path: []
60+
path: [] as number[]
5761
}]
5862
59-
let folderNavPathTemp = []
63+
let folderNavPathTemp:number[] = []
6064
65+
// loop the path to rebuild the folderNavArr
6166
if (path.length > 0) {
6267
path.forEach((index) => {
6368
folderNavPathTemp = folderNavPathTemp.concat(index)
6469
folderNavArrTemp.unshift({
6570
title: treeTemp[index].title,
6671
path: folderNavPathTemp
6772
})
68-
treeTemp = treeTemp[index].children
73+
treeTemp = treeTemp[index].children as NavItem[]
6974
})
7075
}
7176
@@ -77,15 +82,15 @@ const setFolderNavPath = (path) => {
7782
})
7883
}
7984
80-
const addFolderNav = (title, index) => {
85+
const addFolderNav = (title:string, index:number) => {
8186
folderNavPath = folderNavPath.concat(index)
8287
8388
folderNavArr.value.unshift({
8489
title,
8590
path: folderNavPath
8691
})
8792
88-
currentTree.value = currentTree.value[index].children
93+
currentTree.value = currentTree.value[index].children as NavItem[]
8994
9095
nextTick(() => {
9196
rejudgeShowScrollBtn()
@@ -106,7 +111,7 @@ const showScrollBtn = ref(true)
106111
107112
const scrollPos = ref<'start' | 'middle' | 'end'>('start')
108113
109-
const folderNavContainer = ref(null)
114+
const folderNavContainer = ref<HTMLElement | null>(null) // get the folderNav container DOM
110115
111116
const rejudgeShowScrollBtn = () => {
112117
// show of hide the scroll button
@@ -136,7 +141,7 @@ onMounted(() => {
136141
})
137142
})
138143
139-
const scrollFolderNavHandler = (direction) => {
144+
const scrollFolderNavHandler = (direction:('left' | 'right')) => {
140145
if (!folderNavContainer.value) { return }
141146
const containerWidth = folderNavContainer.value.clientWidth
142147
@@ -166,11 +171,14 @@ const folderNavScrollingHandler = () => {
166171
>
167172
<button
168173
v-show="!expand"
169-
class="group w-full px-4 py-2 flex items-center gap-1 hover:text-yellow-500 hover:bg-yellow-50 rounded-lg transition-colors duration-300"
174+
:title="props.rootName"
175+
class="group w-full px-4 py-2 flex items-start gap-1 hover:text-yellow-500 hover:bg-yellow-50 rounded-lg transition-colors duration-300"
170176
@click="expand = true"
171177
>
172-
<IconCustom name="ph:folder-fill" class="w-6 h-6 text-yellow-400" />
173-
{{ props.rootName }}
178+
<IconCustom name="ph:folder-fill" class="shrink-0 w-6 h-6 text-yellow-400" />
179+
<span class="line-camp-2 break-all">
180+
{{ props.rootName }}
181+
</span>
174182
</button>
175183
<div v-show="expand" class="w-full flex flex-col">
176184
<div class="w-full flex justify-between items-center">
@@ -234,19 +242,23 @@ const folderNavScrollingHandler = () => {
234242
:key="item._path"
235243
:to="item._path"
236244
target="_blank"
237-
class="p-2 flex items-center gap-1 text-sm rounded hover:text-blue-500 active:text-white hover:bg-blue-100 active:bg-blue-500 transition-colors duration-300"
245+
class="p-2 flex items-start gap-1 rounded hover:text-blue-500 active:text-white hover:bg-blue-100 active:bg-blue-500 transition-colors duration-300"
238246
>
239-
<IconCustom :name="getFileTypeIcon(item._type)" class="w-5 h-5" />
240-
{{ item.title }}
247+
<IconCustom :name="getFileTypeIcon(item._type)" class="shrink-0 w-5 h-5" />
248+
<span class="text-sm break-all">
249+
{{ item.title }}
250+
</span>
241251
</NuxtLink>
242252
<button
243253
v-if="item.children"
244254
:key="item._path"
245-
class="group p-2 flex items-center gap-1 text-sm rounded hover:text-yellow-500 active:text-white hover:bg-yellow-50 active:bg-yellow-500 transition-colors duration-300"
255+
class="group p-2 flex items-start gap-1 rounded hover:text-yellow-500 active:text-white hover:bg-yellow-50 active:bg-yellow-500 transition-colors duration-300"
246256
@click="addFolderNav(item.title, index)"
247257
>
248-
<IconCustom name="ph:folder-fill" class="w-5 h-5 text-yellow-400 group-active:text-white" />
249-
{{ item.title }}
258+
<IconCustom name="ph:folder-fill" class="shrink-0 w-5 h-5 text-yellow-400 group-active:text-white" />
259+
<span class="text-sm break-all">
260+
{{ item.title }}
261+
</span>
250262
</button>
251263
</template>
252264
</div>
@@ -275,4 +287,11 @@ const folderNavScrollingHandler = () => {
275287
background-color: #94a3b8;
276288
}
277289
}
290+
291+
.line-camp-2 {
292+
overflow: hidden;
293+
display: -webkit-box;
294+
-webkit-box-orient: vertical;
295+
-webkit-line-clamp: 2;
296+
}
278297
</style>

pages/index.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,21 @@ const getFileTypeIcon = (type) => {
292292
</div>
293293
<hr class="p-4">
294294
<div
295-
class="folders-container w-full grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-col-4 xl:grid-cols-5 2xl:grid-cols-6 gap-2 grid-flow-row-dense"
295+
class="folders-container w-full my-2 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-col-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4 grid-flow-row-dense"
296296
>
297297
<template v-for="(item, index) in currentTree">
298298
<NuxtLink
299299
v-if="item._type"
300300
:key="item._path"
301301
:to="item._path"
302+
:title="item.title"
302303
target="_blank"
303-
class="self-start px-4 py-2 flex items-center gap-1 hover:text-blue-500 hover:bg-blue-100 transition-colors duration-300 rounded-lg"
304+
class="self-start px-4 py-2 flex items-start gap-1 hover:text-blue-500 hover:bg-blue-100 transition-colors duration-300 rounded-lg"
304305
>
305-
<IconCustom :name="getFileTypeIcon(item._type)" class="w-6 h-6" />
306-
{{ item.title }}
306+
<IconCustom :name="getFileTypeIcon(item._type)" class="shrink-0 w-6 h-6" />
307+
<span class="line-camp-2 break-all">
308+
{{ item.title }}
309+
</span>
307310
</NuxtLink>
308311
<FolderTree
309312
v-if="item.children"
@@ -333,7 +336,6 @@ const getFileTypeIcon = (type) => {
333336
</template>
334337

335338
<style lang="scss" scoped>
336-
337339
.folders-container {
338340
grid-auto-rows: 40px
339341
}
@@ -345,4 +347,11 @@ const getFileTypeIcon = (type) => {
345347
.folder-nav-container::-webkit-scrollbar {
346348
display: none;
347349
}
350+
351+
.line-camp-2 {
352+
overflow: hidden;
353+
display: -webkit-box;
354+
-webkit-box-orient: vertical;
355+
-webkit-line-clamp: 2;
356+
}
348357
</style>

0 commit comments

Comments
 (0)