Skip to content

Commit 1a213a9

Browse files
authored
feat(folder): move the count msg to bottom and add options (#128)
* feat(home): move the count msg to bottom and add options * refactor(home): improve count message functionality * refactor(obj): optimize code * style(folder): update count message style
1 parent 8700960 commit 1a213a9

File tree

6 files changed

+67
-19
lines changed

6 files changed

+67
-19
lines changed

src/lang/en/home.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@
168168
"none": "None",
169169
"visible": "Visible"
170170
},
171+
"show_count_msg": "Show file count message",
172+
"show_count_msg_options": {
173+
"none": "None",
174+
"visible": "Visible"
175+
},
171176
"list_item_filename_overflow": "List item filename overflow",
172177
"list_item_filename_overflow_options": {
173178
"ellipsis": "Ellipsis",

src/pages/home/folder/Grid.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Box, Grid, Text } from "@hope-ui/solid"
2-
import { For } from "solid-js"
2+
import { For, Show } from "solid-js"
33
import { GridItem } from "./GridItem"
44
import "lightgallery/css/lightgallery-bundle.css"
5-
import { countMsg, local, objStore } from "~/store"
5+
import { smartCountMsg, local, objStore } from "~/store"
66
import { useSelectWithMouse } from "./helper"
77

88
const GridLayout = () => {
@@ -11,9 +11,13 @@ const GridLayout = () => {
1111
registerSelectContainer()
1212
return (
1313
<>
14-
<Box w="100%" textAlign="left" pl="$2">
15-
<Text>{countMsg()}</Text>
16-
</Box>
14+
<Show when={local["show_count_msg"] === "visible"}>
15+
<Box w="100%" textAlign="left" pl="$2">
16+
<Text size="sm" color="$neutral11">
17+
{smartCountMsg()}
18+
</Text>
19+
</Box>
20+
</Show>
1721
<Grid
1822
oncapture:contextmenu={captureContentMenu}
1923
class="viselect-container"

src/pages/home/folder/Images.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Box, Flex, Grid, Heading, Text, VStack } from "@hope-ui/solid"
22
import { For, Show, createMemo } from "solid-js"
33
import { ImageItem } from "./ImageItem"
4-
import { countMsg, local, objStore } from "~/store"
4+
import { smartCountMsg, local, objStore } from "~/store"
55
import { GridItem } from "./GridItem"
66
import { ObjType, StoreObj } from "~/types"
77
import { useT } from "~/hooks"
@@ -33,9 +33,13 @@ const ImageLayout = (props: { images: StoreObj[] }) => {
3333
spacing="$2"
3434
w="$full"
3535
>
36-
<Box w="100%" textAlign="left" pl="$2">
37-
<Text>{countMsg(ObjType.IMAGE)}</Text>
38-
</Box>
36+
<Show when={local["show_count_msg"] === "visible"}>
37+
<Box w="100%" textAlign="left" pl="$2">
38+
<Text size="sm" color="$neutral11">
39+
{smartCountMsg(ObjType.IMAGE)}
40+
</Text>
41+
</Box>
42+
</Show>
3943
<Show when={local["show_folder_in_image_view"] === "top"}>
4044
{folders()}
4145
</Show>

src/pages/home/folder/List.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import {
1313
checkboxOpen,
1414
countMsg,
1515
isIndeterminate,
16+
local,
1617
objStore,
1718
selectAll,
19+
selectedMsg,
1820
sortObjs,
1921
} from "~/store"
2022
import { OrderBy } from "~/store"
@@ -66,8 +68,11 @@ export const ListTitle = (props: {
6668
}}
6769
/>
6870
</Show>
69-
<Text {...itemProps(cols[0])}>{t(`home.obj.${cols[0].name}`)}</Text>
70-
<Text {...itemProps(cols[0])}>{countMsg()}</Text>
71+
{selectedMsg() ? (
72+
<Text {...itemProps(cols[0])}>{selectedMsg()}</Text>
73+
) : (
74+
<Text {...itemProps(cols[0])}>{t(`home.obj.${cols[0].name}`)}</Text>
75+
)}
7176
</HStack>
7277
<Text w={cols[1].w} {...itemProps(cols[1])}>
7378
{t(`home.obj.${cols[1].name}`)}
@@ -112,6 +117,11 @@ const ListLayout = () => {
112117
return <ListItem obj={obj} index={i()} />
113118
}}
114119
</For>
120+
<Show when={local["show_count_msg"] === "visible"}>
121+
<Text size="sm" color="$neutral11">
122+
{countMsg()}
123+
</Text>
124+
</Show>
115125
</VStack>
116126
)
117127
}

src/store/local_settings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export const initialLocalSettings = [
3636
type: "select",
3737
options: ["none", "visible"],
3838
},
39+
{
40+
key: "show_count_msg",
41+
default: "none",
42+
type: "select",
43+
options: ["none", "visible"],
44+
},
3945
{
4046
key: "position_of_header_navbar",
4147
default: "static",

src/store/obj.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,22 @@ export const setPassword = (password: string) => {
224224
cookieStorage.setItem("browser-password", password)
225225
}
226226

227-
export const countMsg = (filterType?: ObjType) => {
227+
const getCountStr = (
228+
objs: StoreObj[],
229+
prefix: string,
230+
filterType?: ObjType,
231+
) => {
228232
const t = useT()
229-
const selectedList = selectedObjs()
230-
const isSelected = selectedList.length > 0
231-
let objs = isSelected ? selectedList : objStore.objs
232233

233234
if (filterType) {
234235
objs = objs.filter((obj) => obj.is_dir || obj.type === filterType)
235236
}
236237

238+
if (objs.length === 0) return ""
239+
237240
const folders = objs.filter((o) => o.is_dir).length
238241
const files = objs.length - folders
239-
240-
const vars = { folders: `${folders}`, files: `${files}` }
241-
const prefix = isSelected ? "selected" : "count"
242-
242+
const vars = { folders: folders.toString(), files: files.toString() }
243243
const key =
244244
folders && files
245245
? `${prefix}`
@@ -250,3 +250,22 @@ export const countMsg = (filterType?: ObjType) => {
250250
: ""
251251
return key ? t(`home.obj.count.${key}`, vars) : ""
252252
}
253+
254+
export const countMsg = (filterType?: ObjType) =>
255+
getCountStr(objStore.objs, "count", filterType)
256+
257+
export const selectedMsg = (filterType?: ObjType) => {
258+
const selectedList = selectedObjs()
259+
const isSelected = selectedList.length > 0
260+
261+
return isSelected ? getCountStr(selectedList, "selected", filterType) : ""
262+
}
263+
264+
export const smartCountMsg = (filterType?: ObjType) => {
265+
const selectedList = selectedObjs()
266+
const isSelected = selectedList.length > 0
267+
268+
return isSelected
269+
? getCountStr(selectedList, "selected", filterType)
270+
: countMsg(filterType)
271+
}

0 commit comments

Comments
 (0)