Skip to content

Commit

Permalink
Merge pull request #72 from data-students/1-scrolling-combobox
Browse files Browse the repository at this point in the history
1 scrolling combobox
  • Loading branch information
puigde committed Mar 18, 2024
2 parents a5a7fbd + 4e6dc95 commit dca480c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 149 deletions.
26 changes: 26 additions & 0 deletions src/app/api/subject/all/value-label/route.ts
Original file line number Diff line number Diff line change
@@ -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",
},
})
}
11 changes: 1 addition & 10 deletions src/app/unansweredquestions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
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"
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: {
Expand Down
12 changes: 7 additions & 5 deletions src/components/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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..."}
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-[200px] p-0">
<PopoverContent className="max-h-80 flex flex-col w-80 p-0">
<Command>
<CommandInput placeholder="Search..." />
<CommandEmpty>No option found.</CommandEmpty>
<CommandGroup>
<CommandEmpty className="flex-1">
No s&apos;han trobat resultats.
</CommandEmpty>
<CommandGroup className="flex-1 h-full overflow-y-scroll">
{options.map((option) => (
<CommandItem
key={option.value}
Expand Down
1 change: 0 additions & 1 deletion src/components/CreateAnswer.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/components/CreatePost.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -12,7 +12,6 @@ interface CreatePostProps {
}

const CreatePost: FC<CreatePostProps> = ({ session }) => {
const router = useRouter()
const pathname = usePathname()

return (
Expand Down
9 changes: 1 addition & 8 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
138 changes: 17 additions & 121 deletions src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -296,7 +193,6 @@ export function ProfileForm({
? (generacio + Math.floor((semester - 1) / 2)).toString()
: undefined

// ------------------------------
return (
<Form {...form}>
<form
Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const SearchBar: FC<SearchBarProps> = ({}) => {
_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()
Expand Down
2 changes: 1 addition & 1 deletion src/components/votes/AnswerAcceptClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AnswerAcceptClient = ({

await axios.patch("/api/subject/answer/accept", payload)
},
onError: (err, accept) => {
onError: (err) => {
// reset current acceptation
setCurrentAccepted(prevAccepted)

Expand Down

0 comments on commit dca480c

Please sign in to comment.