Skip to content

Commit

Permalink
make coderabbit pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed Oct 20, 2024
1 parent cdea9da commit 378f97b
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 63 deletions.
80 changes: 44 additions & 36 deletions apps/web/app/(app)/onboarding/OnboardingBulkUnsubscriber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ export function OnboardingBulkUnsubscriber() {

const posthog = usePostHog();

const sortedNewsletters = useMemo(() => {
return (
data?.newsletters
.map((row) => {
const readPercentage = (row.readEmails / row.value) * 100;

return {
...row,
readPercentage,
};
})
// sort by lowest read percentage
// if tied, sort by most unread emails
.sort((a, b) => {
if (a.readPercentage === b.readPercentage) {
const aUnread = a.value - a.readEmails;
const bUnread = b.value - b.readEmails;
return bUnread - aUnread;
}

return a.readPercentage - b.readPercentage;
})
.slice(0, 5)
);
}, [data?.newsletters]);

return (
<>
<Card className="overflow-hidden">
Expand All @@ -61,35 +87,14 @@ export function OnboardingBulkUnsubscriber() {
</TableRow>
</TableHeader>
<TableBody>
{data?.newsletters
.map((row) => {
const readPercentage = (row.readEmails / row.value) * 100;

return {
...row,
readPercentage,
};
})
// sort by lowest read percentage
// if tied, sort by most unread emails
.sort((a, b) => {
if (a.readPercentage === b.readPercentage) {
const aUnread = a.value - a.readEmails;
const bUnread = b.value - b.readEmails;
return bUnread - aUnread;
}

return a.readPercentage - b.readPercentage;
})
.slice(0, 5)
.map((row) => (
<UnsubscribeRow
key={row.name}
row={row}
posthog={posthog}
mutate={mutate}
/>
))}
{sortedNewsletters?.map((row) => (
<UnsubscribeRow
key={row.name}
row={row}
posthog={posthog}
mutate={mutate}
/>
))}
</TableBody>
</Table>
</LoadingContent>
Expand All @@ -109,25 +114,28 @@ function UnsubscribeRow({
}: {
row: NewsletterStatsResponse["newsletters"][number];
posthog: PostHog;
mutate: () => void;
mutate: () => Promise<any>;
}) {
const { unsubscribeLoading, onUnsubscribe, unsubscribeLink } = useUnsubscribe(
{
item: row,
hasUnsubscribeAccess: true,
mutate: () => Promise.resolve(),
mutate,
refetchPremium: () => Promise.resolve(),
posthog,
},
);

const splitIndex = row.name.split("<");
const name = splitIndex[0].trim();
const email = splitIndex[1].split(">")[0].trim();
const parseEmail = (name: string) => {
const match = name.match(/<(.+)>/);
return match ? match[1] : name;
};
const name = row.name.split("<")[0].trim();
const email = parseEmail(row.name);

const readPercentage = (row.readEmails / row.value) * 100;
const readPercentage = row.value ? (row.readEmails / row.value) * 100 : 0;
const archivedEmails = row.value - row.inboxEmails;
const archivedPercentage = (archivedEmails / row.value) * 100;
const archivedPercentage = row.value ? (archivedEmails / row.value) * 100 : 0;

const isUnsubscribed = row.status === NewsletterStatus.UNSUBSCRIBED;

Expand Down
5 changes: 3 additions & 2 deletions apps/web/app/(app)/onboarding/OnboardingEmailAssistant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { useState } from "react";
import useSWR from "swr";
import { useForm, SubmitHandler } from "react-hook-form";
import { useForm } from "react-hook-form";
import type { SubmitHandler } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import { Input } from "@/components/Input";
Expand All @@ -18,7 +19,7 @@ import {
TableCell,
} from "@/components/ui/table";
import { Card } from "@/components/ui/card";
import { RulesExamplesResponse } from "@/app/api/user/rules/examples/route";
import type { RulesExamplesResponse } from "@/app/api/user/rules/examples/route";
import { LoadingContent } from "@/components/LoadingContent";
import { OnboardingNextButton } from "@/app/(app)/onboarding/OnboardingNextButton";
import { decodeSnippet } from "@/utils/gmail/decode";
Expand Down
6 changes: 4 additions & 2 deletions apps/web/app/(app)/onboarding/OnboardingNextButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { useSearchParams } from "next/navigation";

export function OnboardingNextButton() {
const searchParams = useSearchParams();
const currentStep = parseInt(searchParams.get("step") || "1");
const stepParam = searchParams.get("step");
const currentStep = stepParam ? Number.parseInt(stepParam) : 1;
const nextStep = isNaN(currentStep) ? 2 : currentStep + 1;

return (
<div className="mt-4">
<Button asChild>
<Link href={`/onboarding?step=${currentStep + 1}`} scroll={false}>
<Link href={`/onboarding?step=${nextStep}`} scroll={false}>
Next
</Link>
</Button>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/(app)/onboarding/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export function Steps({
}, [selectedStep, steps.length]);

return (
<ul role="list" className="space-y-6">
<ul className="space-y-6">
{steps.map((step, stepIdx) => (
<li
key={stepIdx}
key={step.title}
ref={(el) => {
if (el) stepRefs.current[stepIdx] = el;
}}
Expand Down
6 changes: 4 additions & 2 deletions apps/web/app/(app)/onboarding/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export const maxDuration = 120;
export default function OnboardingPage({
searchParams,
}: {
searchParams: { step: string };
searchParams: { step?: string };
}) {
const step = searchParams.step ? parseInt(searchParams.step) : undefined;
const step = searchParams.step
? Number.parseInt(searchParams.step)
: undefined;

return (
<div className="mx-auto mt-8 w-full max-w-5xl">
Expand Down
10 changes: 2 additions & 8 deletions apps/web/app/(app)/premium/Pricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,7 @@ export function Pricing(props: { header?: React.ReactNode }) {
) : (
<div className="mt-16" />
)}
<ul
role="list"
className="mt-8 space-y-3 text-sm leading-6 text-gray-600"
>
<ul className="mt-8 space-y-3 text-sm leading-6 text-gray-600">
{tier.features.map((feature) => (
<li key={feature} className="flex gap-x-3">
<CheckIcon
Expand Down Expand Up @@ -301,10 +298,7 @@ function LifetimePricing(props: {
</h4>
<div className="h-px flex-auto bg-gray-100" />
</div>
<ul
role="list"
className="mt-8 grid grid-cols-1 gap-4 text-sm leading-6 text-gray-600 sm:grid-cols-2 sm:gap-6"
>
<ul className="mt-8 grid grid-cols-1 gap-4 text-sm leading-6 text-gray-600 sm:grid-cols-2 sm:gap-6">
{lifetimeFeatures.map((feature) => (
<li key={feature} className="flex gap-x-3">
<CheckIcon
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(landing)/home/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function FooterList(props: {
<h3 className="text-sm font-semibold leading-6 text-gray-900">
{props.title}
</h3>
<ul role="list" className="mt-6 space-y-4">
<ul className="mt-6 space-y-4">
{props.items.map((item) => (
<li key={item.name}>
<Link
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function RadioGroup<T extends string>({
key={option.value}
value={option.value}
aria-label={option.label}
aria-description={option.description}
aria-describedby={option.description}
className={cn(
optionIdx === 0 ? "rounded-tl-md rounded-tr-md" : "",
optionIdx === options.length - 1
Expand Down
4 changes: 2 additions & 2 deletions apps/web/components/SideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function Sidebar(props: { isMobile: boolean }) {
</div>
</Link>
<nav className="flex flex-1 flex-col">
<ul role="list" className="flex flex-1 flex-col">
<ul className="flex flex-1 flex-col">
<Transition
as="div"
show={showMailNav}
Expand Down Expand Up @@ -394,7 +394,7 @@ function Sidebar(props: { isMobile: boolean }) {
function Links(props: { path: string; links: NavItem[] }) {
return (
<li>
<ul role="list" className="-mx-2 space-y-1">
<ul className="-mx-2 space-y-1">
{props.links.map((item) => (
<NavLink key={item.name} path={props.path} link={item} />
))}
Expand Down
1 change: 0 additions & 1 deletion apps/web/components/email-list/EmailList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ export function EmailList({
<ResizeGroup
left={
<ul
role="list"
className="divide-y divide-gray-100 overflow-y-auto scroll-smooth"
ref={listRef}
>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/email-list/EmailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function EmailThread(props: {
}) {
return (
<div className="grid flex-1 gap-4 overflow-auto bg-gray-100 p-4">
<ul role="list" className="space-y-2 sm:space-y-4">
<ul className="space-y-2 sm:space-y-4">
{props.messages?.map((message) => (
<EmailMessage
key={message.id}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/utils/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const completedOnboardingAction = withActionInstrumentation(

await prisma.user.update({
where: { id: session.user.id, completedOnboardingAt: null },
data: { completedOnboardingAt: new Date() },
data: { completedOnboardingAt: new Date(), completedOnboarding: true },
});
},
);
Expand Down
10 changes: 6 additions & 4 deletions apps/web/utils/ai/example-matches/find-example-matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ Please proceed step-by-step, fetching emails and analyzing them to find only the
}, []);

return {
matches: matches.map((match) => ({
...listedEmails[match.emailId],
rule: match.rule,
})),
matches: matches
.filter((match) => listedEmails[match.emailId])
.map((match) => ({
...listedEmails[match.emailId],
rule: match.rule,
})),
};
}

0 comments on commit 378f97b

Please sign in to comment.