From 3273508e55592f98d3541e7b987188ae15e5707d Mon Sep 17 00:00:00 2001 From: Pau Matas Date: Sat, 16 Mar 2024 18:12:08 +0100 Subject: [PATCH 1/3] feat: scrolling problem solved --- src/components/Combobox.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Combobox.tsx b/src/components/Combobox.tsx index b7258ed..d220fee 100644 --- a/src/components/Combobox.tsx +++ b/src/components/Combobox.tsx @@ -46,11 +46,11 @@ export function Combobox({ - + - No option found. - + No option found. + {options.map((option) => ( Date: Sat, 16 Mar 2024 19:47:55 +0100 Subject: [PATCH 2/3] fix: hardcoding just isn't for me --- src/app/api/subject/all/value-label/route.ts | 26 ++++ src/components/Combobox.tsx | 10 +- src/components/Form.tsx | 137 +++---------------- 3 files changed, 48 insertions(+), 125 deletions(-) create mode 100644 src/app/api/subject/all/value-label/route.ts diff --git a/src/app/api/subject/all/value-label/route.ts b/src/app/api/subject/all/value-label/route.ts new file mode 100644 index 0000000..1b63fc7 --- /dev/null +++ b/src/app/api/subject/all/value-label/route.ts @@ -0,0 +1,26 @@ +import { db } from "@/lib/db" + +export async function GET(req: Request) { + const subjects = await db.subject.findMany({ + select: { + acronym: true, + name: true, + }, + orderBy: { + semester: "asc", + }, + }) + + const subjectsValueLabel = subjects.map((subject) => { + return { + value: subject.acronym.toLowerCase(), + label: `${subject.acronym} - ${subject.name}`, + } + }) + + return new Response(JSON.stringify(subjectsValueLabel), { + headers: { + "content-type": "application/json", + }, + }) +} diff --git a/src/components/Combobox.tsx b/src/components/Combobox.tsx index d220fee..8ae33d1 100644 --- a/src/components/Combobox.tsx +++ b/src/components/Combobox.tsx @@ -38,18 +38,20 @@ export function Combobox({ variant="outline" role="combobox" aria-expanded={open} - className="w-[200px] justify-between" + className="w-80 justify-between" > {value ? options.find((option) => option.value === value)?.label - : "Select..."} + : "Selecciona..."} - + - No option found. + + No s'han trobat resultats. + {options.map((option) => ( { + async function fetchAssignatures() { + try { + const response = await axios.get("/api/subject/all/value-label") + setAssignatures(response.data) + } catch (error) { + console.error("Error fetching subjects:", error) + } + } + fetchAssignatures() + }, []) + const tipus = [ { value: "apunts", @@ -264,7 +159,7 @@ export function ProfileForm({ label: "Altres", }, ] - // ------------------------------ + return (
Date: Sun, 17 Mar 2024 09:52:45 +0100 Subject: [PATCH 3/3] fix: build warnings cleaning --- src/app/api/subject/all/value-label/route.ts | 2 +- src/app/unansweredquestions/page.tsx | 11 +---------- src/components/CreateAnswer.tsx | 1 - src/components/CreatePost.tsx | 3 +-- src/components/Editor.tsx | 9 +-------- src/components/Form.tsx | 5 ++++- src/components/SearchBar.tsx | 2 +- src/components/votes/AnswerAcceptClient.tsx | 2 +- 8 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/app/api/subject/all/value-label/route.ts b/src/app/api/subject/all/value-label/route.ts index 1b63fc7..35d1c7f 100644 --- a/src/app/api/subject/all/value-label/route.ts +++ b/src/app/api/subject/all/value-label/route.ts @@ -1,6 +1,6 @@ import { db } from "@/lib/db" -export async function GET(req: Request) { +export async function GET() { const subjects = await db.subject.findMany({ select: { acronym: true, diff --git a/src/app/unansweredquestions/page.tsx b/src/app/unansweredquestions/page.tsx index a6bc002..258347a 100644 --- a/src/app/unansweredquestions/page.tsx +++ b/src/app/unansweredquestions/page.tsx @@ -1,5 +1,4 @@ import { INFINITE_SCROLL_PAGINATION_RESULTS } from "@/config" -import { getAuthSession } from "@/lib/auth" import { db } from "@/lib/db" import QuestionFeed from "@/components/QuestionFeed" import { buttonVariants } from "@/components/ui/Button" @@ -7,15 +6,7 @@ import { HomeIcon } from "lucide-react" import Link from "next/link" import { cn } from "@/lib/utils" -interface PageProps { - params: { - slug: string - } -} - -const page = async ({ params }: PageProps) => { - const { slug } = params - const session = await getAuthSession() +const page = async () => { const questions = await db.question.findMany({ where: { NOT: { diff --git a/src/components/CreateAnswer.tsx b/src/components/CreateAnswer.tsx index 1f85da7..9b7f6bc 100644 --- a/src/components/CreateAnswer.tsx +++ b/src/components/CreateAnswer.tsx @@ -1,7 +1,6 @@ "use client" import { Session } from "next-auth" -import { Button } from "@/components/ui/Button" import { FC } from "react" import UserAvatar from "./UserAvatar" import Editor from "@/components/Editor" diff --git a/src/components/CreatePost.tsx b/src/components/CreatePost.tsx index 63b8091..84b6522 100644 --- a/src/components/CreatePost.tsx +++ b/src/components/CreatePost.tsx @@ -1,7 +1,7 @@ "use client" import { Session } from "next-auth" -import { usePathname, useRouter } from "next/navigation" +import { usePathname } from "next/navigation" import { FC } from "react" import UserAvatar from "./UserAvatar" import Link from "next/link" @@ -12,7 +12,6 @@ interface CreatePostProps { } const CreatePost: FC = ({ session }) => { - const router = useRouter() const pathname = usePathname() return ( diff --git a/src/components/Editor.tsx b/src/components/Editor.tsx index b0b648a..2952d3e 100644 --- a/src/components/Editor.tsx +++ b/src/components/Editor.tsx @@ -1,13 +1,6 @@ "use client" -import { - FC, - startTransition, - useCallback, - useEffect, - useRef, - useState, -} from "react" +import { FC, useCallback, useEffect, useRef, useState } from "react" import TextareaAutosize from "react-textarea-autosize" import { useForm } from "react-hook-form" import { diff --git a/src/components/Form.tsx b/src/components/Form.tsx index 6b4d079..5b8cd6b 100644 --- a/src/components/Form.tsx +++ b/src/components/Form.tsx @@ -144,7 +144,10 @@ export function ProfileForm({ const response = await axios.get("/api/subject/all/value-label") setAssignatures(response.data) } catch (error) { - console.error("Error fetching subjects:", error) + toast({ + title: "No s'han pogut carregar les assignatures", + description: `Error fetching subjects: ${error}`, + }) } } fetchAssignatures() diff --git a/src/components/SearchBar.tsx b/src/components/SearchBar.tsx index 94d9384..89dc46f 100644 --- a/src/components/SearchBar.tsx +++ b/src/components/SearchBar.tsx @@ -90,7 +90,7 @@ const SearchBar: FC = ({}) => { _count: Prisma.QuestionCountOutputType subject: Subject })[] - const isFetching = queriesResults.some((query) => query.isFetching) + // const isFetching = queriesResults.some((query) => query.isFetching) const isFetched = queriesResults.every((query) => query.isFetched) const refetch = useCallback(() => { subjectQueryResultsObjects.refetch() diff --git a/src/components/votes/AnswerAcceptClient.tsx b/src/components/votes/AnswerAcceptClient.tsx index 082476c..52e8356 100644 --- a/src/components/votes/AnswerAcceptClient.tsx +++ b/src/components/votes/AnswerAcceptClient.tsx @@ -48,7 +48,7 @@ const AnswerAcceptClient = ({ await axios.patch("/api/subject/answer/accept", payload) }, - onError: (err, accept) => { + onError: (err) => { // reset current acceptation setCurrentAccepted(prevAccepted)