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..35d1c7f
--- /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() {
+ 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/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/Combobox.tsx b/src/components/Combobox.tsx
index b7258ed..8ae33d1 100644
--- a/src/components/Combobox.tsx
+++ b/src/components/Combobox.tsx
@@ -38,19 +38,21 @@ 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) => (
= ({ 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 3810275..5b8cd6b 100644
--- a/src/components/Form.tsx
+++ b/src/components/Form.tsx
@@ -22,7 +22,6 @@ import { Combobox } from "@/components/Combobox"
import { Checkbox } from "@/components/ui/checkbox"
import { ApuntsPostCreationRequest } from "@/lib/validators/post"
import { uploadFiles } from "@/lib/uploadthing"
-import { GCED_START } from "@/config"
import Fireworks from "react-canvas-confetti/dist/presets/fireworks"
const formSchema = z.object({
@@ -57,6 +56,7 @@ export function ProfileForm({
semester?: number
}) {
const router = useRouter()
+ const [assignatures, setAssignatures] = useState([])
const [isVisible, setIsVisible] = useState(false)
const { mutate: createApuntsPost } = useMutation({
@@ -137,125 +137,22 @@ export function ProfileForm({
createApuntsPost(payload)
}
- // ------------------------------
- const assignatures = [
- {
- value: "alg",
- label: "ALG",
- },
- {
- value: "cal",
- label: "CAL",
- },
- {
- value: "lmd",
- label: "LMD",
- },
- {
- value: "ap1",
- label: "AP1",
- },
- {
- value: "ap2",
- label: "AP2",
- },
- {
- value: "ac2",
- label: "AC2",
- },
- {
- value: "pie1",
- label: "PIE1",
- },
- {
- value: "com",
- label: "COM",
- },
- {
- value: "sis",
- label: "SIS",
- },
- {
- value: "ap3",
- label: "AP3",
- },
- {
- value: "teoi",
- label: "TEOI",
- },
- {
- value: "pie2",
- label: "PIE2",
- },
- {
- value: "bd",
- label: "BD",
- },
- {
- value: "psd",
- label: "PSD",
- },
- {
- value: "ipa",
- label: "IPA",
- },
- {
- value: "om",
- label: "OM",
- },
- {
- value: "ad",
- label: "AD",
- },
- {
- value: "aa1",
- label: "AA1",
- },
- {
- value: "vi",
- label: "VI",
- },
- {
- value: "cai",
- label: "CAI",
- },
- {
- value: "bda",
- label: "BDA",
- },
- {
- value: "aa2",
- label: "AA2",
- },
- {
- value: "ei",
- label: "EI",
- },
- {
- value: "taed1",
- label: "TAED1",
- },
- {
- value: "poe",
- label: "POE",
- },
- {
- value: "piva",
- label: "PIVA",
- },
- {
- value: "pe",
- label: "PE",
- },
- {
- value: "taed2",
- label: "TAED2",
- },
- {
- value: "altres",
- label: "Altres",
- },
- ]
+
+ useEffect(() => {
+ async function fetchAssignatures() {
+ try {
+ const response = await axios.get("/api/subject/all/value-label")
+ setAssignatures(response.data)
+ } catch (error) {
+ toast({
+ title: "No s'han pogut carregar les assignatures",
+ description: `Error fetching subjects: ${error}`,
+ })
+ }
+ }
+ fetchAssignatures()
+ }, [])
+
const tipus = [
{
value: "apunts",
@@ -296,7 +193,6 @@ export function ProfileForm({
? (generacio + Math.floor((semester - 1) / 2)).toString()
: undefined
- // ------------------------------
return (