Skip to content

Commit e54996b

Browse files
committed
good build
1 parent 5ecbdab commit e54996b

8 files changed

Lines changed: 79 additions & 50 deletions

File tree

app/api/algolia/route.tsx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { isValidSignature, SIGNATURE_HEADER_NAME } from "@sanity/webhook";
2-
import algoliasearch from "algoliasearch";
2+
import { algoliasearch } from "algoliasearch";
33

44
const secret = process.env.PRIVATE_ALGOLIA_WEBOOK_SECRET;
55
const algoliaAdminApiKey = process.env.PRIVATE_ALGOLIA_ADMIN_API_KEY;
66
const algoliaAppId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID;
77
const algoliaIndex = process.env.NEXT_PUBLIC_ALGOLIA_INDEX;
88

9-
if (!algoliaAdminApiKey) throw "Missing PRIVATE_ALGOLIA_ADMIN_API_KEY";
10-
if (!algoliaAppId) throw "Missing NEXT_PUBLIC_ALGOLIA_APP_ID";
11-
if (!algoliaIndex) throw "Missing NEXT_PUBLIC_ALGOLIA_INDEX";
9+
if (!algoliaAdminApiKey) {
10+
throw "Missing PRIVATE_ALGOLIA_ADMIN_API_KEY";
11+
}
12+
if (!algoliaAppId) {
13+
throw "Missing NEXT_PUBLIC_ALGOLIA_APP_ID";
14+
}
15+
if (!algoliaIndex) {
16+
throw "Missing NEXT_PUBLIC_ALGOLIA_INDEX";
17+
}
1218

13-
const algolia = algoliasearch(algoliaAppId, algoliaAdminApiKey);
14-
const index = algolia.initIndex(algoliaIndex);
19+
const client = algoliasearch(algoliaAppId, algoliaAdminApiKey);
1520

1621
function toAlgoliaObject(sanityDoc: any) {
1722
const doc = { ...sanityDoc };
23+
// biome-ignore lint/performance/noDelete: <explanation>
1824
delete doc.content;
1925

2026
return (
@@ -41,19 +47,21 @@ function toAlgoliaObject(sanityDoc: any) {
4147
}
4248

4349
export async function POST(request: Request) {
44-
if (!secret)
50+
if (!secret) {
4551
return Response.json(
4652
{ success: false, error: "Missing Secret PRIVATE_ALGOLIA_WEBOOK_SECRET" },
4753
{ status: 400 },
4854
);
55+
}
4956

5057
const signature = request.headers.get(SIGNATURE_HEADER_NAME);
5158

52-
if (!signature)
59+
if (!signature) {
5360
return Response.json(
5461
{ success: false, error: "Missing Signature Header" },
5562
{ status: 401 },
5663
);
64+
}
5765

5866
const body = await request.text();
5967
if (!(await isValidSignature(body, signature, secret))) {
@@ -81,19 +89,31 @@ export async function POST(request: Request) {
8189
const deleted = sanityDoc.deleted;
8290
const updated = sanityDoc.updated;
8391

92+
// biome-ignore lint/performance/noDelete: <explanation>
8493
delete sanityDoc.created;
94+
// biome-ignore lint/performance/noDelete: <explanation>
8595
delete sanityDoc.deleted;
96+
// biome-ignore lint/performance/noDelete: <explanation>
8697
delete sanityDoc.updated;
8798

8899
const algoliaDoc = toAlgoliaObject(sanityDoc);
89100

90101
try {
91102
if (created) {
92-
await index.saveObjects(algoliaDoc).wait();
103+
await client.saveObjects({
104+
indexName: algoliaIndex as string,
105+
objects: [algoliaDoc],
106+
});
93107
} else if (updated) {
94-
await index.saveObjects(algoliaDoc).wait();
108+
await client.saveObjects({
109+
indexName: algoliaIndex as string,
110+
objects: [algoliaDoc],
111+
});
95112
} else {
96-
await index.deleteObject(sanityDoc.objectID).wait();
113+
await client.deleteObject({
114+
indexName: algoliaIndex as string,
115+
objectID: sanityDoc.objectID,
116+
});
97117
}
98118
} catch (e) {
99119
const error = JSON.stringify(e);

components/algolia-search.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export default function AlgoliaSearch({
104104
hit={hit}
105105
attribute="title"
106106
classNames={{ highlighted: "bg-primary" }}
107-
className="text-sm sm:text-xl font-bold"
108107
/>
109108
<Highlight
110109
hit={hit}

components/bookmark.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use client";
22
import { useBookmarked, useFirestoreUser } from "@/lib/firebase.hooks";
33
import { Checkbox } from "@/components/ui/checkbox";
4-
import { useToast } from "@/components/ui/use-toast";
54
import type { BaseBookmarkContent } from "@/lib/types";
5+
import { toast } from "sonner";
66

77
export default function Bookmark({
88
content,
@@ -13,21 +13,15 @@ export default function Bookmark({
1313
const { bookmarked, addBookmark, removeBookmark } = useBookmarked({
1414
content,
1515
});
16-
const { toast } = useToast();
1716

1817
const makeComplete = async (isChecked: boolean) => {
1918
if (!currentUser?.uid) {
20-
toast({
21-
variant: "destructive",
22-
description: "You must be logged in to complete a lesson.",
23-
});
19+
toast("You must be logged in to complete a lesson.");
2420
return;
2521
}
2622
if (isChecked) {
2723
await addBookmark();
28-
toast({
29-
description: "Bookmark added 〽️",
30-
});
24+
toast("Bookmark added 〽️");
3125
} else {
3226
await removeBookmark();
3327
}
@@ -37,7 +31,7 @@ export default function Bookmark({
3731
{currentUser?.uid ? (
3832
<div className="flex items-center gap-2">
3933
<Checkbox
40-
checked={bookmarked?._id ? true : false}
34+
checked={!!bookmarked?._id}
4135
onCheckedChange={makeComplete}
4236
/>
4337
</div>

components/player-context.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { PodcastQueryResult } from "@/sanity/types";
33
import {
44
type Dispatch,
5-
type MutableRefObject,
5+
type RefObject,
66
type SetStateAction,
77
createContext,
88
useEffect,
@@ -39,7 +39,7 @@ export const PlayerContext = createContext<{
3939
playbackRate: number;
4040
}>
4141
>;
42-
audioRef: MutableRefObject<HTMLAudioElement | undefined> | undefined;
42+
audioRef: RefObject<HTMLAudioElement | null> | undefined;
4343
volume: number;
4444
setVolume: Dispatch<SetStateAction<number>>;
4545
}>({
@@ -80,21 +80,27 @@ export const PlayerProvider = ({ children }: { children: JSX.Element }) => {
8080
duration: 100,
8181
playbackRate: 1.0,
8282
});
83-
const audioRef = useRef<HTMLAudioElement>();
83+
const audioRef = useRef<HTMLAudioElement | null>(null);
8484
const [volume, setVolume] = useState(100);
8585

8686
useEffect(() => {
8787
const src = podcast?.spotify?.enclosures?.at(0)?.url;
88-
if (!src){ return;}
89-
if (src === audio.src){ return;}
88+
if (!src) {
89+
return;
90+
}
91+
if (src === audio.src) {
92+
return;
93+
}
9094
setAudio((p) => {
9195
return { ...p, src };
9296
});
9397
setIsOpen(true);
9498
}, [podcast, audio.src]);
9599

96100
useEffect(() => {
97-
if (!audioRef.current){ return;}
101+
if (!audioRef.current) {
102+
return;
103+
}
98104
audioRef.current.volume = volume / 100;
99105
}, [volume]);
100106

@@ -105,11 +111,15 @@ export const PlayerProvider = ({ children }: { children: JSX.Element }) => {
105111
}, [podcast]);
106112

107113
useEffect(() => {
108-
if (audioRef.current){ audioRef.current.playbackRate = audio.playbackRate;}
114+
if (audioRef.current) {
115+
audioRef.current.playbackRate = audio.playbackRate;
116+
}
109117
}, [audio.playbackRate]);
110118

111119
useEffect(() => {
112-
if (!audio?.src || audioRef.current?.src === audio.src){ return;}
120+
if (!audio?.src || audioRef.current?.src === audio.src) {
121+
return;
122+
}
113123

114124
audioRef.current = new Audio(audio.src);
115125

@@ -133,7 +143,9 @@ export const PlayerProvider = ({ children }: { children: JSX.Element }) => {
133143
// time and duration
134144
audioRef.current.addEventListener("loadedmetadata", () => {
135145
setAudio((p) => {
136-
if (!audioRef?.current){ return p;}
146+
if (!audioRef?.current) {
147+
return p;
148+
}
137149
return {
138150
...p,
139151
curTime: audioRef.current.currentTime,
@@ -143,7 +155,9 @@ export const PlayerProvider = ({ children }: { children: JSX.Element }) => {
143155
});
144156
audioRef.current.addEventListener("timeupdate", () => {
145157
setAudio((p) => {
146-
if (!audioRef?.current){ return p;}
158+
if (!audioRef?.current) {
159+
return p;
160+
}
147161
return {
148162
...p,
149163
curTime: audioRef.current.currentTime,

components/theme-provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as React from "react";
44
import { ThemeProvider as NextThemesProvider } from "next-themes";
5-
import type { ThemeProviderProps } from "next-themes/dist/types";
5+
import type { ThemeProviderProps } from "next-themes";
66

77
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
88
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;

components/user-buy.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import { useFirestoreUser } from "@/lib/firebase.hooks";
1313
import Link from "next/link";
1414
import { useCookies } from "react-cookie";
1515
import { jwtDecode } from "jwt-decode";
16-
import { CourseQueryResult, type HomePageQueryResult } from "@/sanity/types";
16+
import type { CoursesQueryResult } from "@/sanity/types";
1717
import type { Price3 } from "@/lib/stripe.types";
1818

1919
export default function Buy({
2020
title,
2121
stripeProduct,
2222
}: {
23-
title: NonNullable<HomePageQueryResult>["featuredCourses"][0]["title"];
24-
stripeProduct: NonNullable<HomePageQueryResult>["featuredCourses"][0]["stripeProduct"];
23+
title: NonNullable<CoursesQueryResult>["title"];
24+
stripeProduct: NonNullable<CoursesQueryResult>["stripeProduct"];
2525
}) {
2626
const { currentUser } = useFirestoreUser();
2727
const [redirecting, setRedirecting] = useState(false);
@@ -31,7 +31,9 @@ export default function Buy({
3131
const [jwt, setJwt] = useState<any | null>(null);
3232

3333
useEffect(() => {
34-
if (showBuy) { setRedirecting(false); }
34+
if (showBuy) {
35+
setRedirecting(false);
36+
}
3537
}, [showBuy]);
3638

3739
useEffect(() => {
@@ -52,7 +54,9 @@ export default function Buy({
5254
};
5355

5456
useEffect(() => {
55-
if (stripeProduct && showBuy) { getPrice(); }
57+
if (stripeProduct && showBuy) {
58+
getPrice();
59+
}
5660
// eslint-disable-next-line react-hooks/exhaustive-deps
5761
}, [stripeProduct, showBuy]);
5862

@@ -79,9 +83,7 @@ export default function Buy({
7983
const subscribe = (
8084
<>
8185
<DialogHeader>
82-
<DialogTitle>
83-
Purchase: {title}
84-
</DialogTitle>
86+
<DialogTitle>Purchase: {title}</DialogTitle>
8587
</DialogHeader>
8688
{price && (
8789
<div className="mt-4 flex gap-2 sm:gap-4 text-xl sm:text-2xl">

components/user-go-pro.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
DialogTitle,
77
} from "@/components/ui/dialog";
88
import { Card } from "@/components/ui/card";
9-
import { Avatar, AvatarImage } from "@/components/ui/avatar";
109
import { Button } from "@/components/ui/button";
1110
import { type Dispatch, type SetStateAction, useEffect, useState } from "react";
1211
import { addSubscription } from "@/lib/firebase";
@@ -16,6 +15,7 @@ import Link from "next/link";
1615
import { useCookies } from "react-cookie";
1716
import { jwtDecode } from "jwt-decode";
1817
import { usePathname } from "next/navigation";
18+
import { toast } from "sonner";
1919

2020
export default function GoPro({
2121
setShowGoPro,
@@ -47,10 +47,7 @@ export default function GoPro({
4747
const { error, url } = snap.data() as { error: Error; url: string };
4848
if (error) {
4949
console.error(error);
50-
toast({
51-
variant: "destructive",
52-
description: error.message,
53-
});
50+
toast(error.message);
5451
}
5552
if (url) {
5653
// We have a Stripe Checkout URL, let's redirect.

sanity/components/BlockEditor.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { handlePaste } from "./pastehandler";
44

55
const wordsPerMinute = 200;
66

7-
function BlockEditor(props: any, ref: any) {
7+
import React from "react";
8+
9+
const BlockEditor = React.forwardRef(function BlockEditor(
10+
props: any,
11+
ref: any,
12+
) {
813
const value = props.value ?? [];
914
const plainText = toPlainText(value);
1015
const characterCount = plainText.length;
@@ -30,8 +35,6 @@ function BlockEditor(props: any, ref: any) {
3035
</div>
3136
</div>
3237
);
33-
}
34-
// TODO: Add stronger typing
35-
38+
});
3639
const input = (props: any) => <BlockEditor {...props} onPaste={handlePaste} />;
3740
export default input;

0 commit comments

Comments
 (0)