Skip to content

Commit

Permalink
fix(archive): support meta content sort (#236)
Browse files Browse the repository at this point in the history
* fix(archive): support meta content sort

* fix: context menu style fail after refreshing
  • Loading branch information
KirCute authored Jan 27, 2025
1 parent cadbfe0 commit 073d486
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/pages/home/previews/archive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { Item, Menu, useContextMenu } from "solid-contextmenu"
import { TbCopy, TbLink } from "solid-icons/tb"
import { AiOutlineCloudDownload } from "solid-icons/ai"
import { Operations } from "~/pages/home/toolbar/operations"
import "solid-contextmenu/dist/style.css"

const download = (url: string) => {
window.open(url, "_blank")
Expand Down Expand Up @@ -233,6 +234,9 @@ const Preview = () => {
const [innerPaths, setInnerPaths] = createSignal<string[]>([])
const [orderBy, setOrderBy] = createSignal<OrderBy>()
const [reverse, setReverse] = createSignal(false)
const [extractFolder, setExtractFolder] = createSignal<"" | "front" | "back">(
"",
)
const getObjsMutex = createMutex()
const toList = (tree: ObjTree[] | Obj[]): List => {
let l: List = {}
Expand Down Expand Up @@ -277,6 +281,19 @@ const Preview = () => {
raw_url = resp.data.raw_url
sign = resp.data.sign
setComment(resp.data.comment)
if (resp.data.sort !== undefined) {
let order: OrderBy | undefined = undefined
if (resp.data.sort.order_by !== "") {
order = resp.data.sort.order_by
}
let re = resp.data.sort.order_direction === "desc"
let ef = resp.data.sort.extract_folder
batch(() => {
setOrderBy(order)
setReverse(re)
setExtractFolder(ef)
})
}
if (resp.data.encrypted && archive_pass === "") {
batch(() => {
setRequiringPassword(true)
Expand Down Expand Up @@ -334,10 +351,18 @@ const Preview = () => {
return (reverse() ? -1 : 1) * naturalSort(a[orderBy()!], b[orderBy()!])
})
}
let ef = extractFolder()
if (ef !== "") {
let dir: Obj[] = []
let file: Obj[] = []
ret.forEach((o) => (o.is_dir ? dir : file).push(o))
ret = ef === "front" ? dir.concat(file) : file.concat(dir)
}
return ret
}
const sortObjs = (orderBy: OrderBy, reverse?: boolean) => {
batch(() => {
setExtractFolder("")
setOrderBy(orderBy)
if (reverse !== undefined) {
setReverse(reverse)
Expand Down
5 changes: 5 additions & 0 deletions src/types/obj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export type ArchiveMeta = {
content: ObjTree[] | null
encrypted: boolean
comment: string
sort?: {
order_by: "" | "name" | "size" | "modified"
order_direction: "" | "asc" | "desc"
extract_folder: "" | "front" | "back"
}
raw_url: string
sign: string
}
Expand Down

0 comments on commit 073d486

Please sign in to comment.