diff --git a/docker-compose.yml b/docker-compose.yml index a96541355..8c487ef75 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: - '5555:5555' volumes: - .:/usr/src/app + - /usr/src/app/.next - /usr/src/app/node_modules depends_on: db: diff --git a/src/app/layout.tsx b/src/app/layout.tsx index b1b152e64..733f37e35 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -8,6 +8,7 @@ import { GoogleAnalytics } from '@/components/analytics/GoogleAnalytics'; import { siteConfig } from '@/config/site-config'; import { Toaster } from 'sonner'; import { Navbar } from '@/components/Navbar'; +import NextTopLoader from 'nextjs-toploader'; const satoshi = localFont({ display: 'swap', @@ -31,6 +32,7 @@ export default function RootLayout({ children }: { children: ReactNode }) { )} > + {children} diff --git a/src/components/CourseView.tsx b/src/components/CourseView.tsx index 9b5c57a5f..124a48f32 100644 --- a/src/components/CourseView.tsx +++ b/src/components/CourseView.tsx @@ -38,8 +38,8 @@ export const CourseView = ({ ? 'folder' : courseContent?.value.type; return ( -
-
+
+
{ const paramsObject = searchParamsToObject(searchParam); const path = usePathname(); const router = useRouter(); + const tagInputRef = useRef(null); const [value, setValue] = useState('**Hello world!!!**'); + const [tags, setTags] = useState([]); const containerRef = useRef(null); const { ref, onOpen, onClose } = useModal(); const handleMarkdownChange = (newValue?: string) => { @@ -54,6 +56,7 @@ export const NewPostDialog = () => { formRef?.current?.reset(); setValue(''); router.push(`/question/${data.slug}`); + setTags([]); handleOnCloseClick(); }, onError: (error) => { @@ -68,20 +71,41 @@ export const NewPostDialog = () => { setFieldErrors({}); } }; + const onSubmit = (event: React.FormEvent) => { event.preventDefault(); const formData = new FormData(event.currentTarget); const title = formData.get('title'); - - const tags = formData.get('tags'); - execute({ title: title?.toString() || '', content: value, - tags: (tags?.toString() || '').split(','), + tags, }); }; + const addTag = (event: React.KeyboardEvent) => { + if (event.key === ',') { + event.preventDefault(); + const formData = new FormData(formRef.current as HTMLFormElement); + const tag = formData.get('tags')?.toString().trim().replace(/,+$/, ''); + + if (tag) { + setTags((prevTags) => [ + ...prevTags, + tag + ]); + } + if (tagInputRef.current) { + tagInputRef.current.value = ''; + } + } + }; + + + const removeTag = (tag: string) => { + setTags(tags.filter((t) => t !== tag)); + }; + return (
@@ -130,12 +154,31 @@ export const NewPostDialog = () => {

Tags

- +
+
+ {tags.map((tag, index) => ( + + {tag} + removeTag(tag)} + /> + + ))} +
+ +
{ ); -}; +}; \ No newline at end of file diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 823362a75..10614e6e0 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -182,7 +182,7 @@ export function Sidebar({ return ( <> - diff --git a/src/components/Signin.tsx b/src/components/Signin.tsx index b528db3b2..301932d03 100644 --- a/src/components/Signin.tsx +++ b/src/components/Signin.tsx @@ -131,7 +131,17 @@ const Signin = () => { router.push('/'); toast.success('Signed In'); } else { - toast.error('oops something went wrong..!'); + if (res.status === 401) { + toast.error('Invalid Credentials, try again!'); + } else if (res.status === 400) { + toast.error('Missing Credentials!'); + } else if (res.status === 404) { + toast.error('Account not found!'); + } else if (res.status === 403) { + toast.error('Forbidden!'); + } else { + toast.error('oops something went wrong..!'); + } setCheckingPassword(false); } }; diff --git a/src/components/comment/Comments.tsx b/src/components/comment/Comments.tsx index 441896a5e..8e1261380 100644 --- a/src/components/comment/Comments.tsx +++ b/src/components/comment/Comments.tsx @@ -241,36 +241,40 @@ const Comments = async ({ )}
- - - - - - {(session.user.id.toString() === - (c as ExtendedComment).userId.toString() || - session.user.role === ROLES.ADMIN) && ( - - - - )} - {session.user.role === ROLES.ADMIN && ( - - - - )} - {session.user.role === ROLES.ADMIN && ( - - - - )} - - + {(session.user.id.toString() === + (c as ExtendedComment).userId.toString() || + session.user.role === ROLES.ADMIN) && ( + + + + + + {(session.user.id.toString() === + (c as ExtendedComment).userId.toString() || + session.user.role === ROLES.ADMIN) && ( + + + + )} + {session.user.role === ROLES.ADMIN && ( + + + + )} + {session.user.role === ROLES.ADMIN && ( + + + + )} + + + )}
= ({ const router = useRouter(); + const [isPending, startTransition] = useTransition(); + const { execute, fieldErrors } = useAction(createAnswer, { onSuccess: () => { toast.success(`Reply added`); @@ -97,11 +99,13 @@ const PostCard: React.FC = ({ !post.content && !isAnswer ? `rounded-xl bg-neutral-50 hover:-translate-y-2 dark:bg-neutral-900` : `rounded-r-xl border-l-2 border-blue-500 bg-primary/5` - }`} + } ${isPending && `animate-pulse duration-700`}`} onClick={() => { - if (isExtendedQuestion(post)) { - router.push(`/question/${post?.slug}`); - } + startTransition(() => { + if (isExtendedQuestion(post)) { + router.push(`/question/${post?.slug}`); + } + }); }} >
diff --git a/src/components/posts/form/form-input.tsx b/src/components/posts/form/form-input.tsx index d68d11f9e..577bd81a9 100644 --- a/src/components/posts/form/form-input.tsx +++ b/src/components/posts/form/form-input.tsx @@ -1,5 +1,6 @@ 'use client'; +import React from 'react'; import { forwardRef } from 'react'; import { useFormStatus } from 'react-dom'; @@ -19,6 +20,7 @@ interface FormInputProps { className?: string; defaultValue?: string; onBlur?: () => void; + onKeyUp?: (event: React.KeyboardEvent) => void; } export const FormPostInput = forwardRef( @@ -33,6 +35,7 @@ export const FormPostInput = forwardRef( errors, className, defaultValue = '', + onKeyUp, onBlur, }, ref, @@ -57,6 +60,7 @@ export const FormPostInput = forwardRef( required={required} name={id} id={id} + onKeyUp={onKeyUp} placeholder={placeholder} type={type} disabled={pending || disabled} @@ -73,4 +77,4 @@ export const FormPostInput = forwardRef( }, ); -FormPostInput.displayName = 'FormPostInput'; +FormPostInput.displayName = 'FormPostInput'; \ No newline at end of file