mirror of
https://github.com/usememos/memos.git
synced 2025-02-19 04:40:40 +01:00
chore: set default memo visibility
This commit is contained in:
parent
d5b88775d9
commit
2f33eceada
@ -60,11 +60,16 @@ const Memo: React.FC<Props> = (props: Props) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let intervalFlag = -1;
|
||||||
if (Date.now() - memo.createdTs < 1000 * 60 * 60 * 24) {
|
if (Date.now() - memo.createdTs < 1000 * 60 * 60 * 24) {
|
||||||
setInterval(() => {
|
intervalFlag = setInterval(() => {
|
||||||
setCreatedAtStr(getFormatedMemoCreatedAtStr(memo.createdTs, locale));
|
setCreatedAtStr(getFormatedMemoCreatedAtStr(memo.createdTs, locale));
|
||||||
}, 1000 * 1);
|
}, 1000 * 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearInterval(intervalFlag);
|
||||||
|
};
|
||||||
}, [locale]);
|
}, [locale]);
|
||||||
|
|
||||||
const handleShowMemoStoryDialog = () => {
|
const handleShowMemoStoryDialog = () => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect, useCallback } from "react";
|
||||||
import { editorStateService, memoService, userService } from "../services";
|
import { editorStateService, memoService, userService } from "../services";
|
||||||
import { IMAGE_URL_REG, MEMO_LINK_REG, UNKNOWN_ID } from "../helpers/consts";
|
import { IMAGE_URL_REG, MEMO_LINK_REG, UNKNOWN_ID, VISIBILITY_SELECTOR_ITEMS } from "../helpers/consts";
|
||||||
import * as utils from "../helpers/utils";
|
import * as utils from "../helpers/utils";
|
||||||
import { formatMemoContent, parseHtmlToRawText } from "../helpers/marked";
|
import { formatMemoContent, parseHtmlToRawText } from "../helpers/marked";
|
||||||
import Only from "./common/OnlyWhen";
|
import Only from "./common/OnlyWhen";
|
||||||
@ -27,11 +27,6 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
|
|||||||
const [linkMemos, setLinkMemos] = useState<LinkedMemo[]>([]);
|
const [linkMemos, setLinkMemos] = useState<LinkedMemo[]>([]);
|
||||||
const [linkedMemos, setLinkedMemos] = useState<LinkedMemo[]>([]);
|
const [linkedMemos, setLinkedMemos] = useState<LinkedMemo[]>([]);
|
||||||
const imageUrls = Array.from(memo.content.match(IMAGE_URL_REG) ?? []).map((s) => s.replace(IMAGE_URL_REG, "$1"));
|
const imageUrls = Array.from(memo.content.match(IMAGE_URL_REG) ?? []).map((s) => s.replace(IMAGE_URL_REG, "$1"));
|
||||||
const visibilityList = [
|
|
||||||
{ text: "PUBLIC", value: "PUBLIC" },
|
|
||||||
{ text: "PROTECTED", value: "PROTECTED" },
|
|
||||||
{ text: "PRIVATE", value: "PRIVATE" },
|
|
||||||
];
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchLinkedMemos = async () => {
|
const fetchLinkedMemos = async () => {
|
||||||
@ -132,7 +127,7 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
|
|||||||
<Icon.Eye className="icon-img" />
|
<Icon.Eye className="icon-img" />
|
||||||
<Selector
|
<Selector
|
||||||
className="visibility-selector"
|
className="visibility-selector"
|
||||||
dataSource={visibilityList}
|
dataSource={VISIBILITY_SELECTOR_ITEMS}
|
||||||
value={memo.visibility}
|
value={memo.visibility}
|
||||||
handleValueChanged={(value) => handleVisibilitySelectorChange(value as Visibility)}
|
handleValueChanged={(value) => handleVisibilitySelectorChange(value as Visibility)}
|
||||||
/>
|
/>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { globalService, userService } from "../../services";
|
import { globalService, userService } from "../../services";
|
||||||
import { useAppSelector } from "../../store";
|
import { useAppSelector } from "../../store";
|
||||||
|
import { VISIBILITY_SELECTOR_ITEMS } from "../../helpers/consts";
|
||||||
import useI18n from "../../hooks/useI18n";
|
import useI18n from "../../hooks/useI18n";
|
||||||
import Selector from "../common/Selector";
|
import Selector from "../common/Selector";
|
||||||
import "../../less/settings/preferences-section.less";
|
import "../../less/settings/preferences-section.less";
|
||||||
@ -26,12 +27,25 @@ const PreferencesSection: React.FC<Props> = () => {
|
|||||||
await userService.upsertUserSetting("locale", value);
|
await userService.upsertUserSetting("locale", value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDefaultMemoVisibilityChanged = async (value: string) => {
|
||||||
|
await userService.upsertUserSetting("memoVisibility", value);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="section-container preferences-section-container">
|
<div className="section-container preferences-section-container">
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
<span className="normal-text">{t("common.language")}:</span>
|
<span className="normal-text">{t("common.language")}:</span>
|
||||||
<Selector className="ml-2 w-28" value={setting.locale} dataSource={localeSelectorItems} handleValueChanged={handleLocaleChanged} />
|
<Selector className="ml-2 w-28" value={setting.locale} dataSource={localeSelectorItems} handleValueChanged={handleLocaleChanged} />
|
||||||
</label>
|
</label>
|
||||||
|
<label className="form-label">
|
||||||
|
<span className="normal-text">{t("setting.preference-section.default-memo-visibility")}:</span>
|
||||||
|
<Selector
|
||||||
|
className="ml-2 w-28"
|
||||||
|
value={setting.memoVisibility}
|
||||||
|
dataSource={VISIBILITY_SELECTOR_ITEMS}
|
||||||
|
handleValueChanged={handleDefaultMemoVisibilityChanged}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -21,3 +21,9 @@ export const LINK_URL_REG = /\[(.*?)\]\((.+?)\)/g;
|
|||||||
|
|
||||||
// linked memo regex
|
// linked memo regex
|
||||||
export const MEMO_LINK_REG = /@\[(.+?)\]\((.+?)\)/g;
|
export const MEMO_LINK_REG = /@\[(.+?)\]\((.+?)\)/g;
|
||||||
|
|
||||||
|
export const VISIBILITY_SELECTOR_ITEMS = [
|
||||||
|
{ text: "PUBLIC", value: "PUBLIC" },
|
||||||
|
{ text: "PROTECTED", value: "PROTECTED" },
|
||||||
|
{ text: "PRIVATE", value: "PRIVATE" },
|
||||||
|
];
|
||||||
|
@ -3,8 +3,6 @@ import i18nStore from "./i18nStore";
|
|||||||
import enLocale from "../../locales/en.json";
|
import enLocale from "../../locales/en.json";
|
||||||
import zhLocale from "../../locales/zh.json";
|
import zhLocale from "../../locales/zh.json";
|
||||||
|
|
||||||
type Locale = "en" | "zh";
|
|
||||||
|
|
||||||
const resources: Record<string, any> = {
|
const resources: Record<string, any> = {
|
||||||
en: enLocale,
|
en: enLocale,
|
||||||
zh: zhLocale,
|
zh: zhLocale,
|
||||||
|
@ -51,6 +51,9 @@
|
|||||||
"account-section": {
|
"account-section": {
|
||||||
"title": "Account Information"
|
"title": "Account Information"
|
||||||
},
|
},
|
||||||
|
"preference-section": {
|
||||||
|
"default-memo-visibility": "Default memo visibility"
|
||||||
|
},
|
||||||
"member-section": {
|
"member-section": {
|
||||||
"create-a-member": "Create a member"
|
"create-a-member": "Create a member"
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,9 @@
|
|||||||
"account-section": {
|
"account-section": {
|
||||||
"title": "账号信息"
|
"title": "账号信息"
|
||||||
},
|
},
|
||||||
|
"preference-section": {
|
||||||
|
"default-memo-visibility": "默认 Memo 可见性"
|
||||||
|
},
|
||||||
"member-section": {
|
"member-section": {
|
||||||
"create-a-member": "创建成员"
|
"create-a-member": "创建成员"
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import { setUser, patchUser, setHost, setOwner } from "../store/modules/user";
|
|||||||
|
|
||||||
const defauleSetting: Setting = {
|
const defauleSetting: Setting = {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
|
memoVisibility: "PRIVATE",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const convertResponseModelUser = (user: User): User => {
|
export const convertResponseModelUser = (user: User): User => {
|
||||||
|
10
web/src/types/modules/setting.d.ts
vendored
10
web/src/types/modules/setting.d.ts
vendored
@ -1,10 +1,16 @@
|
|||||||
interface Setting {
|
interface Setting {
|
||||||
locale: "en" | "zh";
|
locale: Locale;
|
||||||
|
memoVisibility: Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserLocaleSetting {
|
interface UserLocaleSetting {
|
||||||
key: "locale";
|
key: "locale";
|
||||||
value: "en" | "zh";
|
value: Locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UserMemoVisibilitySetting {
|
||||||
|
key: "memoVisibility";
|
||||||
|
value: Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserSetting = UserLocaleSetting;
|
type UserSetting = UserLocaleSetting;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user