1
- import { TrashIcon } from "@heroicons/react/24/outline" ;
1
+ import { TrashIcon , ArrowUpTrayIcon } from "@heroicons/react/24/outline" ;
2
2
import { useAtomValue , useSetAtom } from "jotai" ;
3
- import { useEffect } from "react" ;
3
+ import { useEffect , useRef } from "react" ;
4
4
import { SubmitHandler , useForm } from "react-hook-form" ;
5
5
import z from "zod" ;
6
6
7
- import { CreatePost } from "../../ dto" ;
8
- import { usePostNoteMutation } from "../../ queries/note " ;
9
- import { pictureUrl } from "../../states/states " ;
10
- import BottomUpload from "./BottomUpload " ;
7
+ import { CreatePost } from "../dto" ;
8
+ import { useLocalFiles } from "../queries/file " ;
9
+ import { usePostNoteMutation } from "../queries/note " ;
10
+ import { pictureUrl } from "../states/states " ;
11
11
12
12
export default function BottomNewChirp ( ) {
13
+ const modalRef = useRef < HTMLDialogElement > ( null ) ;
14
+ const setUrl = useSetAtom ( pictureUrl ) ;
15
+
16
+ const { data : localFiles } = useLocalFiles ( ) ;
17
+
18
+ const handlePictureClick = ( url : string ) => {
19
+ setUrl ( ( el ) => [ ...el , url ] ) ;
20
+
21
+ modalRef ?. current ?. close ( ) ;
22
+ } ;
23
+
13
24
const { register, handleSubmit, setValue, reset } =
14
25
useForm < z . infer < typeof CreatePost > > ( ) ;
15
26
const {
@@ -47,7 +58,12 @@ export default function BottomNewChirp() {
47
58
< input type = "hidden" value = "public" { ...register ( "visibility" ) } />
48
59
< div className = "chat-bubble chat-bubble-primary" >
49
60
< div className = "flex items-center" >
50
- < BottomUpload />
61
+ < button
62
+ onClick = { ( ) => modalRef ?. current ?. showModal ( ) }
63
+ className = "btn btn-ghost btn-sm mr-2"
64
+ >
65
+ < ArrowUpTrayIcon width = { 24 } height = { 24 } />
66
+ </ button >
51
67
< div >
52
68
{ pictureUrlArr . length > 0 && (
53
69
< div >
@@ -74,7 +90,6 @@ export default function BottomNewChirp() {
74
90
) ) }
75
91
</ div >
76
92
) }
77
-
78
93
< input
79
94
type = "text"
80
95
className = "input w-full bg-transparent"
@@ -95,6 +110,35 @@ export default function BottomNewChirp() {
95
110
</ div >
96
111
{ error && < div className = "mt-5 text-error" > { error . message } </ div > }
97
112
</ form >
113
+ < dialog ref = { modalRef } className = "modal" >
114
+ < div className = "modal-box max-w-screen-xl" >
115
+ { ( localFiles ?. pages ?? [ ] ) . map ( ( page , i ) => (
116
+ < div key = { i } className = "flex" >
117
+ < >
118
+ { page . length !== 0 ? (
119
+ < div className = "grid grid-cols-3 gap-4" >
120
+ { page . map ( ( file ) => (
121
+ < div key = { file . id } className = "h-48 w-48" >
122
+ < img
123
+ src = { file . url }
124
+ alt = { file . alt ?? undefined }
125
+ className = "cursor-pointer rounded-lg border border-solid hover:shadow-lg"
126
+ onClick = { ( ) => handlePictureClick ( file . url ) }
127
+ />
128
+ </ div >
129
+ ) ) }
130
+ </ div >
131
+ ) : (
132
+ < span > no items</ span >
133
+ ) }
134
+ </ >
135
+ </ div >
136
+ ) ) }
137
+ </ div >
138
+ < form method = "dialog" className = "modal-backdrop" >
139
+ < button > close</ button >
140
+ </ form >
141
+ </ dialog >
98
142
</ >
99
143
) ;
100
144
}
0 commit comments