Skip to content

feat: add infinite scrolling for memos #4715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions web/src/components/PagedMemoList/PagedMemoList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button } from "@usememos/mui";
import { ArrowDownIcon, ArrowUpIcon, LoaderIcon } from "lucide-react";
import { ArrowUpIcon, LoaderIcon } from "lucide-react";
import { observer } from "mobx-react-lite";
import { useEffect, useState } from "react";
import { matchPath } from "react-router-dom";
Expand Down Expand Up @@ -71,6 +71,18 @@ const PagedMemoList = observer((props: Props) => {
refreshList();
}, [props.owner, props.state, props.direction, props.filter, props.oldFilter, props.pageSize]);

useEffect(() => {
if (!state.nextPageToken) return;
const handleScroll = () => {
const nearBottom = window.innerHeight + window.scrollY >= document.body.offsetHeight - 300;
if (nearBottom && !state.isRequesting) {
fetchMoreMemos(state.nextPageToken);
}
};
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
}, [state.nextPageToken, state.isRequesting]);

const children = (
<div className="flex flex-col justify-start items-start w-full max-w-full">
<MasonryView
Expand All @@ -93,12 +105,6 @@ const PagedMemoList = observer((props: Props) => {
</div>
) : (
<div className="w-full opacity-70 flex flex-row justify-center items-center my-4">
{state.nextPageToken && (
<Button variant="plain" onClick={() => fetchMoreMemos(state.nextPageToken)}>
{t("memo.load-more")}
<ArrowDownIcon className="ml-1 w-4 h-auto" />
</Button>
)}
<BackToTop />
</div>
)}
Expand Down
25 changes: 7 additions & 18 deletions web/src/components/Settings/PreferencesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,33 @@ const PreferencesSection = observer(() => {
const setting = userStore.state.userSetting as UserSetting;

const handleLocaleSelectChange = async (locale: Locale) => {
await userStore.updateUserSetting(
{
locale,
},
["locale"],
);
await userStore.updateUserSetting({ locale }, ["locale"]);
};

const handleAppearanceSelectChange = async (appearance: Appearance) => {
await userStore.updateUserSetting(
{
appearance,
},
["appearance"],
);
await userStore.updateUserSetting({ appearance }, ["appearance"]);
};

const handleDefaultMemoVisibilityChanged = async (value: string) => {
await userStore.updateUserSetting(
{
memoVisibility: value,
},
["memo_visibility"],
);
await userStore.updateUserSetting({ memoVisibility: value }, ["memo_visibility"]);
};

return (
<div className="w-full flex flex-col gap-2 pt-2 pb-4">
<p className="font-medium text-gray-700 dark:text-gray-500">{t("common.basic")}</p>

<div className="w-full flex flex-row justify-between items-center">
<span>{t("common.language")}</span>
<LocaleSelect value={setting.locale} onChange={handleLocaleSelectChange} />
</div>

<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.preference-section.theme")}</span>
<AppearanceSelect value={setting.appearance as Appearance} onChange={handleAppearanceSelectChange} />
</div>

<p className="font-medium text-gray-700 dark:text-gray-500">{t("setting.preference")}</p>

<div className="w-full flex flex-row justify-between items-center">
<span className="truncate">{t("setting.preference-section.default-memo-visibility")}</span>
<Select
Expand Down
139 changes: 120 additions & 19 deletions web/src/types/proto/google/protobuf/descriptor.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.