fix: default visibility setting
This commit is contained in:
parent
86013d6c2a
commit
ac37738148
4 changed files with 23 additions and 6 deletions
|
|
@ -421,7 +421,7 @@ func (s *APIV1Service) UpdateUserSetting(ctx context.Context, request *v1pb.Upda
|
||||||
incomingGeneral := request.Setting.GetGeneralSetting()
|
incomingGeneral := request.Setting.GetGeneralSetting()
|
||||||
for _, field := range request.UpdateMask.Paths {
|
for _, field := range request.UpdateMask.Paths {
|
||||||
switch field {
|
switch field {
|
||||||
case "memoVisibility":
|
case "memo_visibility":
|
||||||
updatedGeneral.MemoVisibility = incomingGeneral.MemoVisibility
|
updatedGeneral.MemoVisibility = incomingGeneral.MemoVisibility
|
||||||
case "theme":
|
case "theme":
|
||||||
updatedGeneral.Theme = incomingGeneral.Theme
|
updatedGeneral.Theme = incomingGeneral.Theme
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
|
import type { Visibility } from "@/types/proto/api/v1/memo_service_pb";
|
||||||
import type { EditorRefActions } from "../Editor";
|
import type { EditorRefActions } from "../Editor";
|
||||||
import { cacheService, memoService } from "../services";
|
import { cacheService, memoService } from "../services";
|
||||||
import { useEditorContext } from "../state";
|
import { useEditorContext } from "../state";
|
||||||
|
|
@ -9,6 +10,7 @@ export const useMemoInit = (
|
||||||
cacheKey: string | undefined,
|
cacheKey: string | undefined,
|
||||||
username: string,
|
username: string,
|
||||||
autoFocus?: boolean,
|
autoFocus?: boolean,
|
||||||
|
defaultVisibility?: Visibility,
|
||||||
) => {
|
) => {
|
||||||
const { actions, dispatch } = useEditorContext();
|
const { actions, dispatch } = useEditorContext();
|
||||||
const initializedRef = useRef(false);
|
const initializedRef = useRef(false);
|
||||||
|
|
@ -37,6 +39,10 @@ export const useMemoInit = (
|
||||||
if (cachedContent) {
|
if (cachedContent) {
|
||||||
dispatch(actions.updateContent(cachedContent));
|
dispatch(actions.updateContent(cachedContent));
|
||||||
}
|
}
|
||||||
|
// Apply default visibility for new memos
|
||||||
|
if (defaultVisibility !== undefined) {
|
||||||
|
dispatch(actions.setMetadata({ visibility: defaultVisibility }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to initialize editor:", error);
|
console.error("Failed to initialize editor:", error);
|
||||||
|
|
@ -52,5 +58,5 @@ export const useMemoInit = (
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}, [memoName, cacheKey, username, autoFocus, actions, dispatch, editorRef]);
|
}, [memoName, cacheKey, username, autoFocus, defaultVisibility, actions, dispatch, editorRef]);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { useRef } from "react";
|
import { useRef } from "react";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
|
import { useAuth } from "@/contexts/AuthContext";
|
||||||
import useCurrentUser from "@/hooks/useCurrentUser";
|
import useCurrentUser from "@/hooks/useCurrentUser";
|
||||||
import { memoKeys } from "@/hooks/useMemoQueries";
|
import { memoKeys } from "@/hooks/useMemoQueries";
|
||||||
import { userKeys } from "@/hooks/useUserQueries";
|
import { userKeys } from "@/hooks/useUserQueries";
|
||||||
import { handleError } from "@/lib/error";
|
import { handleError } from "@/lib/error";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
|
import { convertVisibilityFromString } from "@/utils/memo";
|
||||||
import { EditorContent, EditorMetadata, EditorToolbar, FocusModeExitButton, FocusModeOverlay } from "./components";
|
import { EditorContent, EditorMetadata, EditorToolbar, FocusModeExitButton, FocusModeOverlay } from "./components";
|
||||||
import { FOCUS_MODE_STYLES } from "./constants";
|
import { FOCUS_MODE_STYLES } from "./constants";
|
||||||
import type { EditorRefActions } from "./Editor";
|
import type { EditorRefActions } from "./Editor";
|
||||||
|
|
@ -49,8 +51,14 @@ const MemoEditorImpl: React.FC<MemoEditorProps> = ({
|
||||||
const currentUser = useCurrentUser();
|
const currentUser = useCurrentUser();
|
||||||
const editorRef = useRef<EditorRefActions>(null);
|
const editorRef = useRef<EditorRefActions>(null);
|
||||||
const { state, actions, dispatch } = useEditorContext();
|
const { state, actions, dispatch } = useEditorContext();
|
||||||
|
const { userGeneralSetting } = useAuth();
|
||||||
|
|
||||||
useMemoInit(editorRef, memoName, cacheKey, currentUser?.name ?? "", autoFocus);
|
// Get default visibility from user settings
|
||||||
|
const defaultVisibility = userGeneralSetting?.memoVisibility
|
||||||
|
? convertVisibilityFromString(userGeneralSetting.memoVisibility)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
useMemoInit(editorRef, memoName, cacheKey, currentUser?.name ?? "", autoFocus, defaultVisibility);
|
||||||
|
|
||||||
// Auto-save content to localStorage
|
// Auto-save content to localStorage
|
||||||
useAutoSave(state.content, currentUser?.name ?? "", cacheKey);
|
useAutoSave(state.content, currentUser?.name ?? "", cacheKey);
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ const PreferencesSection = () => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDefaultMemoVisibilityChanged = async (value: string) => {
|
const handleDefaultMemoVisibilityChanged = (value: string) => {
|
||||||
updateUserGeneralSetting(
|
updateUserGeneralSetting(
|
||||||
{ generalSetting: { memoVisibility: value }, updateMask: ["memoVisibility"] },
|
{ generalSetting: { memoVisibility: value }, updateMask: ["memo_visibility"] },
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
refetchSettings();
|
refetchSettings();
|
||||||
|
|
@ -82,7 +82,10 @@ const PreferencesSection = () => {
|
||||||
|
|
||||||
<SettingGroup title={t("setting.preference")} showSeparator>
|
<SettingGroup title={t("setting.preference")} showSeparator>
|
||||||
<SettingRow label={t("setting.preference-section.default-memo-visibility")}>
|
<SettingRow label={t("setting.preference-section.default-memo-visibility")}>
|
||||||
<Select value={setting.memoVisibility} onValueChange={handleDefaultMemoVisibilityChanged}>
|
<Select
|
||||||
|
value={setting.memoVisibility || "PRIVATE"}
|
||||||
|
onValueChange={handleDefaultMemoVisibilityChanged}
|
||||||
|
>
|
||||||
<SelectTrigger className="min-w-fit">
|
<SelectTrigger className="min-w-fit">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<VisibilityIcon visibility={convertVisibilityFromString(setting.memoVisibility)} />
|
<VisibilityIcon visibility={convertVisibilityFromString(setting.memoVisibility)} />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue