Skip to content

Commit 8c9380c

Browse files
committed
🐛(frontend) fix empty left panel after deleting root doc
When we were deleting a root document, the left panel was getting empty. It was because the panel thought that it was a child document and was trying clear dynamically the panel. Now, we are checking if the document is a root or not, if it is a root we just redirect to the homepage.
1 parent 3ff6d25 commit 8c9380c

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to
2323
### Fixed
2424

2525
- 🐛(service-worker) Fix useOffline Maximum update depth exceeded #1196
26+
- 🐛(frontend) fix empty left panel after deleting root doc #1197
2627
- 🐛(helm) charts generate invalid YAML for collaboration API / WS #890
2728
- 🐛(frontend) 401 redirection overridden #1214
2829

src/frontend/apps/impress/src/features/docs/doc-management/components/ModalRemoveDoc.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import { useRemoveDoc } from '../api/useRemoveDoc';
1515
import { Doc } from '../types';
1616

1717
interface ModalRemoveDocProps {
18-
onClose: () => void;
1918
doc: Doc;
20-
afterDelete?: (doc: Doc) => void;
19+
onClose: () => void;
20+
onSuccess?: (doc: Doc) => void;
2121
}
2222

2323
export const ModalRemoveDoc = ({
24-
onClose,
2524
doc,
26-
afterDelete,
25+
onClose,
26+
onSuccess,
2727
}: ModalRemoveDocProps) => {
2828
const { toast } = useToastProvider();
2929
const { t } = useTranslation();
@@ -35,19 +35,17 @@ export const ModalRemoveDoc = ({
3535
error,
3636
} = useRemoveDoc({
3737
onSuccess: () => {
38-
toast(t('The document has been deleted.'), VariantType.SUCCESS, {
39-
duration: 4000,
40-
});
41-
if (afterDelete) {
42-
afterDelete(doc);
43-
return;
44-
}
45-
46-
if (pathname === '/') {
38+
if (onSuccess) {
39+
onSuccess(doc);
40+
} else if (pathname === '/') {
4741
onClose();
4842
} else {
4943
void push('/');
5044
}
45+
46+
toast(t('The document has been deleted.'), VariantType.SUCCESS, {
47+
duration: 4000,
48+
});
5149
},
5250
});
5351

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocTreeItemActions.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ export const DocTreeItemActions = ({
125125
},
126126
});
127127

128-
const afterDelete = () => {
128+
const onSuccessDelete = () => {
129129
if (parentId) {
130130
void router.push(`/docs/${parentId}`).then(() => {
131131
setTimeout(() => {
132132
treeContext?.treeData.deleteNode(doc.id);
133133
}, 100);
134134
});
135135
} else if (doc.id === treeContext?.root?.id && !parentId) {
136-
void router.push(`/docs/`);
136+
void router.push(`/`);
137137
} else if (treeContext && treeContext.root) {
138138
void router.push(`/docs/${treeContext.root.id}`).then(() => {
139139
setTimeout(() => {
@@ -193,7 +193,7 @@ export const DocTreeItemActions = ({
193193
<ModalRemoveDoc
194194
onClose={deleteModal.onClose}
195195
doc={doc}
196-
afterDelete={afterDelete}
196+
onSuccess={onSuccessDelete}
197197
/>
198198
)}
199199
</Box>

0 commit comments

Comments
 (0)