Skip to content

Commit 45ca846

Browse files
feat: add dynamic message for selected and total object counts (#38)
1 parent 95cb0b2 commit 45ca846

File tree

5 files changed

+77
-23
lines changed

5 files changed

+77
-23
lines changed

src/lang/en/home.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
"obj": {
33
"name": "Name",
44
"size": "Size",
5-
"modified": "Modified"
5+
"modified": "Modified",
6+
"count": {
7+
"count": "{{folders}} folders, {{files}} files in total",
8+
"count_folders": "{{folders}} folders in total",
9+
"count_files": "{{files}} files in total",
10+
"selected": "{{folders}} folders, {{files}} files selected",
11+
"selected_folders": "{{folders}} folders selected",
12+
"selected_files": "{{files}} files selected"
13+
}
614
},
715
"preview": {
816
"download": "Download",

src/pages/home/folder/Grid.tsx

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

88
const GridLayout = () => {
99
const { isMouseSupported, registerSelectContainer, captureContentMenu } =
1010
useSelectWithMouse()
1111
registerSelectContainer()
1212
return (
13-
<Grid
14-
oncapture:contextmenu={captureContentMenu}
15-
class="viselect-container"
16-
w="$full"
17-
gap="$1"
18-
templateColumns={`repeat(auto-fill, minmax(${
19-
parseInt(local["grid_item_size"]) + 20
20-
}px,1fr))`}
21-
>
22-
<For each={objStore.objs}>
23-
{(obj, i) => {
24-
return <GridItem obj={obj} index={i()} />
25-
}}
26-
</For>
27-
</Grid>
13+
<>
14+
<Box w="100%" textAlign="left" pl="$2">
15+
<Text>{countMsg()}</Text>
16+
</Box>
17+
<Grid
18+
oncapture:contextmenu={captureContentMenu}
19+
class="viselect-container"
20+
w="$full"
21+
gap="$1"
22+
templateColumns={`repeat(auto-fill, minmax(${
23+
parseInt(local["grid_item_size"]) + 20
24+
}px,1fr))`}
25+
>
26+
<For each={objStore.objs}>
27+
{(obj, i) => {
28+
return <GridItem obj={obj} index={i()} />
29+
}}
30+
</For>
31+
</Grid>
32+
</>
2833
)
2934
}
3035

src/pages/home/folder/Images.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Flex, Grid, Heading, VStack } from "@hope-ui/solid"
1+
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 { local, objStore } from "~/store"
4+
import { countMsg, local, objStore } from "~/store"
55
import { GridItem } from "./GridItem"
6-
import { StoreObj } from "~/types"
6+
import { ObjType, StoreObj } from "~/types"
77
import { useT } from "~/hooks"
88
import { useSelectWithMouse } from "./helper"
99

@@ -33,6 +33,9 @@ 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>
3639
<Show when={local["show_folder_in_image_view"] === "top"}>
3740
{folders()}
3841
</Show>

src/pages/home/folder/List.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { HStack, VStack, Text } from "@hope-ui/solid"
2-
import { batch, createEffect, createSignal, For, Show } from "solid-js"
2+
import {
3+
batch,
4+
createEffect,
5+
createMemo,
6+
createSignal,
7+
For,
8+
Show,
9+
} from "solid-js"
310
import { useT } from "~/hooks"
411
import {
512
allChecked,
613
checkboxOpen,
14+
countMsg,
715
isIndeterminate,
816
objStore,
917
selectAll,
@@ -26,6 +34,7 @@ export const ListTitle = (props: {
2634
props.sortCallback(orderBy()!, reverse())
2735
}
2836
})
37+
2938
const itemProps = (col: Col) => {
3039
return {
3140
fontWeight: "bold",
@@ -58,6 +67,7 @@ export const ListTitle = (props: {
5867
/>
5968
</Show>
6069
<Text {...itemProps(cols[0])}>{t(`home.obj.${cols[0].name}`)}</Text>
70+
<Text {...itemProps(cols[0])}>{countMsg()}</Text>
6171
</HStack>
6272
<Text w={cols[1].w} {...itemProps(cols[1])}>
6373
{t(`home.obj.${cols[1].name}`)}

src/store/obj.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import naturalSort from "typescript-natural-sort"
22
import { cookieStorage, createStorageSignal } from "@solid-primitives/storage"
33
import { createMemo, createSignal } from "solid-js"
44
import { createStore, produce } from "solid-js/store"
5-
import { Obj, StoreObj } from "~/types"
5+
import { Obj, ObjType, StoreObj } from "~/types"
66
import { bus, log } from "~/utils"
77
import { keyPressed } from "./key-event"
88
import { local } from "./local_settings"
9+
import { useT } from "~/hooks"
910

1011
export enum State {
1112
Initial, // Initial state
@@ -222,3 +223,30 @@ export const setPassword = (password: string) => {
222223
_setPassword(password)
223224
cookieStorage.setItem("browser-password", password)
224225
}
226+
227+
export const countMsg = (filterType?: ObjType) => {
228+
const t = useT()
229+
const selectedList = selectedObjs()
230+
const isSelected = selectedList.length > 0
231+
let objs = isSelected ? selectedList : objStore.objs
232+
233+
if (filterType) {
234+
objs = objs.filter((obj) => obj.is_dir || obj.type === filterType)
235+
}
236+
237+
const folders = objs.filter((o) => o.is_dir).length
238+
const files = objs.length - folders
239+
240+
const vars = { folders: `${folders}`, files: `${files}` }
241+
const prefix = isSelected ? "selected" : "count"
242+
243+
const key =
244+
folders && files
245+
? `${prefix}`
246+
: folders
247+
? `${prefix}_folders`
248+
: files
249+
? `${prefix}_files`
250+
: ""
251+
return key ? t(`home.obj.count.${key}`, vars) : ""
252+
}

0 commit comments

Comments
 (0)