diff --git a/api/user_setting.go b/api/user_setting.go index 78f794a1..77c728fc 100644 --- a/api/user_setting.go +++ b/api/user_setting.go @@ -16,8 +16,8 @@ const ( UserSettingEditorFontStyleKey UserSettingKey = "editorFontStyle" // UserSettingEditorFontStyleKey is the key type for mobile editor style. UserSettingMobileEditorStyleKey UserSettingKey = "mobileEditorStyle" - // UserSettingMemoSortOptionKey is the key type for memo sort option. - UserSettingMemoSortOptionKey UserSettingKey = "memoSortOption" + // UserSettingMemoDisplayTsOptionKey is the key type for memo display ts option. + UserSettingMemoDisplayTsOptionKey UserSettingKey = "memoSortOption" ) // String returns the string format of UserSettingKey type. @@ -31,18 +31,18 @@ func (key UserSettingKey) String() string { return "editorFontFamily" case UserSettingMobileEditorStyleKey: return "mobileEditorStyle" - case UserSettingMemoSortOptionKey: - return "memoSortOption" + case UserSettingMemoDisplayTsOptionKey: + return "memoDisplayTsOption" } return "" } var ( - UserSettingLocaleValue = []string{"en", "zh", "vi"} - UserSettingMemoVisibilityValue = []Visibility{Privite, Protected, Public} - UserSettingEditorFontStyleValue = []string{"normal", "mono"} - UserSettingMobileEditorStyleValue = []string{"normal", "float"} - UserSettingMemoSortOptionKeyValue = []string{"created_ts", "updated_ts"} + UserSettingLocaleValue = []string{"en", "zh", "vi"} + UserSettingMemoVisibilityValue = []Visibility{Privite, Protected, Public} + UserSettingEditorFontStyleValue = []string{"normal", "mono"} + UserSettingMobileEditorStyleValue = []string{"normal", "float"} + UserSettingMemoDisplayTsOptionKeyValue = []string{"created_ts", "updated_ts"} ) type UserSetting struct { @@ -127,22 +127,22 @@ func (upsert UserSettingUpsert) Validate() error { if invalid { return fmt.Errorf("invalid user setting mobile editor style value") } - } else if upsert.Key == UserSettingMemoSortOptionKey { - memoSortOption := "created_ts" - err := json.Unmarshal([]byte(upsert.Value), &memoSortOption) + } else if upsert.Key == UserSettingMemoDisplayTsOptionKey { + memoDisplayTsOption := "created_ts" + err := json.Unmarshal([]byte(upsert.Value), &memoDisplayTsOption) if err != nil { - return fmt.Errorf("failed to unmarshal user setting memo sort option") + return fmt.Errorf("failed to unmarshal user setting memo display ts option") } invalid := true - for _, value := range UserSettingMemoSortOptionKeyValue { - if memoSortOption == value { + for _, value := range UserSettingMemoDisplayTsOptionKeyValue { + if memoDisplayTsOption == value { invalid = false break } } if invalid { - return fmt.Errorf("invalid user setting memo sort option value") + return fmt.Errorf("invalid user setting memo display ts option value") } } else { return fmt.Errorf("invalid user setting key") diff --git a/store/memo.go b/store/memo.go index b6680fcb..749f2088 100644 --- a/store/memo.go +++ b/store/memo.go @@ -64,22 +64,22 @@ func (s *Store) ComposeMemo(ctx context.Context, memo *api.Memo) (*api.Memo, err return nil, err } - memoSortOptionKey := api.UserSettingMemoSortOptionKey - memoSortOption, err := s.FindUserSetting(ctx, &api.UserSettingFind{ + memoDisplayTsOptionKey := api.UserSettingMemoDisplayTsOptionKey + memoDisplayTsOptionSetting, err := s.FindUserSetting(ctx, &api.UserSettingFind{ UserID: memo.CreatorID, - Key: &memoSortOptionKey, + Key: &memoDisplayTsOptionKey, }) if err != nil { return nil, err } - memoSortOptionValue := "created_ts" - if memoSortOption != nil { - err = json.Unmarshal([]byte(memoSortOption.Value), &memoSortOptionValue) + memoDisplayTsOptionValue := "created_ts" + if memoDisplayTsOptionSetting != nil { + err = json.Unmarshal([]byte(memoDisplayTsOptionSetting.Value), &memoDisplayTsOptionValue) if err != nil { - return nil, fmt.Errorf("failed to unmarshal user setting memo sort option value") + return nil, fmt.Errorf("failed to unmarshal user setting memo display ts option value") } } - if memoSortOptionValue == "updated_ts" { + if memoDisplayTsOptionValue == "updated_ts" { memo.DisplayTs = memo.UpdatedTs } diff --git a/web/src/components/ArchivedMemo.tsx b/web/src/components/ArchivedMemo.tsx index 01d8666e..38629948 100644 --- a/web/src/components/ArchivedMemo.tsx +++ b/web/src/components/ArchivedMemo.tsx @@ -12,12 +12,7 @@ interface Props { } const ArchivedMemo: React.FC = (props: Props) => { - const { memo: propsMemo } = props; - const memo = { - ...propsMemo, - createdAtStr: utils.getDateTimeString(propsMemo.createdTs), - archivedAtStr: utils.getDateTimeString(propsMemo.updatedTs ?? Date.now()), - }; + const { memo } = props; const { t } = useTranslation(); const [showConfirmDeleteBtn, toggleConfirmDeleteBtn] = useToggle(false); @@ -60,7 +55,7 @@ const ArchivedMemo: React.FC = (props: Props) => {
- {t("common.archived-at")} {memo.archivedAtStr} + {t("common.archived-at")} {utils.getDateTimeString(memo.updatedTs)}
diff --git a/web/src/components/DailyMemo.tsx b/web/src/components/DailyMemo.tsx index 67b3f665..b94d48f1 100644 --- a/web/src/components/DailyMemo.tsx +++ b/web/src/components/DailyMemo.tsx @@ -3,22 +3,13 @@ import MemoContent, { DisplayConfig } from "./MemoContent"; import MemoResources from "./MemoResources"; import "../less/daily-memo.less"; -interface DailyMemo extends Memo { - createdAtStr: string; - timeStr: string; -} - interface Props { memo: Memo; } const DailyMemo: React.FC = (props: Props) => { - const { memo: propsMemo } = props; - const memo: DailyMemo = { - ...propsMemo, - createdAtStr: utils.getDateTimeString(propsMemo.createdTs), - timeStr: utils.getTimeString(propsMemo.createdTs), - }; + const { memo } = props; + const displayTimeStr = utils.getTimeString(memo.displayTs); const displayConfig: DisplayConfig = { enableExpand: false, }; @@ -26,7 +17,7 @@ const DailyMemo: React.FC = (props: Props) => { return (
- {memo.timeStr} + {displayTimeStr}
diff --git a/web/src/components/DailyReviewDialog.tsx b/web/src/components/DailyReviewDialog.tsx index f387e292..d938fea5 100644 --- a/web/src/components/DailyReviewDialog.tsx +++ b/web/src/components/DailyReviewDialog.tsx @@ -30,10 +30,10 @@ const DailyReviewDialog: React.FC = (props: Props) => { .filter( (m) => m.rowStatus === "NORMAL" && - utils.getTimeStampByDate(m.createdTs) >= currentDateStamp && - utils.getTimeStampByDate(m.createdTs) < currentDateStamp + DAILY_TIMESTAMP + utils.getTimeStampByDate(m.displayTs) >= currentDateStamp && + utils.getTimeStampByDate(m.displayTs) < currentDateStamp + DAILY_TIMESTAMP ) - .sort((a, b) => utils.getTimeStampByDate(a.createdTs) - utils.getTimeStampByDate(b.createdTs)); + .sort((a, b) => utils.getTimeStampByDate(a.displayTs) - utils.getTimeStampByDate(b.displayTs)); const handleShareBtnClick = () => { if (!memosElRef.current) { diff --git a/web/src/components/MemoCardDialog.tsx b/web/src/components/MemoCardDialog.tsx index 44fc4d17..214a04e0 100644 --- a/web/src/components/MemoCardDialog.tsx +++ b/web/src/components/MemoCardDialog.tsx @@ -58,8 +58,8 @@ const MemoCardDialog: React.FC = (props: Props) => { if (memoTemp) { linkMemos.push({ ...memoTemp, - createdAtStr: utils.getDateTimeString(memoTemp.createdTs), - dateStr: utils.getDateString(memoTemp.createdTs), + createdAtStr: utils.getDateTimeString(memoTemp.displayTs), + dateStr: utils.getDateString(memoTemp.displayTs), }); } } @@ -70,11 +70,11 @@ const MemoCardDialog: React.FC = (props: Props) => { setLinkedMemos( linkedMemos .filter((m) => m.rowStatus === "NORMAL" && m.id !== memo.id) - .sort((a, b) => utils.getTimeStampByDate(b.createdTs) - utils.getTimeStampByDate(a.createdTs)) + .sort((a, b) => utils.getTimeStampByDate(b.displayTs) - utils.getTimeStampByDate(a.displayTs)) .map((m) => ({ ...m, - createdAtStr: utils.getDateTimeString(m.createdTs), - dateStr: utils.getDateString(m.createdTs), + createdAtStr: utils.getDateTimeString(m.displayTs), + dateStr: utils.getDateString(m.displayTs), })) ); } catch (error) { @@ -104,7 +104,7 @@ const MemoCardDialog: React.FC = (props: Props) => { if (memoTemp) { const nextMemo = { ...memoTemp, - createdAtStr: utils.getDateTimeString(memoTemp.createdTs), + createdAtStr: utils.getDateTimeString(memoTemp.displayTs), }; setLinkMemos([]); setLinkedMemos([]); @@ -169,7 +169,7 @@ const MemoCardDialog: React.FC = (props: Props) => {

- {utils.getDateTimeString(memo.createdTs)} + {utils.getDateTimeString(memo.displayTs)}

{!isVisitorMode && ( diff --git a/web/src/components/MemoList.tsx b/web/src/components/MemoList.tsx index 1c254dd1..8b772776 100644 --- a/web/src/components/MemoList.tsx +++ b/web/src/components/MemoList.tsx @@ -12,7 +12,7 @@ import "../less/memo-list.less"; const MemoList = () => { const { t } = useTranslation(); const query = useAppSelector((state) => state.location.query); - const memoSortOption = useAppSelector((state) => state.user.user?.setting.memoSortOption); + const memoDisplayTsOption = useAppSelector((state) => state.user.user?.setting.memoDisplayTsOption); const { memos, isFetching } = useAppSelector((state) => state.memo); const { tag: tagQuery, duration, type: memoType, text: textQuery, shortcutId } = query ?? {}; @@ -50,7 +50,7 @@ const MemoList = () => { if ( duration && duration.from < duration.to && - (utils.getTimeStampByDate(memo.createdTs) < duration.from || utils.getTimeStampByDate(memo.createdTs) > duration.to) + (utils.getTimeStampByDate(memo.displayTs) < duration.from || utils.getTimeStampByDate(memo.displayTs) > duration.to) ) { shouldShow = false; } @@ -88,7 +88,7 @@ const MemoList = () => { console.error(error); toastHelper.error(error.response.data.message); }); - }, [memoSortOption]); + }, [memoDisplayTsOption]); useEffect(() => { const pageWrapper = document.body.querySelector(".page-wrapper"); diff --git a/web/src/components/Settings/PreferencesSection.tsx b/web/src/components/Settings/PreferencesSection.tsx index 76f2cd69..a21a78a2 100644 --- a/web/src/components/Settings/PreferencesSection.tsx +++ b/web/src/components/Settings/PreferencesSection.tsx @@ -1,7 +1,7 @@ import { useTranslation } from "react-i18next"; import { globalService, userService } from "../../services"; import { useAppSelector } from "../../store"; -import { VISIBILITY_SELECTOR_ITEMS, MEMO_SORT_OPTION_SELECTOR_ITEMS } from "../../helpers/consts"; +import { VISIBILITY_SELECTOR_ITEMS, MEMO_DISPLAY_TS_OPTION_SELECTOR_ITEMS } from "../../helpers/consts"; import Selector from "../common/Selector"; import "../../less/settings/preferences-section.less"; @@ -52,7 +52,7 @@ const PreferencesSection = () => { }; }); - const memoSortOptionSelectorItems = MEMO_SORT_OPTION_SELECTOR_ITEMS.map((item) => { + const memoDisplayTsOptionSelectorItems = MEMO_DISPLAY_TS_OPTION_SELECTOR_ITEMS.map((item) => { return { value: item.value, text: t(`setting.preference-section.${item.value}`), @@ -76,8 +76,8 @@ const PreferencesSection = () => { await userService.upsertUserSetting("mobileEditorStyle", value); }; - const handleMemoSortOptionChanged = async (value: string) => { - await userService.upsertUserSetting("memoSortOption", value); + const handleMemoDisplayTsOptionChanged = async (value: string) => { + await userService.upsertUserSetting("memoDisplayTsOption", value); }; return ( @@ -119,9 +119,9 @@ const PreferencesSection = () => { {t("setting.preference-section.default-memo-sort-option")}
diff --git a/web/src/components/ShareMemoImageDialog.tsx b/web/src/components/ShareMemoImageDialog.tsx index d836b3e7..4a3833af 100644 --- a/web/src/components/ShareMemoImageDialog.tsx +++ b/web/src/components/ShareMemoImageDialog.tsx @@ -20,7 +20,7 @@ const ShareMemoImageDialog: React.FC = (props: Props) => { const [shortcutImgUrl, setShortcutImgUrl] = useState(""); const memo = { ...propsMemo, - createdAtStr: utils.getDateTimeString(propsMemo.createdTs), + createdAtStr: utils.getDateTimeString(propsMemo.displayTs), }; const memoElRef = useRef(null); diff --git a/web/src/components/UsageHeatMap.tsx b/web/src/components/UsageHeatMap.tsx index aec46a9c..bfb2a527 100644 --- a/web/src/components/UsageHeatMap.tsx +++ b/web/src/components/UsageHeatMap.tsx @@ -41,7 +41,7 @@ const UsageHeatMap = () => { useEffect(() => { const newStat: DailyUsageStat[] = getInitialUsageStat(usedDaysAmount, beginDayTimestemp); for (const m of memos) { - const index = (utils.getDateStampByDate(m.createdTs) - beginDayTimestemp) / (1000 * 3600 * 24) - 1; + const index = (utils.getDateStampByDate(m.displayTs) - beginDayTimestemp) / (1000 * 3600 * 24) - 1; if (index >= 0) { newStat[index].count += 1; } diff --git a/web/src/helpers/consts.ts b/web/src/helpers/consts.ts index 158a7c26..30f05a0d 100644 --- a/web/src/helpers/consts.ts +++ b/web/src/helpers/consts.ts @@ -13,7 +13,7 @@ export const VISIBILITY_SELECTOR_ITEMS = [ { text: "PRIVATE", value: "PRIVATE" }, ]; -export const MEMO_SORT_OPTION_SELECTOR_ITEMS = [ +export const MEMO_DISPLAY_TS_OPTION_SELECTOR_ITEMS = [ { text: "created_ts", value: "created_ts" }, { text: "created_ts", value: "updated_ts" }, ]; diff --git a/web/src/locales/en.json b/web/src/locales/en.json index f9db57a5..0c4e34a0 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -130,7 +130,7 @@ "default-memo-visibility": "Default memo visibility", "editor-font-style": "Editor font style", "mobile-editor-style": "Mobile editor style", - "default-memo-sort-option": "Sort by created time/updated time", + "default-memo-sort-option": "Display by created/updated time", "created_ts": "Created Time", "updated_ts": "Updated Time" }, diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index 8748f31f..8e4d0a33 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -130,7 +130,7 @@ "default-memo-visibility": "默认 Memo 可见性", "editor-font-style": "编辑器字体样式", "mobile-editor-style": "移动端编辑器样式", - "default-memo-sort-option": "按创建时间/更新时间排序", + "default-memo-sort-option": "按创建时间/更新时间显示", "created_ts": "创建时间", "updated_ts": "更新时间" }, @@ -163,4 +163,4 @@ "copied": "已复制", "succeed-copy-content": "复制内容到剪贴板成功。" } -} \ No newline at end of file +} diff --git a/web/src/pages/Explore.tsx b/web/src/pages/Explore.tsx index a88e5edf..61830818 100644 --- a/web/src/pages/Explore.tsx +++ b/web/src/pages/Explore.tsx @@ -55,7 +55,7 @@ const Explore = () => {
{state.memos.length > 0 ? ( state.memos.map((memo) => { - const createdAtStr = dayjs(memo.createdTs).locale(i18n.language).format("YYYY/MM/DD HH:mm:ss"); + const createdAtStr = dayjs(memo.displayTs).locale(i18n.language).format("YYYY/MM/DD HH:mm:ss"); return (
diff --git a/web/src/pages/MemoDetail.tsx b/web/src/pages/MemoDetail.tsx index e921b632..7b920c43 100644 --- a/web/src/pages/MemoDetail.tsx +++ b/web/src/pages/MemoDetail.tsx @@ -99,7 +99,7 @@ const MemoDetail = () => {
- {dayjs(state.memo.createdTs).locale(i18n.language).format("YYYY/MM/DD HH:mm:ss")} + {dayjs(state.memo.displayTs).locale(i18n.language).format("YYYY/MM/DD HH:mm:ss")} {user?.id === state.memo.creatorId ? ( { diff --git a/web/src/types/modules/setting.d.ts b/web/src/types/modules/setting.d.ts index 2e863618..4329f2de 100644 --- a/web/src/types/modules/setting.d.ts +++ b/web/src/types/modules/setting.d.ts @@ -3,7 +3,7 @@ interface Setting { memoVisibility: Visibility; editorFontStyle: "normal" | "mono"; mobileEditorStyle: "normal" | "float"; - memoSortOption: "created_ts" | "updated_ts"; + memoDisplayTsOption: "created_ts" | "updated_ts"; } interface UserLocaleSetting {