Change comment sidebar to per-document persistence, closes #4985
This commit is contained in:
@@ -728,7 +728,7 @@ export const openDocumentComments = createAction({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stores.ui.toggleComments();
|
stores.ui.toggleComments(activeDocumentId);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ const AuthenticatedLayout: React.FC = ({ children }) => {
|
|||||||
const showComments =
|
const showComments =
|
||||||
!showInsights &&
|
!showInsights &&
|
||||||
!showHistory &&
|
!showHistory &&
|
||||||
!ui.commentsCollapsed &&
|
ui.activeDocumentId &&
|
||||||
|
ui.commentsExpanded.includes(ui.activeDocumentId) &&
|
||||||
team?.getPreference(TeamPreference.Commenting);
|
team?.getPreference(TeamPreference.Commenting);
|
||||||
|
|
||||||
const sidebarRight = (
|
const sidebarRight = (
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ function Comments() {
|
|||||||
const document = documents.getByUrl(match.params.documentSlug);
|
const document = documents.getByUrl(match.params.documentSlug);
|
||||||
const focusedComment = useFocusedComment();
|
const focusedComment = useFocusedComment();
|
||||||
|
|
||||||
useKeyDown("Escape", ui.collapseComments);
|
useKeyDown("Escape", () => document && ui.collapseComments(document?.id));
|
||||||
|
|
||||||
if (!document) {
|
if (!document) {
|
||||||
return null;
|
return null;
|
||||||
@@ -37,7 +37,7 @@ function Comments() {
|
|||||||
return (
|
return (
|
||||||
<Sidebar
|
<Sidebar
|
||||||
title={t("Comments")}
|
title={t("Comments")}
|
||||||
onClose={ui.collapseComments}
|
onClose={() => ui.collapseComments(document?.id)}
|
||||||
scrollable={false}
|
scrollable={false}
|
||||||
>
|
>
|
||||||
<Scrollable bottomShadow={!focusedComment} hiddenScrollbars topShadow>
|
<Scrollable bottomShadow={!focusedComment} hiddenScrollbars topShadow>
|
||||||
|
|||||||
@@ -55,7 +55,10 @@ function TitleDocumentMeta({ to, isDraft, document, ...rest }: Props) {
|
|||||||
{team?.getPreference(TeamPreference.Commenting) && (
|
{team?.getPreference(TeamPreference.Commenting) && (
|
||||||
<>
|
<>
|
||||||
•
|
•
|
||||||
<CommentLink to={documentUrl(document)} onClick={ui.toggleComments}>
|
<CommentLink
|
||||||
|
to={documentUrl(document)}
|
||||||
|
onClick={() => ui.toggleComments(document.id)}
|
||||||
|
>
|
||||||
<CommentIcon color="currentColor" size={18} />
|
<CommentIcon color="currentColor" size={18} />
|
||||||
{commentsCount
|
{commentsCount
|
||||||
? t("{{ count }} comment", { count: commentsCount })
|
? t("{{ count }} comment", { count: commentsCount })
|
||||||
|
|||||||
@@ -87,13 +87,13 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
|||||||
|
|
||||||
const handleClickComment = React.useCallback(
|
const handleClickComment = React.useCallback(
|
||||||
(commentId: string) => {
|
(commentId: string) => {
|
||||||
ui.expandComments();
|
ui.expandComments(document.id);
|
||||||
history.replace({
|
history.replace({
|
||||||
pathname: window.location.pathname.replace(/\/history$/, ""),
|
pathname: window.location.pathname.replace(/\/history$/, ""),
|
||||||
state: { commentId },
|
state: { commentId },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[ui, history]
|
[ui, document.id, history]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create a Comment model in local store when a comment mark is created, this
|
// Create a Comment model in local store when a comment mark is created, this
|
||||||
@@ -115,13 +115,13 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
|||||||
comment.id = commentId;
|
comment.id = commentId;
|
||||||
comments.add(comment);
|
comments.add(comment);
|
||||||
|
|
||||||
ui.expandComments();
|
ui.expandComments(document.id);
|
||||||
history.replace({
|
history.replace({
|
||||||
pathname: window.location.pathname.replace(/\/history$/, ""),
|
pathname: window.location.pathname.replace(/\/history$/, ""),
|
||||||
state: { commentId },
|
state: { commentId },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[comments, user?.id, props.id, ui, history]
|
[comments, user?.id, props.id, ui, document.id, history]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Soft delete the Comment model when associated mark is totally removed.
|
// Soft delete the Comment model when associated mark is totally removed.
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class UiStore {
|
|||||||
sidebarCollapsed = false;
|
sidebarCollapsed = false;
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
commentsCollapsed = false;
|
commentsExpanded: string[] = [];
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
sidebarIsResizing = false;
|
sidebarIsResizing = false;
|
||||||
@@ -100,6 +100,7 @@ class UiStore {
|
|||||||
this.sidebarRightWidth =
|
this.sidebarRightWidth =
|
||||||
data.sidebarRightWidth || defaultTheme.sidebarRightWidth;
|
data.sidebarRightWidth || defaultTheme.sidebarRightWidth;
|
||||||
this.tocVisible = !!data.tocVisible;
|
this.tocVisible = !!data.tocVisible;
|
||||||
|
this.commentsExpanded = data.commentsExpanded || [];
|
||||||
this.theme = data.theme || Theme.System;
|
this.theme = data.theme || Theme.System;
|
||||||
|
|
||||||
autorun(() => {
|
autorun(() => {
|
||||||
@@ -182,18 +183,26 @@ class UiStore {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@action
|
@action
|
||||||
collapseComments = () => {
|
collapseComments = (documentId: string) => {
|
||||||
this.commentsCollapsed = true;
|
this.commentsExpanded = this.commentsExpanded.filter(
|
||||||
|
(id) => id !== documentId
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@action
|
@action
|
||||||
expandComments = () => {
|
expandComments = (documentId: string) => {
|
||||||
this.commentsCollapsed = false;
|
if (!this.commentsExpanded.includes(documentId)) {
|
||||||
|
this.commentsExpanded.push(documentId);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@action
|
@action
|
||||||
toggleComments = () => {
|
toggleComments = (documentId: string) => {
|
||||||
this.commentsCollapsed = !this.commentsCollapsed;
|
if (this.commentsExpanded.includes(documentId)) {
|
||||||
|
this.collapseComments(documentId);
|
||||||
|
} else {
|
||||||
|
this.expandComments(documentId);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@@ -269,6 +278,7 @@ class UiStore {
|
|||||||
sidebarWidth: this.sidebarWidth,
|
sidebarWidth: this.sidebarWidth,
|
||||||
sidebarRightWidth: this.sidebarRightWidth,
|
sidebarRightWidth: this.sidebarRightWidth,
|
||||||
languagePromptDismissed: this.languagePromptDismissed,
|
languagePromptDismissed: this.languagePromptDismissed,
|
||||||
|
commentsExpanded: this.commentsExpanded,
|
||||||
theme: this.theme,
|
theme: this.theme,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user