mirror of
https://github.com/usememos/memos.git
synced 2024-11-15 11:17:58 +08:00
chore: tweak function names
This commit is contained in:
parent
c2e820400e
commit
c3cb3770cc
2 changed files with 18 additions and 14 deletions
|
@ -1,8 +1,9 @@
|
||||||
import { Tooltip } from "@mui/joy";
|
import { Tooltip } from "@mui/joy";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { BookmarkIcon, MessageCircleMoreIcon } from "lucide-react";
|
import { BookmarkIcon, MessageCircleMoreIcon } from "lucide-react";
|
||||||
import { memo, useCallback, useEffect, useRef, useState } from "react";
|
import { memo, useCallback, useRef, useState } from "react";
|
||||||
import { Link, useLocation } from "react-router-dom";
|
import { Link, useLocation } from "react-router-dom";
|
||||||
|
import useAsyncEffect from "@/hooks/useAsyncEffect";
|
||||||
import useCurrentUser from "@/hooks/useCurrentUser";
|
import useCurrentUser from "@/hooks/useCurrentUser";
|
||||||
import useNavigateTo from "@/hooks/useNavigateTo";
|
import useNavigateTo from "@/hooks/useNavigateTo";
|
||||||
import { useUserStore, useWorkspaceSettingStore, useMemoStore } from "@/store/v1";
|
import { useUserStore, useWorkspaceSettingStore, useMemoStore } from "@/store/v1";
|
||||||
|
@ -43,13 +44,14 @@ const MemoView: React.FC<Props> = (props: Props) => {
|
||||||
const currentUser = useCurrentUser();
|
const currentUser = useCurrentUser();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const user = useCurrentUser();
|
const user = useCurrentUser();
|
||||||
|
const memoStore = useMemoStore();
|
||||||
const workspaceSettingStore = useWorkspaceSettingStore();
|
const workspaceSettingStore = useWorkspaceSettingStore();
|
||||||
const workspaceMemoRelatedSetting =
|
|
||||||
workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED).memoRelatedSetting ||
|
|
||||||
WorkspaceMemoRelatedSetting.fromPartial({});
|
|
||||||
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 =
|
||||||
|
workspaceSettingStore.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,
|
||||||
|
@ -57,19 +59,16 @@ const MemoView: React.FC<Props> = (props: Props) => {
|
||||||
const relativeTimeFormat = Date.now() - memo.displayTime!.getTime() > 1000 * 60 * 60 * 24 ? "datetime" : "auto";
|
const relativeTimeFormat = Date.now() - memo.displayTime!.getTime() > 1000 * 60 * 60 * 24 ? "datetime" : "auto";
|
||||||
const readonly = memo.creator !== user?.name && !isSuperUser(user);
|
const readonly = memo.creator !== user?.name && !isSuperUser(user);
|
||||||
const isInMemoDetailPage = location.pathname.startsWith(`/m/${memo.uid}`);
|
const isInMemoDetailPage = location.pathname.startsWith(`/m/${memo.uid}`);
|
||||||
const memoStore = useMemoStore();
|
|
||||||
|
|
||||||
// Initial related data: creator.
|
// Initial related data: creator.
|
||||||
useEffect(() => {
|
useAsyncEffect(async () => {
|
||||||
(async () => {
|
const user = await userStore.getOrFetchUserByName(memo.creator);
|
||||||
const user = await userStore.getOrFetchUserByName(memo.creator);
|
setCreator(user);
|
||||||
setCreator(user);
|
|
||||||
})();
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleGotoMemoDetailPage = () => {
|
const handleGotoMemoDetailPage = useCallback(() => {
|
||||||
navigateTo(`/m/${memo.uid}`);
|
navigateTo(`/m/${memo.uid}`);
|
||||||
};
|
}, [memo.uid]);
|
||||||
|
|
||||||
const handleMemoContentClick = useCallback(async (e: React.MouseEvent) => {
|
const handleMemoContentClick = useCallback(async (e: React.MouseEvent) => {
|
||||||
const targetEl = e.target as HTMLElement;
|
const targetEl = e.target as HTMLElement;
|
||||||
|
@ -93,7 +92,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handlePinnedBookmarkClick = async () => {
|
const onPinIconClick = async () => {
|
||||||
try {
|
try {
|
||||||
if (memo.pinned) {
|
if (memo.pinned) {
|
||||||
await memoStore.updateMemo(
|
await memoStore.updateMemo(
|
||||||
|
@ -195,7 +194,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
|
||||||
{props.showPinned && memo.pinned && (
|
{props.showPinned && memo.pinned && (
|
||||||
<Tooltip title={t("common.unpin")} placement="top">
|
<Tooltip title={t("common.unpin")} placement="top">
|
||||||
<span className="cursor-pointer">
|
<span className="cursor-pointer">
|
||||||
<BookmarkIcon className="w-4 h-auto text-amber-500" onClick={handlePinnedBookmarkClick} />
|
<BookmarkIcon className="w-4 h-auto text-amber-500" onClick={onPinIconClick} />
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -25,10 +25,15 @@ const SignIn = () => {
|
||||||
const workspaceGeneralSetting =
|
const workspaceGeneralSetting =
|
||||||
workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.GENERAL).generalSetting || WorkspaceGeneralSetting.fromPartial({});
|
workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.GENERAL).generalSetting || WorkspaceGeneralSetting.fromPartial({});
|
||||||
|
|
||||||
|
// Redirect to root page if already signed in.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
window.location.href = Routes.ROOT;
|
window.location.href = Routes.ROOT;
|
||||||
}
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Prepare identity provider list.
|
||||||
|
useEffect(() => {
|
||||||
const fetchIdentityProviderList = async () => {
|
const fetchIdentityProviderList = async () => {
|
||||||
const { identityProviders } = await identityProviderServiceClient.listIdentityProviders({});
|
const { identityProviders } = await identityProviderServiceClient.listIdentityProviders({});
|
||||||
setIdentityProviderList(identityProviders);
|
setIdentityProviderList(identityProviders);
|
||||||
|
|
Loading…
Reference in a new issue