chore: clean duplicated requests

This commit is contained in:
Steven
2023-09-10 11:43:38 +08:00
parent ca336af4fa
commit 866937787c
16 changed files with 56 additions and 69 deletions

View File

@ -5,8 +5,8 @@ import Icon from "./Icon";
interface Props {
value: Locale;
onChange: (locale: Locale) => void;
className?: string;
onChange: (locale: Locale) => void;
}
const LocaleSelect: FC<Props> = (props: Props) => {

View File

@ -229,7 +229,7 @@ const Memo: React.FC<Props> = (props: Props) => {
<>
<Link className="flex flex-row justify-start items-center" to={`/u/${memo.creatorUsername}`}>
<UserAvatar className="!w-5 !h-auto mr-1" avatarUrl={creator.avatarUrl} />
<span className="text-sm text-gray-600 max-w-[8em] truncate dark:text-zinc-300">{creator.nickname}</span>
<span className="text-sm text-gray-600 max-w-[8em] truncate dark:text-gray-400">{creator.nickname}</span>
</Link>
<Icon.Dot className="w-4 h-auto text-gray-400 dark:text-zinc-400" />
</>

View File

@ -15,7 +15,8 @@ const MemoList: React.FC = () => {
const userStore = useUserStore();
const filterStore = useFilterStore();
const filter = filterStore.state;
const { memos, isFetching } = memoStore.state;
const { memos } = memoStore.state;
const [isFetching, setIsFetching] = useState<boolean>(true);
const [isComplete, setIsComplete] = useState<boolean>(false);
const currentUsername = userStore.getCurrentUsername();
@ -82,6 +83,7 @@ const MemoList: React.FC = () => {
} else {
setIsComplete(false);
}
setIsFetching(false);
})
.catch((error) => {
console.error(error);
@ -122,12 +124,14 @@ const MemoList: React.FC = () => {
const handleFetchMoreClick = async () => {
try {
setIsFetching(true);
const fetchedMemos = await memoStore.fetchMemos(DEFAULT_MEMO_LIMIT, memos.length);
if (fetchedMemos.length < DEFAULT_MEMO_LIMIT) {
setIsComplete(true);
} else {
setIsComplete(false);
}
setIsFetching(false);
} catch (error: any) {
console.error(error);
toast.error(error.response.data.message);

View File

@ -136,17 +136,17 @@ const PreferencesSection = () => {
<div className="inline-block min-w-full align-middle">
<table className="min-w-full divide-y divide-gray-300">
<thead>
<tr>
<th scope="col" className="py-2 pl-4 pr-3 text-left text-sm font-semibold text-gray-900">
<tr className="text-sm font-semibold text-left text-gray-900 dark:text-gray-300">
<th scope="col" className="py-2 pl-4 pr-3">
ID
</th>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-gray-900">
<th scope="col" className="px-3 py-2">
{t("common.username")}
</th>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-gray-900">
<th scope="col" className="px-3 py-2">
{t("common.nickname")}
</th>
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-gray-900">
<th scope="col" className="px-3 py-2">
{t("common.email")}
</th>
<th scope="col" className="relative py-2 pl-3 pr-4"></th>
@ -155,13 +155,13 @@ const PreferencesSection = () => {
<tbody className="divide-y divide-gray-200">
{userList.map((user) => (
<tr key={user.id}>
<td className="whitespace-nowrap py-2 pl-4 pr-3 text-sm text-gray-900">{user.id}</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-gray-500">
<td className="whitespace-nowrap py-2 pl-4 pr-3 text-sm text-gray-900 dark:text-gray-300">{user.id}</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-gray-500 dark:text-gray-300">
{user.username}
<span className="ml-1 italic">{user.rowStatus === "ARCHIVED" && "(Archived)"}</span>
</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-gray-500">{user.nickname}</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-gray-500">{user.email}</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-gray-500 dark:text-gray-300">{user.nickname}</td>
<td className="whitespace-nowrap px-3 py-2 text-sm text-gray-500 dark:text-gray-300">{user.email}</td>
<td className="relative whitespace-nowrap py-2 pl-3 pr-4 text-right text-sm font-medium flex justify-end">
{currentUser?.id === user.id ? (
<span>{t("common.yourself")}</span>

View File

@ -3,6 +3,7 @@ import { getMemoStats } from "@/helpers/api";
import { DAILY_TIMESTAMP } from "@/helpers/consts";
import { getDateStampByDate, getDateString, getTimeStampByDate } from "@/helpers/datetime";
import * as utils from "@/helpers/utils";
import { useUserV1Store } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import { useFilterStore, useMemoStore, useUserStore } from "../store/module";
import "@/less/usage-heat-map.less";
@ -32,6 +33,7 @@ const UsageHeatMap = () => {
const t = useTranslate();
const filterStore = useFilterStore();
const userStore = useUserStore();
const userV1Store = useUserV1Store();
const memoStore = useMemoStore();
const todayTimeStamp = getDateStampByDate(Date.now());
const todayDay = new Date(todayTimeStamp).getDay() + 1;
@ -47,7 +49,7 @@ const UsageHeatMap = () => {
const currentUsername = userStore.getCurrentUsername();
useEffect(() => {
userStore.getUserByUsername(currentUsername).then((user) => {
userV1Store.getOrFetchUserByUsername(currentUsername).then((user) => {
if (!user) {
return;
}
@ -56,6 +58,10 @@ const UsageHeatMap = () => {
}, [currentUsername]);
useEffect(() => {
if (memos.length === 0) {
return;
}
getMemoStats(currentUsername)
.then(({ data }) => {
setMemoAmount(data.length);

View File

@ -9,7 +9,11 @@ const UserAvatar = (props: Props) => {
const { avatarUrl, className } = props;
return (
<div className={classNames(`w-8 h-auto overflow-clip rounded-full`, className)}>
<img className="w-full h-auto rounded-full min-w-full min-h-full object-cover" src={avatarUrl || "/logo.webp"} alt="" />
<img
className="w-full h-auto rounded-full min-w-full min-h-full object-cover dark:opacity-80"
src={avatarUrl || "/logo.webp"}
alt=""
/>
</div>
);
};