Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix edit tag group

sytolk7af13c5712fe
diff --git a/src/renderer/components/dialogs/EditTagGroupDialog.tsx b/src/renderer/components/dialogs/EditTagGroupDialog.tsx
index 08ccd4c77..1621bb4ac 100644
--- a/src/renderer/components/dialogs/EditTagGroupDialog.tsx
+++ b/src/renderer/components/dialogs/EditTagGroupDialog.tsx
@@ -65,9 +65,8 @@ function EditTagGroupDialog(props: Props) {
useState<boolean>(false);
const [inputError, setInputError] = useState<boolean>(false);
const [applyChanges, setApplyChanges] = useState<boolean>(false);
- const [locationId, setLocationId] = useState<string>(
- selectedTagGroupEntry.locationId ?? defaultTagGroupLocation,
- );
+ const [newLocationId, setNewLocationId] = useState<string>(undefined);
+ //selectedTagGroupEntry.locationId ?? defaultTagGroupLocation,
const [title, setTitle] = useState<string>(selectedTagGroupEntry.title);
const [color, setColor] = useState<string>(selectedTagGroupEntry.color);
const [textcolor, setTextcolor] = useState<string>(
@@ -76,6 +75,10 @@ function EditTagGroupDialog(props: Props) {
const theme = useTheme();
const smallScreen = useMediaQuery(theme.breakpoints.down('md'));
+ useEffect(() => {
+ setNewLocationId(undefined);
+ }, [selectedTagGroupEntry]);
+
useEffect(() => {
handleValidation();
}, [title]);
@@ -107,12 +110,15 @@ function EditTagGroupDialog(props: Props) {
}
if (selectedTagGroupEntry && selectedTagGroupEntry.children) {
- if (Pro && locationId !== selectedTagGroupEntry.locationId) {
- const location: CommonLocation = findLocation(
- selectedTagGroupEntry.locationId,
- );
- if (location) {
- removeLocationTagGroup(location, selectedTagGroupEntry.uuid);
+ if (Pro && newLocationId === undefined) {
+ // remove old location
+ if (selectedTagGroupEntry.locationId) {
+ const location: CommonLocation = findLocation(
+ selectedTagGroupEntry.locationId,
+ );
+ if (location) {
+ removeLocationTagGroup(location, selectedTagGroupEntry.uuid);
+ }
}
}
updateTagGroup({
@@ -120,7 +126,7 @@ function EditTagGroupDialog(props: Props) {
title,
color,
textcolor,
- locationId,
+ locationId: newLocationId,
modified_date: new Date().getTime(),
children: selectedTagGroupEntry.children.map((tag) => ({
...tag,
@@ -175,9 +181,14 @@ function EditTagGroupDialog(props: Props) {
</FormHelperText>
<TsSelect
fullWidth={false}
- defaultValue={locationId}
+ defaultValue={
+ selectedTagGroupEntry.locationId || defaultTagGroupLocation
+ }
onChange={(event: ChangeEvent<HTMLInputElement>) => {
- setLocationId(event.target.value);
+ const locationId = event.target.value;
+ setNewLocationId(
+ locationId === defaultTagGroupLocation ? undefined : locationId,
+ );
}}
>
<MenuItem