= ({ subjectId, contentType, questionId }) => {
const { ref: titleRef, ...rest } = register("title")
return (
-
-
+
)
}
diff --git a/src/components/Form.tsx b/src/components/Form.tsx
index 2a6ea68..6b4d079 100644
--- a/src/components/Form.tsx
+++ b/src/components/Form.tsx
@@ -22,12 +22,16 @@ import { Combobox } from "@/components/Combobox"
import { Checkbox } from "@/components/ui/checkbox"
import { ApuntsPostCreationRequest } from "@/lib/validators/post"
import { uploadFiles } from "@/lib/uploadthing"
+import Fireworks from "react-canvas-confetti/dist/presets/fireworks"
const formSchema = z.object({
pdf: z.any(),
title: z.string({
required_error: "Selecciona un títol",
}),
+ year: z.string({
+ required_error: "Selecciona un any",
+ }),
assignatura: z.string({
required_error: "Selecciona una assignatura.",
}),
@@ -43,17 +47,23 @@ const formSchema = z.object({
export function ProfileForm({
PreselectedSubject,
isAdmin,
+ generacio,
+ semester,
}: {
PreselectedSubject: string
isAdmin: boolean
+ generacio: number
+ semester?: number
}) {
const router = useRouter()
const [assignatures, setAssignatures] = useState([])
+ const [isVisible, setIsVisible] = useState(false)
const { mutate: createApuntsPost } = useMutation({
mutationFn: async ({
pdf,
title,
+ year,
assignatura,
tipus,
anonim,
@@ -62,6 +72,7 @@ export function ProfileForm({
const payload: ApuntsPostCreationRequest = {
pdf,
title,
+ year,
assignatura,
tipus,
anonim,
@@ -90,6 +101,7 @@ export function ProfileForm({
}
},
onSuccess: (subjectAcronym) => {
+ setIsVisible(true)
router.push(`/${subjectAcronym}`)
router.refresh()
@@ -116,6 +128,7 @@ export function ProfileForm({
const payload: ApuntsPostCreationRequest = {
pdf: res.fileUrl,
title: data.title,
+ year: Number(data.year),
assignatura: data.assignatura,
tipus: data.tipus,
anonim: data.anonim,
@@ -160,12 +173,55 @@ export function ProfileForm({
},
]
+ const date = new Date()
+ const end = date.getFullYear()
+ interface Year {
+ value: string
+ label: string
+ }
+ let tipus_any: Year[] = []
+ for (let i = generacio; i < end; i++) {
+ tipus_any.push({
+ value: i.toString(),
+ label: i.toString(),
+ })
+ }
+ const default_year = semester
+ ? (generacio + Math.floor((semester - 1) / 2)).toString()
+ : undefined
+
return (
)
diff --git a/src/components/PostView.tsx b/src/components/PostView.tsx
index 0755cad..9da30e5 100644
--- a/src/components/PostView.tsx
+++ b/src/components/PostView.tsx
@@ -2,7 +2,7 @@
import { FC } from "react"
import { ExtendedPost, ExtendedComment } from "@/types/db"
import { useSession } from "next-auth/react"
-import MiniCreateComment from "@/components/MiniCreateComment"
+import CreateComment from "@/components/CreateComment"
import CommentFeed from "@/components/CommentFeed"
import Post from "@/components/Post"
@@ -29,7 +29,7 @@ export const PostView: FC
= ({ post, comments }) => {
/>
-
+
= ({ question, answers }) => {
/>
- = ({
return isSubscribed ? (
) : (
)
}
diff --git a/src/config.ts b/src/config.ts
index 53cbb5a..cd179dc 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -1 +1,2 @@
export const INFINITE_SCROLL_PAGINATION_RESULTS = 4
+export const GCED_START = 2017
diff --git a/src/lib/validators/post.ts b/src/lib/validators/post.ts
index 610d1dc..be2fdce 100644
--- a/src/lib/validators/post.ts
+++ b/src/lib/validators/post.ts
@@ -19,6 +19,7 @@ export const CommentValidator = z.object({
export const ApuntsPostValidator = z.object({
pdf: z.any(),
title: z.string(),
+ year: z.number(),
assignatura: z.string().min(2).max(5),
tipus: z.string(),
anonim: z.boolean(),
diff --git a/src/lib/validators/question.ts b/src/lib/validators/question.ts
index 835df5b..5cba920 100644
--- a/src/lib/validators/question.ts
+++ b/src/lib/validators/question.ts
@@ -11,8 +11,8 @@ export const QuestionValidator = z.object({
export const AnswerValidator = z.object({
title: z
.string()
- .min(3, { message: "Content must be at least 3 characters long" })
- .max(128, { message: "Content must be at most 2048 characters long" }),
+ .min(3, { message: "Title must be at least 3 characters long" })
+ .max(128, { message: "Title must be at most 2048 characters long" }),
subjectId: z.string(),
content: z.any(),
questionId: z.string(),
diff --git a/yarn.lock b/yarn.lock
index ef89138..368e1b6 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1109,6 +1109,11 @@
"@tanstack/query-core" "4.29.11"
use-sync-external-store "^1.2.0"
+"@types/canvas-confetti@^1.6.4":
+ version "1.6.4"
+ resolved "https://registry.yarnpkg.com/@types/canvas-confetti/-/canvas-confetti-1.6.4.tgz#620fd8d78b335d6a4046c0f73236d6988b37552a"
+ integrity sha512-fNyZ/Fdw/Y92X0vv7B+BD6ysHL4xVU5dJcgzgxLdGbn8O3PezZNIJpml44lKM0nsGur+o/6+NZbZeNTt00U1uA==
+
"@types/editorjs__header@^2.6.0":
version "2.6.0"
resolved "https://registry.npmjs.org/@types/editorjs__header/-/editorjs__header-2.6.0.tgz"
@@ -1656,6 +1661,11 @@ caniuse-lite@^1.0.30001464, caniuse-lite@^1.0.30001489, caniuse-lite@^1.0.300015
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001585.tgz"
integrity sha512-yr2BWR1yLXQ8fMpdS/4ZZXpseBgE7o4g41x3a6AJOqZuOi+iE/WdJYAuZ6Y95i4Ohd2Y+9MzIWRR+uGABH4s3Q==
+canvas-confetti@^1.9.2:
+ version "1.9.2"
+ resolved "https://registry.yarnpkg.com/canvas-confetti/-/canvas-confetti-1.9.2.tgz#c9f74098c7fdf66dd9d1aab5d381061cf74e48f0"
+ integrity sha512-6Xi7aHHzKwxZsem4mCKoqP6YwUG3HamaHHAlz1hTNQPCqXhARFpSXnkC9TWlahHY5CG6hSL5XexNjxK8irVErg==
+
canvas@^2.11.2:
version "2.11.2"
resolved "https://registry.npmjs.org/canvas/-/canvas-2.11.2.tgz"
@@ -4183,6 +4193,14 @@ rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"
+react-canvas-confetti@^2.0.7:
+ version "2.0.7"
+ resolved "https://registry.yarnpkg.com/react-canvas-confetti/-/react-canvas-confetti-2.0.7.tgz#0499e7815b50f6a7731fd01729e07c30faa300f3"
+ integrity sha512-DIj44O35TPAwJkUSIZqWdVsgAMHtVf8h7YNmnr3jF3bn5mG+d7Rh9gEcRmdJfYgRzh6K+MAGujwUoIqQyLnMJw==
+ dependencies:
+ "@types/canvas-confetti" "^1.6.4"
+ canvas-confetti "^1.9.2"
+
react-dom@^18.2.0:
version "18.2.0"
resolved "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz"