Skip to content

Commit

Permalink
Allow loading longer email history
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed Dec 30, 2024
1 parent 10275a6 commit b27c197
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apps/web/app/(app)/stats/LoadStatsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { ButtonLoader } from "@/components/Loading";
import { useStatLoader } from "@/providers/StatLoaderProvider";

export function LoadStatsButton() {
const { isLoading, onLoad } = useStatLoader();
const { isLoading, onLoadBatch } = useStatLoader();

return (
<div>
<Button
variant="outline"
onClick={() => onLoad({ loadBefore: true, showToast: true })}
onClick={() => onLoadBatch({ loadBefore: true, showToast: true })}
disabled={isLoading}
>
{isLoading ? (
Expand Down
21 changes: 20 additions & 1 deletion apps/web/providers/StatLoaderProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ type Context = {
loadBefore: boolean;
showToast: boolean;
}) => Promise<void>;
onLoadBatch: (options: {
loadBefore: boolean;
showToast: boolean;
}) => Promise<void>;
};

const StatLoaderContext = createContext<Context>({
isLoading: false,
onLoad: async () => {},
onLoadBatch: async () => {},
});

export const useStatLoader = () => useContext(StatLoaderContext);
Expand Down Expand Up @@ -69,8 +74,22 @@ export function StatLoaderProvider(props: { children: React.ReactNode }) {
[],
);

const onLoadBatch = useCallback(
async (options: { loadBefore: boolean; showToast: boolean }) => {
const batchSize = 50;
for (let i = 0; i < batchSize; i++) {
console.log("Loading batch", i);
await onLoad({
...options,
showToast: options.showToast && i === batchSize - 1,
});
}
},
[onLoad],
);

return (
<StatLoaderContext.Provider value={{ isLoading, onLoad }}>
<StatLoaderContext.Provider value={{ isLoading, onLoad, onLoadBatch }}>
{props.children}
</StatLoaderContext.Provider>
);
Expand Down

1 comment on commit b27c197

@vercel
Copy link

@vercel vercel bot commented on b27c197 Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.