Skip to content

Commit

Permalink
feat: update timeline page
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed May 8, 2024
1 parent 33133ea commit 1d99dad
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 229 deletions.
15 changes: 10 additions & 5 deletions web/src/components/ActivityCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslate } from "@/utils/i18n";
interface Props {
// Format: 2021-1
month: string;
selectedDate: string;
data: Record<string, number>;
onClick?: (date: string) => void;
}
Expand All @@ -28,8 +29,8 @@ const getCellAdditionalStyles = (count: number, maxCount: number) => {
const ActivityCalendar = (props: Props) => {
const t = useTranslate();
const { month: monthStr, data, onClick } = props;
const year = new Date(monthStr).getUTCFullYear();
const month = new Date(monthStr).getUTCMonth() + 1;
const year = new Date(monthStr).getFullYear();
const month = new Date(monthStr).getMonth() + 1;
const dayInMonth = new Date(year, month, 0).getDate();
const firstDay = new Date(year, month - 1, 1).getDay();
const lastDay = new Date(year, month - 1, dayInMonth).getDay();
Expand All @@ -55,15 +56,19 @@ const ActivityCalendar = (props: Props) => {
const count = data[date] || 0;
const isToday = new Date().toDateString() === new Date(date).toDateString();
const tooltipText = count ? t("memo.count-memos-in-date", { count: count, date: date }) : date;
const isSelected = new Date(props.selectedDate).toDateString() === new Date(date).toDateString();
return day ? (
<Tooltip className="shrink-0" key={`${date}-${index}`} title={tooltipText} placement="top" arrow>
<div
className={clsx(
"w-4 h-4 text-[9px] rounded-md flex justify-center items-center border border-transparent",
"w-4 h-4 text-[9px] rounded-md flex justify-center items-center border",
getCellAdditionalStyles(count, maxCount),
isToday && "border-gray-600 dark:!border-gray-500",
isToday && "border-gray-600 dark:border-zinc-300",
isSelected && "font-bold border-gray-600 dark:border-zinc-300",
!isToday && !isSelected && "border-transparent",
count > 0 && "cursor-pointer",
)}
onClick={() => count && onClick && onClick(date)}
onClick={() => count && onClick && onClick(new Date(date).toDateString())}
>
{day}
</div>
Expand Down
105 changes: 0 additions & 105 deletions web/src/components/ChangeMemoCreatedTsDialog.tsx

This file was deleted.

8 changes: 6 additions & 2 deletions web/src/components/HomeSidebar/TagsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ const TagContainer: React.FC<TagContainerProps> = (props: TagContainerProps) =>
style: "danger",
dialogName: "delete-tag-dialog",
onConfirm: async () => {
await tagStore.deleteTag(tag);
tagStore.fetchTags({ skipCache: true });
await memoServiceClient.deleteMemoTag({
parent: "memos/-",
tag: tag,
});
await tagStore.fetchTags({ skipCache: true });
toast.success(t("message.deleted-successfully"));
},
});
};
Expand Down
11 changes: 3 additions & 8 deletions web/src/components/MemoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { memo, useCallback, useEffect, useRef, useState } from "react";
import { Link, useLocation } from "react-router-dom";
import useCurrentUser from "@/hooks/useCurrentUser";
import useNavigateTo from "@/hooks/useNavigateTo";
import { extractMemoIdFromName, useUserStore } from "@/store/v1";
import { useUserStore } from "@/store/v1";
import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
import { Memo, Visibility } from "@/types/proto/api/v1/memo_service";
import { useTranslate } from "@/utils/i18n";
import { convertVisibilityToString } from "@/utils/memo";
import showChangeMemoCreatedTsDialog from "./ChangeMemoCreatedTsDialog";
import Icon from "./Icon";
import MemoActionMenu from "./MemoActionMenu";
import MemoContent from "./MemoContent";
Expand Down Expand Up @@ -56,12 +55,8 @@ const MemoView: React.FC<Props> = (props: Props) => {
})();
}, []);

const handleGotoMemoDetailPage = (event: React.MouseEvent<HTMLDivElement>) => {
if (event.altKey) {
showChangeMemoCreatedTsDialog(extractMemoIdFromName(memo.name));
} else {
navigateTo(`/m/${memo.uid}`);
}
const handleGotoMemoDetailPage = () => {
navigateTo(`/m/${memo.uid}`);
};

const handleMemoContentClick = useCallback(async (e: React.MouseEvent) => {
Expand Down
15 changes: 9 additions & 6 deletions web/src/pages/Archived.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ const Archived = () => {
.sort((a, b) => getTimeStampByDate(b.displayTime) - getTimeStampByDate(a.displayTime));

useEffect(() => {
setIsRequesting(true);
nextPageTokenRef.current = undefined;
memoList.reset();
fetchMemos();
setTimeout(async () => {
memoList.reset();
const nextPageToken = await fetchMemos();
nextPageTokenRef.current = nextPageToken;
setIsRequesting(false);
});
}, [tagQuery, textQuery]);

const fetchMemos = async () => {
Expand All @@ -48,14 +53,12 @@ const Archived = () => {
if (tagQuery) {
filters.push(`tag == "${tagQuery}"`);
}
setIsRequesting(true);
const data = await memoStore.fetchMemos({
const { nextPageToken } = await memoStore.fetchMemos({
pageSize: DEFAULT_LIST_MEMOS_PAGE_SIZE,
filter: filters.join(" && "),
pageToken: nextPageTokenRef.current,
});
setIsRequesting(false);
nextPageTokenRef.current = data.nextPageToken;
return nextPageToken;
};

const handleDeleteMemoClick = async (memo: Memo) => {
Expand Down
15 changes: 9 additions & 6 deletions web/src/pages/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ const Explore = () => {
const sortedMemos = memoList.value.sort((a, b) => getTimeStampByDate(b.displayTime) - getTimeStampByDate(a.displayTime));

useEffect(() => {
setIsRequesting(true);
nextPageTokenRef.current = undefined;
memoList.reset();
fetchMemos();
setTimeout(async () => {
memoList.reset();
const nextPageToken = await fetchMemos();
nextPageTokenRef.current = nextPageToken;
setIsRequesting(false);
});
}, [tagQuery, textQuery]);

const fetchMemos = async () => {
Expand All @@ -44,14 +49,12 @@ const Explore = () => {
if (tagQuery) {
filters.push(`tag == "${tagQuery}"`);
}
setIsRequesting(true);
const data = await memoStore.fetchMemos({
const { nextPageToken } = await memoStore.fetchMemos({
pageSize: DEFAULT_LIST_MEMOS_PAGE_SIZE,
filter: filters.join(" && "),
pageToken: nextPageTokenRef.current,
});
setIsRequesting(false);
nextPageTokenRef.current = data.nextPageToken;
return nextPageToken;
};

return (
Expand Down
15 changes: 9 additions & 6 deletions web/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ const Home = () => {
.sort((a, b) => Number(b.pinned) - Number(a.pinned));

useEffect(() => {
setIsRequesting(true);
nextPageTokenRef.current = undefined;
memoList.reset();
fetchMemos();
setTimeout(async () => {
memoList.reset();
const nextPageToken = await fetchMemos();
nextPageTokenRef.current = nextPageToken;
setIsRequesting(false);
});
}, [tagQuery, textQuery]);

const fetchMemos = async () => {
Expand All @@ -50,14 +55,12 @@ const Home = () => {
if (tagQuery) {
filters.push(`tag == "${tagQuery}"`);
}
setIsRequesting(true);
const data = await memoStore.fetchMemos({
const { nextPageToken } = await memoStore.fetchMemos({
pageSize: DEFAULT_LIST_MEMOS_PAGE_SIZE,
filter: filters.join(" && "),
pageToken: nextPageTokenRef.current,
});
setIsRequesting(false);
nextPageTokenRef.current = data.nextPageToken;
return nextPageToken;
};

const handleEditPrevious = useCallback(() => {
Expand Down

0 comments on commit 1d99dad

Please sign in to comment.