Skip to content
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

Show bulk archive progress #237

Merged
merged 7 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion apps/web/app/(app)/automation/BulkRunRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SectionDescription } from "@/components/Typography";
import type { ThreadsResponse } from "@/app/api/google/threads/controller";
import type { ThreadsQuery } from "@/app/api/google/threads/validation";
import { LoadingContent } from "@/components/LoadingContent";
import { runAiRules } from "@/providers/QueueProvider";
import { runAiRules } from "@/utils/queue/email-actions";
import { aiQueueAtom } from "@/store/queue";
import { sleep } from "@/utils/sleep";
import { PremiumAlertWithData, usePremium } from "@/components/PremiumAlert";
Expand Down
58 changes: 58 additions & 0 deletions apps/web/app/(app)/bulk-unsubscribe/ArchiveProgress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { useEffect } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { useAtomValue } from "jotai";
import { ProgressBar } from "@tremor/react";
import { queueAtoms, resetTotalThreads } from "@/store/archive-queue";
import { cn } from "@/utils";

export const ArchiveProgress = () => {
const { totalThreads, activeThreadIds } = useAtomValue(queueAtoms.archive);

const threadsRemaining =
Object.values(activeThreadIds).filter(Boolean).length;
const totalArchived = totalThreads - threadsRemaining;
const progress = (totalArchived / totalThreads) * 100;
const isCompleted = progress === 100;

useEffect(() => {
if (isCompleted) {
setTimeout(() => {
resetTotalThreads("archive");
}, 5_000);
}
}, [isCompleted]);

if (!totalThreads) return null;

return (
<div className="px-4 py-2">
<AnimatePresence mode="wait">
<motion.div
key="progress"
initial={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.3 }}
>
<ProgressBar
value={progress}
className="w-full"
color={isCompleted ? "green" : "blue"}
/>
<p className="mt-2 flex justify-between text-sm" aria-live="polite">
<span
className={cn(
"text-muted-foreground",
isCompleted ? "text-green-500" : "",
)}
>
{isCompleted ? "Archiving complete!" : "Archiving emails..."}
</span>
<span>
{totalArchived} of {totalThreads} emails archived
</span>
</p>
</motion.div>
</AnimatePresence>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { ShortcutTooltip } from "@/app/(app)/bulk-unsubscribe/ShortcutTooltip";
import { SearchBar } from "@/app/(app)/bulk-unsubscribe/SearchBar";
import { useToggleSelect } from "@/hooks/useToggleSelect";
import { BulkActions } from "@/app/(app)/bulk-unsubscribe/BulkActions";
import { ArchiveProgress } from "@/app/(app)/bulk-unsubscribe/ArchiveProgress";

type Newsletter = NewsletterStatsResponse["newsletters"][number];

Expand Down Expand Up @@ -228,6 +229,8 @@ export function BulkUnsubscribeSection({
</div>
</div>

<ArchiveProgress />

{isStatsLoading && !isLoading && !data?.newsletters.length ? (
<div className="p-4">
<Skeleton className="h-screen rounded" />
Expand Down
8 changes: 4 additions & 4 deletions apps/web/app/(app)/bulk-unsubscribe/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { captureException } from "@/utils/error";
import {
archiveAllSenderEmails,
deleteEmails,
} from "@/providers/QueueProvider";
} from "@/utils/queue/email-actions";
import type { Row } from "@/app/(app)/bulk-unsubscribe/types";
import type { GetThreadsResponse } from "@/app/api/google/threads/basic/route";
import { isDefined } from "@/utils/types";
Expand Down Expand Up @@ -524,9 +524,9 @@ export function useNewsletterFilter() {
Record<"unhandled" | "unsubscribed" | "autoArchived" | "approved", boolean>
>({
unhandled: true,
unsubscribed: false,
autoArchived: false,
approved: false,
unsubscribed: true,
autoArchived: true,
approved: true,
});

return {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(app)/simple/SimpleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Button as HoverButton } from "@/components/Button";
import { extractNameFromEmail } from "@/utils/email";
import { Tooltip } from "@/components/Tooltip";
import type { ParsedMessage } from "@/utils/types";
import { archiveEmails } from "@/providers/QueueProvider";
import { archiveEmails } from "@/utils/queue/email-actions";
import { Summary } from "@/app/(app)/simple/Summary";
import { getGmailUrl } from "@/utils/url";
import {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/CommandK.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { navigation } from "@/components/SideNav";
import { useComposeModal } from "@/providers/ComposeModalProvider";
import { refetchEmailListAtom, selectedEmailAtom } from "@/store/email";
import { archiveEmails } from "@/providers/QueueProvider";
import { archiveEmails } from "@/utils/queue/email-actions";

export function CommandK() {
const [open, setOpen] = React.useState(false);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/email-list/EmailList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
deleteEmails,
markReadThreads,
runAiRules,
} from "@/providers/QueueProvider";
} from "@/utils/queue/email-actions";
import { selectedEmailAtom } from "@/store/email";
import { categorizeAction } from "@/utils/actions/categorize";

Expand Down
5 changes: 1 addition & 4 deletions apps/web/providers/AppProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import type React from "react";
import { Provider } from "jotai";
import { ComposeModalProvider } from "@/providers/ComposeModalProvider";
import { QueueProvider } from "@/providers/QueueProvider";
import { jotaiStore } from "@/store";

export function AppProviders(props: { children: React.ReactNode }) {
return (
<Provider store={jotaiStore}>
<QueueProvider>
<ComposeModalProvider>{props.children}</ComposeModalProvider>
</QueueProvider>
<ComposeModalProvider>{props.children}</ComposeModalProvider>
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Issues Found: Remaining References to QueueProvider

There are still several files importing QueueProvider:

  • apps/web/components/email-list/EmailList.tsx
  • apps/web/components/CommandK.tsx
  • apps/web/app/(app)/automation/BulkRunRules.tsx
  • apps/web/app/(app)/simple/SimpleList.tsx

This indicates that removing QueueProvider from AppProviders.tsx may break these components. Please ensure that QueueProvider has been appropriately replaced or removed from these files.

🔗 Analysis chain

LGTM! Verify the impact of removing QueueProvider.

The simplification of the AppProviders component by removing QueueProvider aligns with the PR objectives. This change reduces nesting and potentially improves performance.

However, please ensure:

  1. All functionalities previously provided by QueueProvider are properly handled in the new state management system (as mentioned in the AI summary).
  2. No components are relying on the context or functionalities that were provided by QueueProvider.

To verify the removal of QueueProvider hasn't broken any dependencies, run:

Consider adding a comment in this file or updating the relevant documentation to explain why QueueProvider was removed and where its functionality has been moved. This will help future developers understand the change.



🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to QueueProvider
rg 'QueueProvider' --type typescript --type typescriptreact

Length of output: 94


Script:

#!/bin/bash
# Search for any remaining references to QueueProvider in .ts and .tsx files
rg 'QueueProvider' --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx

Length of output: 135


Script:

#!/bin/bash
# Search for any remaining references to QueueProvider in .ts and .tsx files using correct type definitions
rg 'QueueProvider' --type-add 'ts:*.ts' --type-add 'tsx:*.tsx' -t ts -t tsx

Length of output: 451

</Provider>
);
}
198 changes: 0 additions & 198 deletions apps/web/providers/QueueProvider.tsx

This file was deleted.

Loading