mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: handle redirect
This commit is contained in:
@@ -3,8 +3,6 @@ import { useState } from "react";
|
|||||||
import { markdownServiceClient } from "@/grpcweb";
|
import { markdownServiceClient } from "@/grpcweb";
|
||||||
import { workspaceStore } from "@/store/v2";
|
import { workspaceStore } from "@/store/v2";
|
||||||
import { LinkMetadata } from "@/types/proto/api/v1/markdown_service";
|
import { LinkMetadata } from "@/types/proto/api/v1/markdown_service";
|
||||||
import { WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service";
|
|
||||||
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
url: string;
|
url: string;
|
||||||
@@ -21,9 +19,7 @@ const getFaviconWithGoogleS2 = (url: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Link: React.FC<Props> = ({ text, url }: Props) => {
|
const Link: React.FC<Props> = ({ text, url }: Props) => {
|
||||||
const workspaceMemoRelatedSetting =
|
const workspaceMemoRelatedSetting = workspaceStore.state.memoRelatedSetting;
|
||||||
workspaceStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED).memoRelatedSetting ||
|
|
||||||
WorkspaceMemoRelatedSetting.fromPartial({});
|
|
||||||
const [initialized, setInitialized] = useState<boolean>(false);
|
const [initialized, setInitialized] = useState<boolean>(false);
|
||||||
const [showTooltip, setShowTooltip] = useState<boolean>(false);
|
const [showTooltip, setShowTooltip] = useState<boolean>(false);
|
||||||
const [linkMetadata, setLinkMetadata] = useState<LinkMetadata | undefined>();
|
const [linkMetadata, setLinkMetadata] = useState<LinkMetadata | undefined>();
|
||||||
|
@@ -20,8 +20,6 @@ import { MemoRelation, MemoRelation_Type } from "@/types/proto/api/v1/memo_relat
|
|||||||
import { Location, Memo, Visibility } from "@/types/proto/api/v1/memo_service";
|
import { Location, Memo, Visibility } from "@/types/proto/api/v1/memo_service";
|
||||||
import { Resource } from "@/types/proto/api/v1/resource_service";
|
import { Resource } from "@/types/proto/api/v1/resource_service";
|
||||||
import { UserSetting } from "@/types/proto/api/v1/user_service";
|
import { UserSetting } from "@/types/proto/api/v1/user_service";
|
||||||
import { WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service";
|
|
||||||
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
|
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
import { convertVisibilityFromString, convertVisibilityToString } from "@/utils/memo";
|
import { convertVisibilityFromString, convertVisibilityToString } from "@/utils/memo";
|
||||||
import VisibilityIcon from "../VisibilityIcon";
|
import VisibilityIcon from "../VisibilityIcon";
|
||||||
@@ -87,9 +85,7 @@ const MemoEditor = observer((props: Props) => {
|
|||||||
relation.memo?.name === memoName && relation.relatedMemo?.name !== memoName && relation.type === MemoRelation_Type.REFERENCE,
|
relation.memo?.name === memoName && relation.relatedMemo?.name !== memoName && relation.type === MemoRelation_Type.REFERENCE,
|
||||||
)
|
)
|
||||||
: state.relationList.filter((relation) => relation.type === MemoRelation_Type.REFERENCE);
|
: state.relationList.filter((relation) => relation.type === MemoRelation_Type.REFERENCE);
|
||||||
const workspaceMemoRelatedSetting =
|
const workspaceMemoRelatedSetting = workspaceStore.state.memoRelatedSetting;
|
||||||
workspaceStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED)?.memoRelatedSetting ||
|
|
||||||
WorkspaceMemoRelatedSetting.fromPartial({});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
editorRef.current?.setContent(contentCache || "");
|
editorRef.current?.setContent(contentCache || "");
|
||||||
|
@@ -10,8 +10,6 @@ import { userStore, workspaceStore } from "@/store/v2";
|
|||||||
import { State } from "@/types/proto/api/v1/common";
|
import { State } from "@/types/proto/api/v1/common";
|
||||||
import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
|
import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
|
||||||
import { Memo, Visibility } from "@/types/proto/api/v1/memo_service";
|
import { Memo, Visibility } from "@/types/proto/api/v1/memo_service";
|
||||||
import { WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service";
|
|
||||||
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
|
|
||||||
import { cn } from "@/utils";
|
import { cn } from "@/utils";
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
import { convertVisibilityToString } from "@/utils/memo";
|
import { convertVisibilityToString } from "@/utils/memo";
|
||||||
@@ -50,9 +48,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
|
|||||||
const [showEditor, setShowEditor] = useState<boolean>(false);
|
const [showEditor, setShowEditor] = useState<boolean>(false);
|
||||||
const [creator, setCreator] = useState(userStore.getUserByName(memo.creator));
|
const [creator, setCreator] = useState(userStore.getUserByName(memo.creator));
|
||||||
const memoContainerRef = useRef<HTMLDivElement>(null);
|
const memoContainerRef = useRef<HTMLDivElement>(null);
|
||||||
const workspaceMemoRelatedSetting =
|
const workspaceMemoRelatedSetting = workspaceStore.state.memoRelatedSetting;
|
||||||
workspaceStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED).memoRelatedSetting ||
|
|
||||||
WorkspaceMemoRelatedSetting.fromPartial({});
|
|
||||||
const referencedMemos = memo.relations.filter((relation) => relation.type === MemoRelation_Type.REFERENCE);
|
const referencedMemos = memo.relations.filter((relation) => relation.type === MemoRelation_Type.REFERENCE);
|
||||||
const commentAmount = memo.relations.filter(
|
const commentAmount = memo.relations.filter(
|
||||||
(relation) => relation.type === MemoRelation_Type.COMMENT && relation.relatedMemo?.name === memo.name,
|
(relation) => relation.type === MemoRelation_Type.COMMENT && relation.relatedMemo?.name === memo.name,
|
||||||
|
@@ -7,8 +7,6 @@ import useCurrentUser from "@/hooks/useCurrentUser";
|
|||||||
import { useMemoStore } from "@/store/v1";
|
import { useMemoStore } from "@/store/v1";
|
||||||
import { workspaceStore } from "@/store/v2";
|
import { workspaceStore } from "@/store/v2";
|
||||||
import { Memo } from "@/types/proto/api/v1/memo_service";
|
import { Memo } from "@/types/proto/api/v1/memo_service";
|
||||||
import { WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service";
|
|
||||||
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
|
|
||||||
import { cn } from "@/utils";
|
import { cn } from "@/utils";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -22,9 +20,7 @@ const ReactionSelector = (props: Props) => {
|
|||||||
const memoStore = useMemoStore();
|
const memoStore = useMemoStore();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const workspaceMemoRelatedSetting =
|
const workspaceMemoRelatedSetting = workspaceStore.state.memoRelatedSetting;
|
||||||
workspaceStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED)?.memoRelatedSetting ||
|
|
||||||
WorkspaceMemoRelatedSetting.fromPartial({});
|
|
||||||
|
|
||||||
useClickAway(containerRef, () => {
|
useClickAway(containerRef, () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
@@ -12,9 +12,7 @@ import { useTranslate } from "@/utils/i18n";
|
|||||||
|
|
||||||
const MemoRelatedSettings = () => {
|
const MemoRelatedSettings = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
const originalSetting = WorkspaceMemoRelatedSetting.fromPartial(
|
const originalSetting = workspaceStore.state.memoRelatedSetting;
|
||||||
workspaceStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED)?.memoRelatedSetting || {},
|
|
||||||
);
|
|
||||||
const [memoRelatedSetting, setMemoRelatedSetting] = useState<WorkspaceMemoRelatedSetting>(originalSetting);
|
const [memoRelatedSetting, setMemoRelatedSetting] = useState<WorkspaceMemoRelatedSetting>(originalSetting);
|
||||||
const [editingReaction, setEditingReaction] = useState<string>("");
|
const [editingReaction, setEditingReaction] = useState<string>("");
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import { observer } from "mobx-react-lite";
|
||||||
import { Suspense, useEffect, useMemo, useState } from "react";
|
import { Suspense, useEffect, useMemo, useState } from "react";
|
||||||
import { Outlet, useLocation, useSearchParams } from "react-router-dom";
|
import { Outlet, useLocation, useSearchParams } from "react-router-dom";
|
||||||
import usePrevious from "react-use/lib/usePrevious";
|
import usePrevious from "react-use/lib/usePrevious";
|
||||||
@@ -7,9 +8,10 @@ import useResponsiveWidth from "@/hooks/useResponsiveWidth";
|
|||||||
import Loading from "@/pages/Loading";
|
import Loading from "@/pages/Loading";
|
||||||
import { Routes } from "@/router";
|
import { Routes } from "@/router";
|
||||||
import { useMemoFilterStore } from "@/store/v1";
|
import { useMemoFilterStore } from "@/store/v1";
|
||||||
|
import { workspaceStore } from "@/store/v2";
|
||||||
import { cn } from "@/utils";
|
import { cn } from "@/utils";
|
||||||
|
|
||||||
const RootLayout = () => {
|
const RootLayout = observer(() => {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const { sm } = useResponsiveWidth();
|
const { sm } = useResponsiveWidth();
|
||||||
@@ -21,7 +23,11 @@ const RootLayout = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!currentUser) {
|
if (!currentUser) {
|
||||||
if (([Routes.ROOT, Routes.RESOURCES, Routes.INBOX, Routes.ARCHIVED, Routes.SETTING] as string[]).includes(location.pathname)) {
|
// If disallowPublicVisibility is enabled, redirect to the login page if the user is not logged in.
|
||||||
|
if (workspaceStore.state.memoRelatedSetting.disallowPublicVisibility) {
|
||||||
|
window.location.href = Routes.AUTH;
|
||||||
|
return;
|
||||||
|
} else if (([Routes.ROOT, Routes.RESOURCES, Routes.INBOX, Routes.ARCHIVED, Routes.SETTING] as string[]).includes(location.pathname)) {
|
||||||
window.location.href = Routes.EXPLORE;
|
window.location.href = Routes.EXPLORE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -59,6 +65,6 @@ const RootLayout = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
export default RootLayout;
|
export default RootLayout;
|
||||||
|
@@ -15,7 +15,6 @@ import { memoNamePrefix, useMemoStore } from "@/store/v1";
|
|||||||
import { workspaceStore } from "@/store/v2";
|
import { workspaceStore } from "@/store/v2";
|
||||||
import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
|
import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
|
||||||
import { Memo } from "@/types/proto/api/v1/memo_service";
|
import { Memo } from "@/types/proto/api/v1/memo_service";
|
||||||
import { WorkspaceMemoRelatedSetting, WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
|
|
||||||
import { cn } from "@/utils";
|
import { cn } from "@/utils";
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
|
|
||||||
@@ -30,9 +29,7 @@ const MemoDetail = () => {
|
|||||||
const uid = params.uid;
|
const uid = params.uid;
|
||||||
const memoName = `${memoNamePrefix}${uid}`;
|
const memoName = `${memoNamePrefix}${uid}`;
|
||||||
const memo = memoStore.getMemoByName(memoName);
|
const memo = memoStore.getMemoByName(memoName);
|
||||||
const workspaceMemoRelatedSetting = WorkspaceMemoRelatedSetting.fromPartial(
|
const workspaceMemoRelatedSetting = workspaceStore.state.memoRelatedSetting;
|
||||||
workspaceStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED)?.memoRelatedSetting || {},
|
|
||||||
);
|
|
||||||
const [parentMemo, setParentMemo] = useState<Memo | undefined>(undefined);
|
const [parentMemo, setParentMemo] = useState<Memo | undefined>(undefined);
|
||||||
const [showCommentEditor, setShowCommentEditor] = useState(false);
|
const [showCommentEditor, setShowCommentEditor] = useState(false);
|
||||||
const commentRelations =
|
const commentRelations =
|
||||||
|
@@ -2,7 +2,7 @@ import { uniqBy } from "lodash-es";
|
|||||||
import { makeAutoObservable } from "mobx";
|
import { makeAutoObservable } from "mobx";
|
||||||
import { workspaceServiceClient, workspaceSettingServiceClient } from "@/grpcweb";
|
import { workspaceServiceClient, workspaceSettingServiceClient } from "@/grpcweb";
|
||||||
import { WorkspaceProfile } from "@/types/proto/api/v1/workspace_service";
|
import { WorkspaceProfile } from "@/types/proto/api/v1/workspace_service";
|
||||||
import { WorkspaceGeneralSetting, WorkspaceSetting } from "@/types/proto/api/v1/workspace_setting_service";
|
import { WorkspaceGeneralSetting, WorkspaceMemoRelatedSetting, WorkspaceSetting } from "@/types/proto/api/v1/workspace_setting_service";
|
||||||
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
|
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
|
||||||
import { isValidateLocale } from "@/utils/i18n";
|
import { isValidateLocale } from "@/utils/i18n";
|
||||||
import { workspaceSettingNamePrefix } from "../v1";
|
import { workspaceSettingNamePrefix } from "../v1";
|
||||||
@@ -20,6 +20,13 @@ class LocalState {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get memoRelatedSetting() {
|
||||||
|
return (
|
||||||
|
this.settings.find((setting) => setting.name === `${workspaceSettingNamePrefix}${WorkspaceSettingKey.MEMO_RELATED}`)
|
||||||
|
?.memoRelatedSetting || WorkspaceMemoRelatedSetting.fromPartial({})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
makeAutoObservable(this);
|
makeAutoObservable(this);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user