mirror of
https://github.com/outline/outline.git
synced 2026-12-05 02:44:34 +03:00
set sidebarContext only in state
This commit is contained in:
1 parent
b749f7dd0e
commit
32ff3e1e80
10 files changed
+65
-29
No files matched your search
@@ -53,10 +53,11 @@ export const resolveCommentFactory = ({
|
||||
perform: async ({ t }) => {
|
||||
await comment.resolve();
|
||||
|
||||
const locationState = history.location.state as Record<string, unknown>;
|
||||
history.replace({
|
||||
...history.location,
|
||||
state: {
|
||||
...(history.location.state as Record<string, unknown>),
|
||||
sidebarContext: locationState["sidebarContext"],
|
||||
commentId: undefined,
|
||||
},
|
||||
});
|
||||
@@ -84,10 +85,11 @@ export const unresolveCommentFactory = ({
|
||||
perform: async () => {
|
||||
await comment.unresolve();
|
||||
|
||||
const locationState = history.location.state as Record<string, unknown>;
|
||||
history.replace({
|
||||
...history.location,
|
||||
state: {
|
||||
...(history.location.state as Record<string, unknown>),
|
||||
sidebarContext: locationState["sidebarContext"],
|
||||
commentId: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -24,6 +24,7 @@ import RevisionMenu from "~/menus/RevisionMenu";
|
||||
import { hover } from "~/styles";
|
||||
import Logger from "~/utils/Logger";
|
||||
import { documentHistoryPath } from "~/utils/routeHelpers";
|
||||
import { useLocationState } from "./Sidebar/hooks/useLocationState";
|
||||
|
||||
type Props = {
|
||||
document: Document;
|
||||
@@ -35,6 +36,7 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const { revisions } = useStores();
|
||||
const location = useLocation();
|
||||
const sidebarContext = useLocationState();
|
||||
const opts = {
|
||||
userName: event.actor.name,
|
||||
};
|
||||
@@ -67,7 +69,7 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
to = {
|
||||
pathname: documentHistoryPath(document, event.modelId || "latest"),
|
||||
state: {
|
||||
...(location.state as Record<string, unknown>),
|
||||
sidebarContext,
|
||||
retainScrollPosition: true,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { UserPreference } from "@shared/types";
|
||||
import InputSelect from "~/components/InputSelect";
|
||||
import { useLocationState } from "~/components/Sidebar/hooks/useLocationState";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import useQuery from "~/hooks/useQuery";
|
||||
import { CommentSortType } from "~/types";
|
||||
@@ -13,6 +14,7 @@ import { CommentSortType } from "~/types";
|
||||
const CommentSortMenu = () => {
|
||||
const { t } = useTranslation();
|
||||
const location = useLocation();
|
||||
const sidebarContext = useLocationState();
|
||||
const history = useHistory();
|
||||
const user = useCurrentUser();
|
||||
const params = useQuery();
|
||||
@@ -39,7 +41,7 @@ const CommentSortMenu = () => {
|
||||
resolved: "",
|
||||
}),
|
||||
pathname: location.pathname,
|
||||
state: location.state,
|
||||
state: { sidebarContext },
|
||||
});
|
||||
};
|
||||
|
||||
@@ -50,7 +52,7 @@ const CommentSortMenu = () => {
|
||||
resolved: undefined,
|
||||
}),
|
||||
pathname: location.pathname,
|
||||
state: location.state,
|
||||
state: { sidebarContext },
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { useDocumentContext } from "~/components/DocumentContext";
|
||||
import Facepile from "~/components/Facepile";
|
||||
import Fade from "~/components/Fade";
|
||||
import { ResizingHeightContainer } from "~/components/ResizingHeightContainer";
|
||||
import { useLocationState } from "~/components/Sidebar/hooks/useLocationState";
|
||||
import useOnClickOutside from "~/hooks/useOnClickOutside";
|
||||
import usePersistedState from "~/hooks/usePersistedState";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
@@ -61,6 +62,7 @@ function CommentThread({
|
||||
const { t } = useTranslation();
|
||||
const history = useHistory();
|
||||
const location = useLocation();
|
||||
const sidebarContext = useLocationState();
|
||||
const [autoFocus, setAutoFocus] = React.useState(thread.isNew);
|
||||
|
||||
const can = usePolicy(document);
|
||||
@@ -102,8 +104,8 @@ function CommentThread({
|
||||
search: location.search,
|
||||
pathname: location.pathname,
|
||||
state: {
|
||||
...(location.state as Record<string, unknown>),
|
||||
commentId: undefined,
|
||||
sidebarContext,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -119,8 +121,8 @@ function CommentThread({
|
||||
search: thread.isResolved ? "resolved=" : "",
|
||||
pathname: location.pathname.replace(/\/history$/, ""),
|
||||
state: {
|
||||
...(location.state as Record<string, unknown>),
|
||||
commentId: thread.id,
|
||||
sidebarContext,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -40,6 +40,7 @@ import LoadingIndicator from "~/components/LoadingIndicator";
|
||||
import PageTitle from "~/components/PageTitle";
|
||||
import PlaceholderDocument from "~/components/PlaceholderDocument";
|
||||
import RegisterKeyDown from "~/components/RegisterKeyDown";
|
||||
import { SidebarContextType } from "~/components/Sidebar/components/SidebarContext";
|
||||
import withStores from "~/components/withStores";
|
||||
import type { Editor as TEditor } from "~/editor";
|
||||
import { SearchResult } from "~/editor/components/LinkEditor";
|
||||
@@ -77,6 +78,7 @@ type LocationState = {
|
||||
title?: string;
|
||||
restore?: boolean;
|
||||
revisionId?: string;
|
||||
sidebarContext?: SidebarContextType;
|
||||
};
|
||||
|
||||
type Props = WithTranslation &
|
||||
@@ -246,7 +248,10 @@ class DocumentScene extends React.Component<Props> {
|
||||
const { document, abilities } = this.props;
|
||||
|
||||
if (abilities.update) {
|
||||
this.props.history.push(documentEditPath(document));
|
||||
this.props.history.push({
|
||||
pathname: documentEditPath(document),
|
||||
state: { sidebarContext: this.props.location.state?.sidebarContext },
|
||||
});
|
||||
}
|
||||
} else if (this.editor.current?.isBlurred) {
|
||||
ev.preventDefault();
|
||||
@@ -265,9 +270,15 @@ class DocumentScene extends React.Component<Props> {
|
||||
const { document, location } = this.props;
|
||||
|
||||
if (location.pathname.endsWith("history")) {
|
||||
this.props.history.push(document.url);
|
||||
this.props.history.push({
|
||||
pathname: document.url,
|
||||
state: { sidebarContext: this.props.location.state?.sidebarContext },
|
||||
});
|
||||
} else {
|
||||
this.props.history.push(documentHistoryPath(document));
|
||||
this.props.history.push({
|
||||
pathname: documentHistoryPath(document),
|
||||
state: { sidebarContext: this.props.location.state?.sidebarContext },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -333,10 +344,16 @@ class DocumentScene extends React.Component<Props> {
|
||||
this.isEditorDirty = false;
|
||||
|
||||
if (options.done) {
|
||||
this.props.history.push(savedDocument.url);
|
||||
this.props.history.push({
|
||||
pathname: savedDocument.url,
|
||||
state: { sidebarContext: this.props.location.state?.sidebarContext },
|
||||
});
|
||||
this.props.ui.setActiveDocument(savedDocument);
|
||||
} else if (document.isNew) {
|
||||
this.props.history.push(documentEditPath(savedDocument));
|
||||
this.props.history.push({
|
||||
pathname: documentEditPath(savedDocument),
|
||||
state: { sidebarContext: this.props.location.state?.sidebarContext },
|
||||
});
|
||||
this.props.ui.setActiveDocument(savedDocument);
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -392,7 +409,7 @@ class DocumentScene extends React.Component<Props> {
|
||||
if (!this.props.readOnly) {
|
||||
this.props.history.push({
|
||||
pathname: this.props.document.url,
|
||||
state: this.props.location.state,
|
||||
state: { sidebarContext: this.props.location.state?.sidebarContext },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,13 +3,14 @@ import { observer, useObserver } from "mobx-react";
|
||||
import { CommentIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link, useLocation, useRouteMatch } from "react-router-dom";
|
||||
import { Link, useRouteMatch } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { TeamPreference } from "@shared/types";
|
||||
import Document from "~/models/Document";
|
||||
import Revision from "~/models/Revision";
|
||||
import DocumentMeta from "~/components/DocumentMeta";
|
||||
import Fade from "~/components/Fade";
|
||||
import { useLocationState } from "~/components/Sidebar/hooks/useLocationState";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
@@ -27,7 +28,7 @@ function TitleDocumentMeta({ to, document, revision, ...rest }: Props) {
|
||||
const { views, comments, ui } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const match = useRouteMatch();
|
||||
const location = useLocation();
|
||||
const sidebarContext = useLocationState();
|
||||
const team = useCurrentTeam();
|
||||
const documentViews = useObserver(() => views.inDocument(document.id));
|
||||
const totalViewers = documentViews.length;
|
||||
@@ -48,7 +49,7 @@ function TitleDocumentMeta({ to, document, revision, ...rest }: Props) {
|
||||
<CommentLink
|
||||
to={{
|
||||
pathname: documentPath(document),
|
||||
state: location.state,
|
||||
state: { sidebarContext },
|
||||
}}
|
||||
onClick={() => ui.toggleComments()}
|
||||
>
|
||||
@@ -71,7 +72,7 @@ function TitleDocumentMeta({ to, document, revision, ...rest }: Props) {
|
||||
match.url === insightsPath
|
||||
? documentPath(document)
|
||||
: insightsPath,
|
||||
state: location.state,
|
||||
state: { sidebarContext },
|
||||
}}
|
||||
>
|
||||
{t("Viewed by")}{" "}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { mergeRefs } from "react-merge-refs";
|
||||
import { useHistory, useLocation, useRouteMatch } from "react-router-dom";
|
||||
import { useHistory, useRouteMatch } from "react-router-dom";
|
||||
import { richExtensions, withComments } from "@shared/editor/nodes";
|
||||
import { TeamPreference } from "@shared/types";
|
||||
import { colorPalette } from "@shared/utils/collections";
|
||||
@@ -13,6 +13,7 @@ import { RefHandle } from "~/components/ContentEditable";
|
||||
import { useDocumentContext } from "~/components/DocumentContext";
|
||||
import Editor, { Props as EditorProps } from "~/components/Editor";
|
||||
import Flex from "~/components/Flex";
|
||||
import { useLocationState } from "~/components/Sidebar/hooks/useLocationState";
|
||||
import BlockMenuExtension from "~/editor/extensions/BlockMenu";
|
||||
import ClipboardTextSerializer from "~/editor/extensions/ClipboardTextSerializer";
|
||||
import EmojiMenuExtension from "~/editor/extensions/EmojiMenu";
|
||||
@@ -82,7 +83,7 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
const user = useCurrentUser({ rejectOnEmpty: false });
|
||||
const team = useCurrentTeam({ rejectOnEmpty: false });
|
||||
const history = useHistory();
|
||||
const location = useLocation();
|
||||
const sidebarContext = useLocationState();
|
||||
const params = useQuery();
|
||||
const {
|
||||
document,
|
||||
@@ -115,14 +116,14 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
search: focusedComment.isResolved ? "resolved=" : "",
|
||||
pathname: location.pathname,
|
||||
state: {
|
||||
...(location.state as Record<string, unknown>),
|
||||
commentId: focusedComment.id,
|
||||
sidebarContext,
|
||||
},
|
||||
});
|
||||
}
|
||||
ui.set({ commentsExpanded: true });
|
||||
}
|
||||
}, [focusedComment, ui, document.id, history, location, params]);
|
||||
}, [focusedComment, ui, document.id, history, params, sidebarContext]);
|
||||
|
||||
// Save document when blurring title, but delay so that if clicking on a
|
||||
// button this is allowed to execute first.
|
||||
@@ -147,10 +148,10 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
(commentId: string) => {
|
||||
history.replace({
|
||||
pathname: window.location.pathname.replace(/\/history$/, ""),
|
||||
state: { ...(location.state as Record<string, unknown>), commentId },
|
||||
state: { commentId, sidebarContext },
|
||||
});
|
||||
},
|
||||
[history, location]
|
||||
[history, sidebarContext]
|
||||
);
|
||||
|
||||
// Create a Comment model in local store when a comment mark is created, this
|
||||
@@ -175,10 +176,10 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
|
||||
history.replace({
|
||||
pathname: window.location.pathname.replace(/\/history$/, ""),
|
||||
state: { ...(location.state as Record<string, unknown>), commentId },
|
||||
state: { commentId, sidebarContext },
|
||||
});
|
||||
},
|
||||
[comments, user?.id, props.id, history, location]
|
||||
[comments, user?.id, props.id, history, sidebarContext]
|
||||
);
|
||||
|
||||
// Soft delete the Comment model when associated mark is totally removed.
|
||||
@@ -247,7 +248,7 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
match.path === matchDocumentHistory
|
||||
? documentPath(document)
|
||||
: documentHistoryPath(document),
|
||||
state: location.state,
|
||||
state: { sidebarContext },
|
||||
}}
|
||||
rtl={
|
||||
titleRef.current?.getComputedDirection() === "rtl" ? true : false
|
||||
|
||||
@@ -24,6 +24,7 @@ import { useDocumentContext } from "~/components/DocumentContext";
|
||||
import Flex from "~/components/Flex";
|
||||
import Header from "~/components/Header";
|
||||
import Icon from "~/components/Icon";
|
||||
import { useLocationState } from "~/components/Sidebar/hooks/useLocationState";
|
||||
import Star from "~/components/Star";
|
||||
import Tooltip from "~/components/Tooltip";
|
||||
import { publishDocument } from "~/actions/definitions/documents";
|
||||
@@ -91,6 +92,7 @@ function DocumentHeader({
|
||||
const isEditingFocus = useEditingFocus();
|
||||
const { editor } = useDocumentContext();
|
||||
const { hasHeadings } = useDocumentContext();
|
||||
const sidebarContext = useLocationState();
|
||||
|
||||
// We cache this value for as long as the component is mounted so that if you
|
||||
// apply a template there is still the option to replace it until the user
|
||||
@@ -154,7 +156,10 @@ function DocumentHeader({
|
||||
<Button
|
||||
as={Link}
|
||||
icon={<EditIcon />}
|
||||
to={documentEditPath(document)}
|
||||
to={{
|
||||
pathname: documentEditPath(document),
|
||||
state: { sidebarContext },
|
||||
}}
|
||||
neutral
|
||||
>
|
||||
{isMobile ? null : t("Edit")}
|
||||
|
||||
@@ -8,6 +8,7 @@ import Document from "~/models/Document";
|
||||
import Event from "~/models/Event";
|
||||
import Empty from "~/components/Empty";
|
||||
import PaginatedEventList from "~/components/PaginatedEventList";
|
||||
import { useLocationState } from "~/components/Sidebar/hooks/useLocationState";
|
||||
import useKeyDown from "~/hooks/useKeyDown";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { documentPath } from "~/utils/routeHelpers";
|
||||
@@ -20,6 +21,7 @@ function History() {
|
||||
const { t } = useTranslation();
|
||||
const match = useRouteMatch<{ documentSlug: string }>();
|
||||
const history = useHistory();
|
||||
const sidebarContext = useLocationState();
|
||||
const document = documents.getByUrl(match.params.documentSlug);
|
||||
|
||||
const eventsInDocument = document
|
||||
@@ -30,7 +32,7 @@ function History() {
|
||||
if (document) {
|
||||
history.push({
|
||||
pathname: documentPath(document),
|
||||
state: history.location.state,
|
||||
state: { sidebarContext },
|
||||
});
|
||||
} else {
|
||||
history.goBack();
|
||||
|
||||
@@ -13,6 +13,7 @@ import DocumentViews from "~/components/DocumentViews";
|
||||
import Flex from "~/components/Flex";
|
||||
import ListItem from "~/components/List/Item";
|
||||
import PaginatedList from "~/components/PaginatedList";
|
||||
import { useLocationState } from "~/components/Sidebar/hooks/useLocationState";
|
||||
import Text from "~/components/Text";
|
||||
import Time from "~/components/Time";
|
||||
import useKeyDown from "~/hooks/useKeyDown";
|
||||
@@ -28,6 +29,7 @@ function Insights() {
|
||||
const { t } = useTranslation();
|
||||
const match = useRouteMatch<{ documentSlug: string }>();
|
||||
const history = useHistory();
|
||||
const sidebarContext = useLocationState();
|
||||
const selectedText = useTextSelection();
|
||||
const document = documents.getByUrl(match.params.documentSlug);
|
||||
const { editor } = useDocumentContext();
|
||||
@@ -40,7 +42,7 @@ function Insights() {
|
||||
if (document) {
|
||||
history.push({
|
||||
pathname: documentPath(document),
|
||||
state: history.location.state,
|
||||
state: { sidebarContext },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user