TagSpaces is an offline, open source, document manager with tagging support
dir size refactoring
sytolk89dbb72a7e5f
diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsxindex 8e6278828..866cfcfe5 100644--- a/src/renderer/components/EntryProperties.tsx+++ b/src/renderer/components/EntryProperties.tsx@@ -103,6 +103,7 @@ import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';+import RefreshIcon from '@mui/icons-material/Refresh';const PREFIX = 'EntryProperties';@@ -200,7 +201,7 @@ const defaultBackgrounds = [function EntryProperties(props: Props) {const { t } = useTranslation();const theme = useTheme();- const { openedEntry, dirProps, updateOpenedFile, sharingLink } =+ const { openedEntry, updateOpenedFile, sharingLink, getOpenedDirProps } =useOpenedEntryContext();const { renameDirectory, renameFile } = useIOActionsContext();const { addTags, removeTags, removeAllTags } = useTaggingActionsContext();@@ -216,6 +217,7 @@ function EntryProperties(props: Props) {const { ignoreByWatcher, deignoreByWatcher } = useFSWatcherContext();const dispatch: AppDispatch = useDispatch();+ const dirProps = useRef<TS.DirProp>(undefined);const fileNameRef = useRef<HTMLInputElement>(null);const sharingLinkRef = useRef<HTMLInputElement>(null);// const fileDescriptionRef = useRef<MilkdownRef>(null);@@ -246,7 +248,7 @@ function EntryProperties(props: Props) {const bgndUrl = useRef<string>(getBgndUrl());const thumbUrl = useRef<string>(getThumbUrl());- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0);+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);const firstRender = useFirstRender();useEffect(() => {@@ -344,6 +346,19 @@ function EntryProperties(props: Props) {}};+ const fileSize = () => {+ if (openedEntry.isFile) {+ return formatBytes(openedEntry.size);+ } else if (dirProps.current) {+ return formatBytes(dirProps.current.totalSize);+ }+ return t(+ PlatformIO.haveObjectStoreSupport()+ ? 'core:notAvailable'+ : 'core:counting',+ );+ };+const setThumb = (filePath, thumbFilePath) => {if (filePath !== undefined) {return switchLocationTypeByID(openedEntry.locationId).then(@@ -841,13 +856,13 @@ function EntryProperties(props: Props) {<Tooltiptitle={!PlatformIO.haveObjectStoreSupport() &&- (dirProps.dirsCount || dirProps.filesCount) &&+ dirProps.current &&!openedEntry.isFile &&- dirProps.dirsCount ++ dirProps.current.dirsCount +' ' +t('core:directories') +', ' +- dirProps.filesCount ++ dirProps.current.filesCount +' ' +t('core:files')}@@ -855,18 +870,22 @@ function EntryProperties(props: Props) {<TextFieldmargin="dense"fullWidth={true}- value={- openedEntry.size- ? formatBytes(openedEntry.size)- : t(- PlatformIO.haveObjectStoreSupport()- ? 'core:notAvailable'- : 'core:counting',- )- }+ value={fileSize()}label={t('core:fileSize')}InputProps={{readOnly: true,+ ...(!openedEntry.isFile && {+ endAdornment: (+ <RefreshIcon+ onClick={() =>+ getOpenedDirProps().then((props) => {+ dirProps.current = props;+ forceUpdate();+ })+ }+ />+ ),+ }),}}/></Tooltip>diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsxindex 15bad11f3..34ef3cba8 100644--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx@@ -68,7 +68,6 @@ import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';type OpenedEntryContextData = {openedEntry: OpenedEntry;- dirProps: TS.DirProp;isEntryInFullWidth: boolean;sharingLink: string;sharingParentFolderLink: string;@@ -94,11 +93,11 @@ type OpenedEntryContextData = {fileType: 'md' | 'txt' | 'html',) => void;createFile: () => void;+ getOpenedDirProps: () => Promise<TS.DirProp>;};export const OpenedEntryContext = createContext<OpenedEntryContextData>({openedEntry: undefined,- dirProps: undefined,isEntryInFullWidth: false,sharingLink: undefined,sharingParentFolderLink: undefined,@@ -116,6 +115,7 @@ export const OpenedEntryContext = createContext<OpenedEntryContextData>({goBack: () => {},createFile: () => {},createFileAdvanced: () => {},+ getOpenedDirProps: undefined,});export type OpenedEntryContextProviderProps = {@@ -153,19 +153,16 @@ export const OpenedEntryContextProvider = ({);const newHTMLFileContent = useSelector(getNewHTMLFileContent);const currentEntry = useRef<OpenedEntry>(undefined);- const dirProps = useRef<TS.DirProp>({+ /* const dirProps = useRef<TS.DirProp>({totalSize: undefined,filesCount: undefined,dirsCount: undefined,- });+ });*/const isEntryInFullWidth = useRef<boolean>(false);const sharingLink = useRef<string>(undefined);const sharingParentFolderLink = useRef<string>(undefined);const firstRender = useFirstRender();const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);- const openedEntryPath = currentEntry.current- ? currentEntry.current.path- : undefined;/*** Handle openLink from initApp@@ -188,30 +185,6 @@ export const OpenedEntryContextProvider = ({}}, []);- useEffect(() => {- if (- currentEntry.current &&- !currentEntry.current.isFile &&- !PlatformIO.haveObjectStoreSupport() &&- !PlatformIO.haveWebDavSupport()- ) {- PlatformIO.getDirProperties(currentEntry.current.path)- .then((dProps: TS.DirProp) => {- if (dProps) {- dirProps.current.dirsCount = dProps.dirsCount;- dirProps.current.filesCount = dProps.filesCount;- dirProps.current.totalSize = dProps.totalSize;- }- currentEntry.current = {- ...currentEntry.current,- size: dProps.totalSize,- };- forceUpdate();- })- .catch((ex) => console.debug('getDirProperties:', ex.message));- }- }, [openedEntryPath]);-useEffect(() => {if (actions && actions.length > 0) {for (const action of actions) {@@ -252,6 +225,23 @@ export const OpenedEntryContextProvider = ({}}, [currentDirectoryPerspective]);+ function getOpenedDirProps(): Promise<TS.DirProp> {+ if (+ currentEntry.current &&+ !currentEntry.current.isFile &&+ !PlatformIO.haveObjectStoreSupport() &&+ !PlatformIO.haveWebDavSupport()+ ) {+ return PlatformIO.getDirProperties(currentEntry.current.path).catch(+ (ex) => {+ console.debug('getDirProperties:', ex.message);+ return Promise.resolve(undefined);+ },+ );+ }+ return Promise.resolve(undefined);+ }+function setSharedLinks(openedFile?) {if (openedFile) {if (window.location.href.indexOf('?') > 0) {@@ -855,7 +845,6 @@ export const OpenedEntryContextProvider = ({const context = useMemo(() => {return {openedEntry: currentEntry.current,- dirProps: dirProps.current,isEntryInFullWidth: isEntryInFullWidth.current,sharingLink: sharingLink.current,sharingParentFolderLink: sharingParentFolderLink.current,@@ -873,11 +862,11 @@ export const OpenedEntryContextProvider = ({openLink,createFile,createFileAdvanced,+ getOpenedDirProps,};}, [currentEntry.current,isEntryInFullWidth.current,- dirProps.current,currentLocation,currentDirectoryPath,fileOpenHistory,