mirror of
https://github.com/xuquan-nikkkki/FolderFile-Splitter-Plugin.git
synced 2026-07-22 05:37:28 +00:00
refactor: simplify popup info method
This commit is contained in:
parent
aa97dfbd87
commit
7da18d7e61
5 changed files with 26 additions and 69 deletions
|
|
@ -7,7 +7,6 @@ import { FFS_DRAG_FILE } from "src/assets/constants";
|
|||
import { useExplorer } from "src/hooks/useExplorer";
|
||||
|
||||
import FileContent, { FileProps } from "./Content";
|
||||
import { ITEM_INFO_COPY } from "src/locales";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
type Props = FileProps & {
|
||||
|
|
@ -38,16 +37,17 @@ const File = ({ file, deleteFile, disableDrag, onOpenFoldersPane }: Props) => {
|
|||
}, [onOpenFoldersPane]);
|
||||
|
||||
const getAriaLabel = () => {
|
||||
const { fileModifiedTime, fileCreatedTime } = ITEM_INFO_COPY;
|
||||
const { ctime, mtime } = file.stat;
|
||||
const { basename, stat } = file;
|
||||
const { ctime, mtime } = stat;
|
||||
const format = "YYYY-MM-DD HH:mm";
|
||||
|
||||
const modifiedInfo =
|
||||
fileModifiedTime[language] + dayjs(mtime).format(format);
|
||||
const createdInfo =
|
||||
fileCreatedTime[language] + dayjs(ctime).format(format);
|
||||
const modifiedInfo = dayjs(mtime).format(format);
|
||||
const createdInfo = dayjs(ctime).format(format);
|
||||
|
||||
return `${file.basename}\n${modifiedInfo}\n${createdInfo}`;
|
||||
if (language === "en") {
|
||||
return `${basename}\nLast modified at ${modifiedInfo}\nCreated at ${createdInfo}`;
|
||||
}
|
||||
return `${basename}\n最后修改于 ${modifiedInfo}\n创建于 ${createdInfo}`;
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import FolderContent, { FolderProps } from "./Content";
|
|||
import { useExplorer } from "src/hooks/useExplorer";
|
||||
import FolderExpandIcon from "./ExpandIcon";
|
||||
import classNames from "classnames";
|
||||
import { ITEM_INFO_COPY, PUNCTUATION_COPY } from "src/locales";
|
||||
import { pluralize } from "src/utils";
|
||||
|
||||
type Props = FolderProps & {
|
||||
onOpenFilesPane: () => void;
|
||||
|
|
@ -104,22 +104,17 @@ const Folder = ({
|
|||
};
|
||||
|
||||
const getAriaLabel = () => {
|
||||
const { name } = folder;
|
||||
const filesCount = getFilesinFolder(folder).length;
|
||||
const foldersCount = getFoldersByParent(folder).length;
|
||||
const { filesCountInFolder, foldersCountInFolder } = ITEM_INFO_COPY;
|
||||
|
||||
const filesCountInfo =
|
||||
filesCount +
|
||||
" " +
|
||||
filesCountInFolder[language] +
|
||||
(filesCount > 1 ? "s" : "");
|
||||
const foldersCountInfo =
|
||||
foldersCount +
|
||||
" " +
|
||||
foldersCountInFolder[language] +
|
||||
(foldersCount > 1 ? "s" : "");
|
||||
const filesCountInfo = pluralize(filesCount, "file");
|
||||
const foldersCountInfo = pluralize(foldersCount, "folder");
|
||||
|
||||
return `${folder.name}\n${filesCountInfo}${PUNCTUATION_COPY.comma[language]}${foldersCountInfo}`;
|
||||
if (language === "en") {
|
||||
return `${name}\n${filesCountInfo}, ${foldersCountInfo}`;
|
||||
}
|
||||
return `${name}\n${filesCount} 条笔记,${foldersCount} 个文件夹`;
|
||||
};
|
||||
|
||||
const getIndentStyle = () => {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { useExplorer } from "src/hooks/useExplorer";
|
|||
import { ExplorerStore } from "src/store";
|
||||
import TagExpandIcon from "./ExpandIcon";
|
||||
import TagContent from "./Content";
|
||||
import { ITEM_INFO_COPY, PUNCTUATION_COPY } from "src/locales";
|
||||
import { pluralize } from "src/utils";
|
||||
|
||||
type Props = {
|
||||
tag: TagNode;
|
||||
|
|
@ -39,22 +39,14 @@ const Tag = ({
|
|||
const isFocused = tag.fullPath == focusedTag?.fullPath;
|
||||
|
||||
const getAriaLabel = () => {
|
||||
const { name } = tag
|
||||
const filesCount = getFilesInTag(tag).length;
|
||||
const tagsCount = getTagsByParent(tag.fullPath).length;
|
||||
const { filesCountInTag, tagsCountInTag } = ITEM_INFO_COPY;
|
||||
|
||||
const filesCountInfo =
|
||||
filesCount +
|
||||
" " +
|
||||
filesCountInTag[language] +
|
||||
(filesCount > 1 ? "s" : "");
|
||||
const tagsCountInfo =
|
||||
tagsCount +
|
||||
" " +
|
||||
tagsCountInTag[language] +
|
||||
(tagsCount > 1 ? "s" : "");
|
||||
|
||||
return `${tag.name}\n${filesCountInfo}${PUNCTUATION_COPY.comma[language]}${tagsCountInfo}`;
|
||||
if (language === "en") {
|
||||
return `${name}\n${pluralize(filesCount, "file")}, ${pluralize(tagsCount, "tag")}`;
|
||||
}
|
||||
return `${name}\n${filesCount} 条笔记,${tagsCount} 个标签`;
|
||||
};
|
||||
|
||||
const getIndentStyle = () => {
|
||||
|
|
|
|||
|
|
@ -147,37 +147,3 @@ export const FILE_SORT_RULES_COPY: Copy = {
|
|||
zh: "手动排序",
|
||||
},
|
||||
};
|
||||
|
||||
export const PUNCTUATION_COPY: Copy = {
|
||||
comma: {
|
||||
en: ", ",
|
||||
zh: ",",
|
||||
},
|
||||
};
|
||||
|
||||
export const ITEM_INFO_COPY: Copy = {
|
||||
filesCountInFolder: {
|
||||
en: "file",
|
||||
zh: "条笔记",
|
||||
},
|
||||
foldersCountInFolder: {
|
||||
en: "folder",
|
||||
zh: "个文件夹",
|
||||
},
|
||||
filesCountInTag: {
|
||||
en: "file",
|
||||
zh: "条笔记",
|
||||
},
|
||||
tagsCountInTag: {
|
||||
en: "tag",
|
||||
zh: "个标签",
|
||||
},
|
||||
fileModifiedTime: {
|
||||
en: "Last modified at ",
|
||||
zh: "最后修改于 ",
|
||||
},
|
||||
fileCreatedTime: {
|
||||
en: "Created at ",
|
||||
zh: "创建于 ",
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,3 +13,7 @@ export const isAbstractFileIncluded = (
|
|||
files: TAbstractFile[],
|
||||
file: TAbstractFile
|
||||
): boolean => files.some((f) => f.path === file.path);
|
||||
|
||||
export const pluralize = (count: number, word: string): string => {
|
||||
return `${count} ${word}${count > 1 ? "s" : ""}`;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue