TagSpaces is an offline, open source, document manager with tagging support
chore: changes in the save description button (#2257)
Ilian0380f5c03421
diff --git a/src/renderer/components/EditDescription.tsx b/src/renderer/components/EditDescription.tsxindex d95b3a905..9232f9d04 100644--- a/src/renderer/components/EditDescription.tsx+++ b/src/renderer/components/EditDescription.tsx@@ -40,16 +40,19 @@ function EditDescription() {};}, []);- const milkdownListener = React.useCallback((markdown: string) => {- if (markdown !== openedEntry.meta?.description) {- // description) {- //descriptionFocus.current &&- setDescription(markdown);- /*if (descriptionButtonsRef.current) {+ const milkdownListener = React.useCallback(+ (markdown: string) => {+ if (markdown !== openedEntry.meta?.description) {+ // description) {+ //descriptionFocus.current &&+ setDescription(markdown);+ /*if (descriptionButtonsRef.current) {descriptionButtonsRef.current.setDescriptionChanged(true);}*/- }- }, []);+ }+ },+ [openedEntry],+ );//const noDescription = !description || description.length < 1;diff --git a/src/renderer/components/EditDescriptionButtons.tsx b/src/renderer/components/EditDescriptionButtons.tsxindex 3298a546a..6f6f3d745 100644--- a/src/renderer/components/EditDescriptionButtons.tsx+++ b/src/renderer/components/EditDescriptionButtons.tsx@@ -10,7 +10,7 @@ import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { Pro } from '-/pro';import { saveAsTextFile } from '-/services/utils-io';import MoreVertIcon from '@mui/icons-material/MoreVert';-import { Box, ButtonGroup } from '@mui/material';+import { Box, ButtonGroup, Tooltip, useTheme } from '@mui/material';import { formatDateTime4Tag } from '@tagspaces/tagspaces-common/misc';import React from 'react';import { useTranslation } from 'react-i18next';@@ -30,6 +30,7 @@ const EditDescriptionButtons: React.FC<ButtonsProps> = ({ getHtml }) => {} = useFilePropertiesContext();const { openedEntry, reloadOpenedFile } = useOpenedEntryContext();const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);+ const theme = useTheme();//const [isDescriptionChanged, descriptionChanged] = useState<boolean>(false);/*React.useImperativeHandle(buttonsRef, () => ({@@ -99,6 +100,20 @@ const EditDescriptionButtons: React.FC<ButtonsProps> = ({ getHtml }) => {}};+ const descrChangedMarker = isDescriptionChanged ? (+ <Tooltip title={t('core:fileChanged')}>+ <span+ style={{+ color: theme.palette.text.primary,+ marginLeft: 3,+ marginTop: -2,+ }}+ >+ {String.fromCharCode(0x25cf)}+ </span>+ </Tooltip>+ ) : null;+return (<divstyle={{@@ -117,7 +132,7 @@ const EditDescriptionButtons: React.FC<ButtonsProps> = ({ getHtml }) => {{t('core:cancel')}</TsButton>)}- <ProTooltip tooltip={t('editDescription')}>+ <ProTooltip tooltip={!isEditDescriptionMode && t('editDescription')}><TsButtondata-tid="editDescriptionTID"disabled={!Pro || isEditMode}@@ -140,10 +155,13 @@ const EditDescriptionButtons: React.FC<ButtonsProps> = ({ getHtml }) => {}}}>- {isEditDescriptionMode- ? t('core:confirmSaveButton') +- (isDescriptionChanged ? String.fromCharCode(0x25cf) : '')- : t('core:editDescription')}+ {isEditDescriptionMode ? (+ <>+ {t('core:confirmSaveButton')} {descrChangedMarker}+ </>+ ) : (+ t('core:editDescription')+ )}</TsButton></ProTooltip></ButtonGroup>diff --git a/src/renderer/hooks/FilePropertiesContextProvider.tsx b/src/renderer/hooks/FilePropertiesContextProvider.tsxindex 0920098fc..10a3406a6 100644--- a/src/renderer/hooks/FilePropertiesContextProvider.tsx+++ b/src/renderer/hooks/FilePropertiesContextProvider.tsx@@ -132,16 +132,18 @@ export const FilePropertiesContextProvider = ({}function setDescription(d: string) {- lastOpenedFile.current = {- ...lastOpenedFile.current,- meta: {- ...lastOpenedFile.current?.meta,- description: d,- },- };- if (!isDescriptionChanged.current) {- isDescriptionChanged.current = true;- forceUpdate();+ if (lastOpenedFile.current?.meta?.description !== d) {+ lastOpenedFile.current = {+ ...lastOpenedFile.current,+ meta: {+ ...lastOpenedFile.current?.meta,+ description: d,+ },+ };+ if (!isDescriptionChanged.current) {+ isDescriptionChanged.current = true;+ forceUpdate();+ }}}diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsxindex 9c313db26..38c6c1792 100644--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx@@ -245,8 +245,10 @@ export const OpenedEntryContextProvider = ({action.action === 'bgdColorChange' ||action.action === 'thumbChange' ||action.action === 'bgdImgChange' ||- action.action === 'descriptionChange' ||- action.action === 'autoSaveChange'+ action.action === 'autoSaveChange' ||+ (action.action === 'descriptionChange' &&+ currentEntry.current.meta.description !==+ action.entry.meta.description)) {currentEntry.current = {...currentEntry.current,