Skip to content

Commit 93888e7

Browse files
committed
Refactor BottomNewChirp
1 parent a2ae6b0 commit 93888e7

File tree

3 files changed

+53
-68
lines changed

3 files changed

+53
-68
lines changed

frontend/src/components/NewChirp/BottomNewChirp.tsx frontend/src/components/BottomNewChirp.tsx

+52-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
import { TrashIcon } from "@heroicons/react/24/outline";
1+
import { TrashIcon, ArrowUpTrayIcon } from "@heroicons/react/24/outline";
22
import { useAtomValue, useSetAtom } from "jotai";
3-
import { useEffect } from "react";
3+
import { useEffect, useRef } from "react";
44
import { SubmitHandler, useForm } from "react-hook-form";
55
import z from "zod";
66

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";
1111

1212
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+
1324
const { register, handleSubmit, setValue, reset } =
1425
useForm<z.infer<typeof CreatePost>>();
1526
const {
@@ -47,7 +58,12 @@ export default function BottomNewChirp() {
4758
<input type="hidden" value="public" {...register("visibility")} />
4859
<div className="chat-bubble chat-bubble-primary">
4960
<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>
5167
<div>
5268
{pictureUrlArr.length > 0 && (
5369
<div>
@@ -74,7 +90,6 @@ export default function BottomNewChirp() {
7490
))}
7591
</div>
7692
)}
77-
7893
<input
7994
type="text"
8095
className="input w-full bg-transparent"
@@ -95,6 +110,35 @@ export default function BottomNewChirp() {
95110
</div>
96111
{error && <div className="mt-5 text-error">{error.message}</div>}
97112
</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>
98142
</>
99143
);
100144
}

frontend/src/components/NewChirp/BottomUpload.tsx

-59
This file was deleted.

frontend/src/pages/login/LogInIndex.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { PlusIcon } from "@heroicons/react/24/outline";
22
import { Fragment } from "react";
33

4+
import BottomNewChirp from "../../components/BottomNewChirp";
45
import Images from "../../components/Images";
5-
import BottomNewChirp from "../../components/NewChirp/BottomNewChirp";
66
import { useNotes } from "../../queries/note";
77

88
export function LogInIndexPage() {

0 commit comments

Comments
 (0)