mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: allow users to customize the refresh time for Daily Reviews (#1313)
* feat: Allow users to customize the refresh time for Daily Reviews * feat: Allow users to customize the refresh time for Daily Reviews. Lint fix * feat: Allow users to customize the refresh time for Daily Reviews. change daily review time offset to include only hour * feat: Allow users to customize the refresh time for Daily Reviews. Retrigger to try CodeQL pass. --------- Co-authored-by: Aswath S <aswath.s@thoughtworks.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useMemoStore } from "../store/module";
|
import { useMemoStore, useUserStore } from "../store/module";
|
||||||
import toImage from "../labs/html2image";
|
import toImage from "../labs/html2image";
|
||||||
import useToggle from "../hooks/useToggle";
|
import useToggle from "../hooks/useToggle";
|
||||||
import { DAILY_TIMESTAMP } from "../helpers/consts";
|
import { DAILY_TIMESTAMP } from "../helpers/consts";
|
||||||
@ -23,17 +23,23 @@ const DailyReviewDialog: React.FC<Props> = (props: Props) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const memoStore = useMemoStore();
|
const memoStore = useMemoStore();
|
||||||
const memos = memoStore.state.memos;
|
const memos = memoStore.state.memos;
|
||||||
|
|
||||||
|
const userStore = useUserStore();
|
||||||
|
const { localSetting } = userStore.state.user as User;
|
||||||
const [currentDateStamp, setCurrentDateStamp] = useState(utils.getDateStampByDate(utils.getDateString(props.currentDateStamp)));
|
const [currentDateStamp, setCurrentDateStamp] = useState(utils.getDateStampByDate(utils.getDateString(props.currentDateStamp)));
|
||||||
const [showDatePicker, toggleShowDatePicker] = useToggle(false);
|
const [showDatePicker, toggleShowDatePicker] = useToggle(false);
|
||||||
const memosElRef = useRef<HTMLDivElement>(null);
|
const memosElRef = useRef<HTMLDivElement>(null);
|
||||||
const currentDate = new Date(currentDateStamp);
|
const currentDate = new Date(currentDateStamp);
|
||||||
const dailyMemos = memos
|
const dailyMemos = memos
|
||||||
.filter(
|
.filter((m) => {
|
||||||
(m) =>
|
const createdTimestamp = utils.getTimeStampByDate(m.createdTs);
|
||||||
|
const currentDateStampWithOffset = currentDateStamp + utils.convertToMillis(localSetting);
|
||||||
|
return (
|
||||||
m.rowStatus === "NORMAL" &&
|
m.rowStatus === "NORMAL" &&
|
||||||
utils.getTimeStampByDate(m.createdTs) >= currentDateStamp &&
|
createdTimestamp >= currentDateStampWithOffset &&
|
||||||
utils.getTimeStampByDate(m.createdTs) < currentDateStamp + DAILY_TIMESTAMP
|
createdTimestamp < currentDateStampWithOffset + DAILY_TIMESTAMP
|
||||||
)
|
);
|
||||||
|
})
|
||||||
.sort((a, b) => utils.getTimeStampByDate(a.createdTs) - utils.getTimeStampByDate(b.createdTs));
|
.sort((a, b) => utils.getTimeStampByDate(a.createdTs) - utils.getTimeStampByDate(b.createdTs));
|
||||||
|
|
||||||
const handleShareBtnClick = () => {
|
const handleShareBtnClick = () => {
|
||||||
|
@ -20,6 +20,8 @@ const PreferencesSection = () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const dailyReviewTimeOffsetOptions: number[] = [...Array(24).keys()];
|
||||||
|
|
||||||
const handleLocaleSelectChange = async (locale: Locale) => {
|
const handleLocaleSelectChange = async (locale: Locale) => {
|
||||||
await userStore.upsertUserSetting("locale", locale);
|
await userStore.upsertUserSetting("locale", locale);
|
||||||
globalStore.setLocale(locale);
|
globalStore.setLocale(locale);
|
||||||
@ -46,6 +48,10 @@ const PreferencesSection = () => {
|
|||||||
userStore.upsertLocalSetting({ ...localSetting, enableDoubleClickEditing: event.target.checked });
|
userStore.upsertLocalSetting({ ...localSetting, enableDoubleClickEditing: event.target.checked });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDailyReviewTimeOffsetChanged = (value: number) => {
|
||||||
|
userStore.upsertLocalSetting({ ...localSetting, dailyReviewTimeOffset: value });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="section-container preferences-section-container">
|
<div className="section-container preferences-section-container">
|
||||||
<p className="title-text">{t("common.basic")}</p>
|
<p className="title-text">{t("common.basic")}</p>
|
||||||
@ -94,6 +100,37 @@ const PreferencesSection = () => {
|
|||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="form-label selector">
|
||||||
|
<span className="normal-text">Daily Review Time Offset</span>
|
||||||
|
<span className="w-auto inline-flex">
|
||||||
|
<Select
|
||||||
|
placeholder="hh"
|
||||||
|
className="!min-w-[4rem] w-auto text-sm"
|
||||||
|
value={localSetting.dailyReviewTimeOffset}
|
||||||
|
onChange={(_, value) => {
|
||||||
|
if (value !== null) {
|
||||||
|
handleDailyReviewTimeOffsetChanged(value);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
slotProps={{
|
||||||
|
listbox: {
|
||||||
|
sx: {
|
||||||
|
maxHeight: "15rem",
|
||||||
|
overflow: "auto",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{dailyReviewTimeOffsetOptions.map((item) => (
|
||||||
|
<Option key={item} value={item} className="whitespace-nowrap">
|
||||||
|
{item.toString().padStart(2, "0")}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<label className="form-label selector">
|
<label className="form-label selector">
|
||||||
<span className="normal-text">{t("setting.preference-section.enable-folding-memo")}</span>
|
<span className="normal-text">{t("setting.preference-section.enable-folding-memo")}</span>
|
||||||
<Switch className="ml-2" checked={localSetting.enableFoldMemo} onChange={handleIsFoldingEnabledChanged} />
|
<Switch className="ml-2" checked={localSetting.enableFoldMemo} onChange={handleIsFoldingEnabledChanged} />
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
export function convertToMillis(localSetting: LocalSetting) {
|
||||||
|
const hoursToMillis = localSetting.dailyReviewTimeOffset * 60 * 60 * 1000;
|
||||||
|
return hoursToMillis;
|
||||||
|
}
|
||||||
|
|
||||||
export const isNullorUndefined = (value: any) => {
|
export const isNullorUndefined = (value: any) => {
|
||||||
return value === null || value === undefined;
|
return value === null || value === undefined;
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,7 @@ const defaultSetting: Setting = {
|
|||||||
const defaultLocalSetting: LocalSetting = {
|
const defaultLocalSetting: LocalSetting = {
|
||||||
enableFoldMemo: true,
|
enableFoldMemo: true,
|
||||||
enableDoubleClickEditing: true,
|
enableDoubleClickEditing: true,
|
||||||
|
dailyReviewTimeOffset: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const convertResponseModelUser = (user: User): User => {
|
export const convertResponseModelUser = (user: User): User => {
|
||||||
|
1
web/src/types/modules/setting.d.ts
vendored
1
web/src/types/modules/setting.d.ts
vendored
@ -10,6 +10,7 @@ interface Setting {
|
|||||||
interface LocalSetting {
|
interface LocalSetting {
|
||||||
enableFoldMemo: boolean;
|
enableFoldMemo: boolean;
|
||||||
enableDoubleClickEditing: boolean;
|
enableDoubleClickEditing: boolean;
|
||||||
|
dailyReviewTimeOffset: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserLocaleSetting {
|
interface UserLocaleSetting {
|
||||||
|
Reference in New Issue
Block a user