feat: week from monday in heatmap for zh-Hans and ko (#2457)

* week from monday in heatmap for zh-Hans and ko

* optimize code
pull/2472/head
Athurg Gooth 2 years ago committed by GitHub
parent b966c16dd5
commit 5d69d89627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,8 +4,9 @@ import { DAILY_TIMESTAMP } from "@/helpers/consts";
import { getDateStampByDate, getDateString, getTimeStampByDate } from "@/helpers/datetime";
import * as utils from "@/helpers/utils";
import useCurrentUser from "@/hooks/useCurrentUser";
import { useGlobalStore } from "@/store/module";
import { useUserV1Store } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import { useTranslate, Translations } from "@/utils/i18n";
import { useFilterStore, useMemoStore } from "../store/module";
import "@/less/usage-heat-map.less";
@ -37,7 +38,10 @@ const UsageHeatMap = () => {
const user = useCurrentUser();
const memoStore = useMemoStore();
const todayTimeStamp = getDateStampByDate(Date.now());
const todayDay = new Date(todayTimeStamp).getDay() + 1;
const weekDay = new Date(todayTimeStamp).getDay();
const weekFromMonday = ["zh-Hans", "ko"].includes(useGlobalStore().state.locale);
const dayTips = weekFromMonday ? ["mon", "", "wed", "", "fri", "", "sun"] : ["sun", "", "tue", "", "thu", "", "sat"];
const todayDay = weekFromMonday ? (weekDay == 0 ? 7 : weekDay) : weekDay + 1;
const nullCell = new Array(7 - todayDay).fill(0);
const usedDaysAmount = (tableConfig.width - 1) * tableConfig.height + todayDay;
const beginDayTimestamp = todayTimeStamp - usedDaysAmount * DAILY_TIMESTAMP;
@ -157,13 +161,11 @@ const UsageHeatMap = () => {
))}
</div>
<div className="day-tip-text-container">
<span className="tip-text">{t("days.sun")}</span>
<span className="tip-text"></span>
<span className="tip-text">{t("days.tue")}</span>
<span className="tip-text"></span>
<span className="tip-text">{t("days.thu")}</span>
<span className="tip-text"></span>
<span className="tip-text">{t("days.sat")}</span>
{dayTips.map((v, i) => (
<span className="tip-text" key={i}>
{v && t(("days." + v) as Translations)}
</span>
))}
</div>
</div>
<p className="w-full pl-4 text-xs -mt-2 mb-3 text-gray-400 dark:text-zinc-400">

@ -38,7 +38,7 @@ export const findNearestLanguageMatch = (codename: string): Locale => {
};
// Represents the keys of nested translation objects.
type Translations = NestedKeyOf<typeof locales>;
export type Translations = NestedKeyOf<typeof locales>;
// Represents a typed translation function.
type TypedT = (key: Translations, params?: Record<string, any>) => string;

Loading…
Cancel
Save