diff --git a/src/app/page.tsx b/src/app/page.tsx index fd152a0..eb2d0c3 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,4 +1,3 @@ -// import CustomFeed from "@/components/CustomFeed"; import { buttonVariants } from "@/components/ui/Button" import { getAuthSession } from "@/lib/auth" import { FileTextIcon, HelpCircleIcon, HomeIcon, BookIcon } from "lucide-react" @@ -90,35 +89,6 @@ export default async function Home() { <>

El teu espai

- {/* Feed - {session ? : null} */} - - {/* subjects info */} - {/*
-
-

- - Home -

-
- -
-
-

- La teva pàgina d Apunts de Dades. Accedeix aquí per a veure els apunts de les assignatures que - t interessen. -

-
- - - Crea una assignatura - -
-
*/}

diff --git a/src/components/CustomFeed.tsx b/src/components/CustomFeed.tsx deleted file mode 100644 index 08ff8a0..0000000 --- a/src/components/CustomFeed.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { INFINITE_SCROLL_PAGINATION_RESULTS } from "@/config" -import { getAuthSession } from "@/lib/auth" -import { db } from "@/lib/db" -import PostFeed from "./PostFeed" -import { notFound } from "next/navigation" - -const CustomFeed = async () => { - const session = await getAuthSession() - - // only rendered if session exists, so this will not happen - if (!session) return notFound() - - const followedCommunities = await db.subscription.findMany({ - where: { - userId: session.user.id, - }, - include: { - subject: true, - }, - }) - - const posts = await db.post.findMany({ - where: { - subject: { - name: { - in: followedCommunities.map((sub) => sub.subject.name), - }, - }, - }, - orderBy: { - createdAt: "desc", - }, - include: { - votes: true, - author: true, - comments: true, - subject: true, - }, - take: INFINITE_SCROLL_PAGINATION_RESULTS, - }) - - return -} - -export default CustomFeed diff --git a/src/components/SubscribeLeaveToggle.tsx b/src/components/SubscribeLeaveToggle.tsx deleted file mode 100644 index 7c5a76d..0000000 --- a/src/components/SubscribeLeaveToggle.tsx +++ /dev/null @@ -1,119 +0,0 @@ -"use client" - -import { FC, startTransition } from "react" -import { Button } from "./ui/Button" -import { SubscribeToSubjectPayload } from "@/lib/validators/subject" -import { useMutation } from "@tanstack/react-query" -import axios, { AxiosError } from "axios" -import { toast } from "@/hooks/use-toast" -import { useRouter } from "next/navigation" -import { useCustomToasts } from "@/hooks/use-custom-toasts" - -interface SubscribeLeaveToggleProps { - subjectId: string - subjectName: string - isSubscribed: boolean -} - -const SubscribeLeaveToggle: FC = ({ - subjectId, - subjectName, - isSubscribed, -}) => { - const { loginToast } = useCustomToasts() - const router = useRouter() - - const { mutate: subscribe, isLoading: isSubLoading } = useMutation({ - mutationFn: async () => { - const payload: SubscribeToSubjectPayload = { - subjectId, - } - const { data } = await axios.post("/api/subject/subscribe", payload) - return data as string - }, - onError: (err) => { - if (err instanceof AxiosError) { - if (err.response?.status === 401) { - return loginToast() - } - } - - return toast({ - title: "S'ha produït un error desconegut.", - description: - "No s'ha pogut subscriure a l'assignatura. Siusplau, torna a intentar-ho més tard.", - variant: "destructive", - }) - }, - onSuccess: ({}) => { - startTransition(() => { - router.refresh() - }) - - const startsWithVowel = /^[aeiouàáâãäåæçèéêëìíîïðòóôõöøùúûüýÿ]/i - const subjectArticle = subjectName.match(startsWithVowel) ? "d'" : "de " - - return toast({ - title: `T'has subscrit als apunts ${subjectArticle}${subjectName}!`, - description: "", - }) - }, - }) - - const { mutate: unsubscribe, isLoading: isUnsubLoading } = useMutation({ - mutationFn: async () => { - const payload: SubscribeToSubjectPayload = { - subjectId, - } - const { data } = await axios.post("/api/subject/unsubscribe", payload) - return data as string - }, - onError: (err) => { - if (err instanceof AxiosError) { - if (err.response?.status === 401) { - return loginToast() - } - } - - return toast({ - title: "S'ha produït un error desconegut.", - description: - "No s'ha pogut donar de baixa la subscripció a l'assignatura. Siusplau, torna a intentar-ho més tard.", - variant: "destructive", - }) - }, - onSuccess: ({}) => { - startTransition(() => { - router.refresh() - }) - - const startsWithVowel = /^[aeiouàáâãäåæçèéêëìíîïðòóôõöøùúûüýÿ]/i - const subjectArticle = subjectName.match(startsWithVowel) ? "d'" : "de " - - return toast({ - title: `Has donat de baixa la teva subscripció als apunts ${subjectArticle}${subjectName}!`, - description: "", - }) - }, - }) - - return isSubscribed ? ( - - ) : ( - - ) -} - -export default SubscribeLeaveToggle