diff --git a/components/modals/upload-post-modal.tsx b/components/modals/upload-post-modal.tsx index 8c0633a..f1fca38 100644 --- a/components/modals/upload-post-modal.tsx +++ b/components/modals/upload-post-modal.tsx @@ -2,9 +2,9 @@ import Image from 'next/image' import { isEmpty } from 'lodash' -import { SubmitHandler, useForm } from 'react-hook-form' -import { ChevronLeft, MapPin } from 'lucide-react' import { zodResolver } from '@hookform/resolvers/zod' +import { SubmitHandler, useForm } from 'react-hook-form' +import { ChevronDown, ChevronLeft, MapPin } from 'lucide-react' import React, { ChangeEvent, ReactNode, useState } from 'react' import { cn } from '~/lib/utils' @@ -12,10 +12,21 @@ import { trpc } from '~/trpc/client' import { Tag } from '~/helpers/tag-helpers' import { useUpload } from '~/hooks/use-upload' import { Emoji } from '~/helpers/emoji-helpers' +import { Textarea } from '~/components/ui/textarea' import { PostSchema, PostSchemaType } from '~/zod/schema' import { Dialog, DialogContent, DialogHeader } from '~/components/ui/dialog' +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '~/components/ui/collapsible' +import { + Form, + FormItem, + FormLabel, + FormField, + FormControl, + FormDescription +} from '~/components/ui/form' import { Button } from './../ui/button' +import { Switch } from './../ui/switch' import { Carousel } from './../carousel' import { TagInput } from './../tag-input' import { EmojiPicker } from './../emoji-picker' @@ -25,24 +36,28 @@ import { UploadPhotoVideoIcon } from './../custom-icon/upload-video-icon' export const UploadPostModal = (): JSX.Element => { const upload = useUpload() const currentUser = trpc.user.currentUser.useQuery() + const hashtags = trpc.hashtag.getHashtags.useQuery() const [tags, setTags] = useState([]) const [files, setFiles] = useState([]) const [fileUrls, setFileUrls] = useState([]) + const [advanceSetting, setAdvanceSetting] = useState(true) const isFileExist = files + const form = useForm({ + mode: 'onTouched', + resolver: zodResolver(PostSchema) + }) + const { reset, watch, - register, + control, setValue, handleSubmit, formState: { isSubmitting } - } = useForm({ - mode: 'onTouched', - resolver: zodResolver(PostSchema) - }) + } = form const handleFileChange = (e: ChangeEvent): void => { const files = e.target.files @@ -62,6 +77,8 @@ export const UploadPostModal = (): JSX.Element => { ) } + const handleCollapsibleChange = (): void => setAdvanceSetting((prev) => !prev) + const handleReset = (): void => { setFileUrls([]) setFiles([]) @@ -82,184 +99,269 @@ export const UploadPostModal = (): JSX.Element => { } } - const handlePost: SubmitHandler = async (data): Promise => { - // console.log(data) - // console.log(tags) - handleReset() + const onPost: SubmitHandler = async (data): Promise => { + // console.log({ + // ...data, + // tags + // }) } return ( -
- - {!isEmpty(isFileExist) ? ( - - ) : ( - - )} -

Create new post

- {!isEmpty(isFileExist) ? ( - - ) : ( - - )} -
- {/*
*/} -
+ - {isEmpty(isFileExist) && ( -
-
- - -

- Drag photos and videos here -

-
- - -
- )} - {!isEmpty(isFileExist) && ( -
-
+ + ) : ( + + )} +

Create new post

+ {!isEmpty(isFileExist) ? ( +
-
-
- : 'Share'} + + ) : ( + + )} + + {/*
*/} +
+ {isEmpty(isFileExist) && ( +
+
+ + +

+ Drag photos and videos here +

+
+ + +
+ )} + {!isEmpty(isFileExist) && ( +
+
+ + { + fileUrls?.map((asset, idx) => { + if (asset.endsWith('.mp4')) { + return ( + + ) + } else { + return ( + + ) + } + }) as ReactNode[] } - width={32} - height={32} - className="rounded-full border-[3px] border-white shadow outline-4" - alt="User Profile" - /> -

{currentUser?.data?.displayName}

+
-
- -
- +
+ User Profile +

{currentUser?.data?.displayName}

+
+
+ ( + + +