mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat(system): support for disabling public memos (#1003)
* feat(system): support for disabling public memos * fix(web/editor): set visibility to private on disabled public memos * feat(server/memo): find/check if public memos are disabled * fix(server/memo): handle error for finding system error * fix(server/memo): unmarshal visiblity when getting system settings * chore(web): move side effect imports to end * Update memo.go --------- Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
@ -5,11 +5,14 @@ import { useGlobalStore } from "../../store/module";
|
||||
import * as api from "../../helpers/api";
|
||||
import toastHelper from "../Toast";
|
||||
import showUpdateCustomizedProfileDialog from "../UpdateCustomizedProfileDialog";
|
||||
import { useAppDispatch } from "../../store";
|
||||
import { setGlobalState } from "../../store/reducer/global";
|
||||
import "@/less/settings/system-section.less";
|
||||
|
||||
interface State {
|
||||
dbSize: number;
|
||||
allowSignUp: boolean;
|
||||
disablePublicMemos: boolean;
|
||||
additionalStyle: string;
|
||||
additionalScript: string;
|
||||
}
|
||||
@ -32,8 +35,11 @@ const SystemSection = () => {
|
||||
allowSignUp: systemStatus.allowSignUp,
|
||||
additionalStyle: systemStatus.additionalStyle,
|
||||
additionalScript: systemStatus.additionalScript,
|
||||
disablePublicMemos: systemStatus.disablePublicMemos,
|
||||
});
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
globalStore.fetchSystemStatus();
|
||||
}, []);
|
||||
@ -44,6 +50,7 @@ const SystemSection = () => {
|
||||
allowSignUp: systemStatus.allowSignUp,
|
||||
additionalStyle: systemStatus.additionalStyle,
|
||||
additionalScript: systemStatus.additionalScript,
|
||||
disablePublicMemos: systemStatus.disablePublicMemos,
|
||||
});
|
||||
}, [systemStatus]);
|
||||
|
||||
@ -100,6 +107,19 @@ const SystemSection = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleDisablePublicMemosChanged = async (value: boolean) => {
|
||||
setState({
|
||||
...state,
|
||||
disablePublicMemos: value,
|
||||
});
|
||||
// Update global store immediately as MemoEditor/Selector is dependent on this value.
|
||||
dispatch(setGlobalState({ systemStatus: { ...systemStatus, disablePublicMemos: value } }));
|
||||
await api.upsertSystemSetting({
|
||||
name: "disablePublicMemos",
|
||||
value: JSON.stringify(value),
|
||||
});
|
||||
};
|
||||
|
||||
const handleSaveAdditionalScript = async () => {
|
||||
try {
|
||||
await api.upsertSystemSetting({
|
||||
@ -133,6 +153,10 @@ const SystemSection = () => {
|
||||
<span className="normal-text">{t("setting.system-section.allow-user-signup")}</span>
|
||||
<Switch checked={state.allowSignUp} onChange={(event) => handleAllowSignUpChanged(event.target.checked)} />
|
||||
</div>
|
||||
<div className="form-label">
|
||||
<span className="normal-text">{t("setting.system-section.disable-public-memos")}</span>
|
||||
<Switch checked={state.disablePublicMemos} onChange={(event) => handleDisablePublicMemosChanged(event.target.checked)} />
|
||||
</div>
|
||||
<div className="form-label">
|
||||
<span className="normal-text">{t("setting.system-section.additional-style")}</span>
|
||||
<Button onClick={handleSaveAdditionalStyle}>{t("common.save")}</Button>
|
||||
|
Reference in New Issue
Block a user