Showing
2 changed files
with
81 additions
and
1 deletions
frontend/src/file/CreateFolderPopover.tsx
0 → 100644
| 1 | +import React, { useState } from "react"; | ||
| 2 | +import { Button, Input } from "antd"; | ||
| 3 | + | ||
| 4 | +export type CreateFolderPopoverProps = { | ||
| 5 | + onCreate: (name: string) => void; | ||
| 6 | + onCancel?: () => void; | ||
| 7 | +}; | ||
| 8 | + | ||
| 9 | +export function CreateFolderPopover({ | ||
| 10 | + onCreate, | ||
| 11 | + onCancel, | ||
| 12 | +}: CreateFolderPopoverProps) { | ||
| 13 | + const [name, setName] = useState<string>(""); | ||
| 14 | + return ( | ||
| 15 | + <div> | ||
| 16 | + <Input | ||
| 17 | + value={name} | ||
| 18 | + onChange={(event) => setName(event.target.value)} | ||
| 19 | + placeholder="이름" | ||
| 20 | + style={{ marginBottom: 10 }} | ||
| 21 | + /> | ||
| 22 | + <div className="ant-popover-buttons"> | ||
| 23 | + <Button size="small" onClick={onCancel}> | ||
| 24 | + 취소 | ||
| 25 | + </Button> | ||
| 26 | + <Button type="primary" size="small" onClick={() => onCreate(name)}> | ||
| 27 | + 생성 | ||
| 28 | + </Button> | ||
| 29 | + </div> | ||
| 30 | + </div> | ||
| 31 | + ); | ||
| 32 | +} |
| 1 | -import React, { useCallback, useState } from "react"; | 1 | +import React, { useCallback, useState, useContext } from "react"; |
| 2 | import { Table, message, Button, Popover } from "antd"; | 2 | import { Table, message, Button, Popover } from "antd"; |
| 3 | import { ColumnsType } from "antd/lib/table"; | 3 | import { ColumnsType } from "antd/lib/table"; |
| 4 | import filesize from "filesize"; | 4 | import filesize from "filesize"; |
| ... | @@ -11,14 +11,43 @@ import { FileItemActions } from "./FileItemActions"; | ... | @@ -11,14 +11,43 @@ import { FileItemActions } from "./FileItemActions"; |
| 11 | 11 | ||
| 12 | import styles from "./FileList.module.scss"; | 12 | import styles from "./FileList.module.scss"; |
| 13 | import { FileUploadPopover } from "./FileUploadPopover"; | 13 | import { FileUploadPopover } from "./FileUploadPopover"; |
| 14 | +import { CreateFolderPopover } from "./CreateFolderPopover"; | ||
| 15 | +import { TokenContext } from "auth/useAuth"; | ||
| 14 | 16 | ||
| 15 | export function FileList() { | 17 | export function FileList() { |
| 16 | const id = useParams<{ id: string }>().id; | 18 | const id = useParams<{ id: string }>().id; |
| 17 | const { data, reload } = useFileList(id); | 19 | const { data, reload } = useFileList(id); |
| 20 | + | ||
| 18 | const [upload, setUpload] = useState<boolean>(false); | 21 | const [upload, setUpload] = useState<boolean>(false); |
| 22 | + const [createFolder, setCreateFolder] = useState<boolean>(false); | ||
| 23 | + | ||
| 24 | + const token = useContext(TokenContext); | ||
| 25 | + const userId = token.user.id; | ||
| 19 | 26 | ||
| 20 | const api = useApi(); | 27 | const api = useApi(); |
| 21 | 28 | ||
| 29 | + const handleCreateFolder = useCallback( | ||
| 30 | + async (id: number, name: string) => { | ||
| 31 | + try { | ||
| 32 | + const body = new URLSearchParams(); | ||
| 33 | + body.set("name", name); | ||
| 34 | + | ||
| 35 | + await api.post(`/items/${id}/children/`, { | ||
| 36 | + searchParams: { | ||
| 37 | + user_id: userId, | ||
| 38 | + }, | ||
| 39 | + body, | ||
| 40 | + }); | ||
| 41 | + await reload(); | ||
| 42 | + | ||
| 43 | + message.info("폴더가 생성되었습니다"); | ||
| 44 | + } catch { | ||
| 45 | + message.error("폴더 생성에 실패했습니다"); | ||
| 46 | + } | ||
| 47 | + }, | ||
| 48 | + [api, reload, userId] | ||
| 49 | + ); | ||
| 50 | + | ||
| 22 | const handleRename = useCallback( | 51 | const handleRename = useCallback( |
| 23 | async (id: number, name: string) => { | 52 | async (id: number, name: string) => { |
| 24 | try { | 53 | try { |
| ... | @@ -115,9 +144,28 @@ export function FileList() { | ... | @@ -115,9 +144,28 @@ export function FileList() { |
| 115 | 파일 업로드 | 144 | 파일 업로드 |
| 116 | </Button> | 145 | </Button> |
| 117 | </Popover> | 146 | </Popover> |
| 147 | + <Popover | ||
| 148 | + title="폴더 이름을 입력하세요" | ||
| 149 | + content={ | ||
| 150 | + <CreateFolderPopover | ||
| 151 | + onCreate={(name: string) => { | ||
| 152 | + if (!name) { | ||
| 153 | + return message.error("폴더 이름을 입력하세요"); | ||
| 154 | + } | ||
| 155 | + handleCreateFolder(data.id, name); | ||
| 156 | + setCreateFolder(false); | ||
| 157 | + }} | ||
| 158 | + onCancel={() => setCreateFolder(false)} | ||
| 159 | + /> | ||
| 160 | + } | ||
| 161 | + trigger="click" | ||
| 162 | + visible={createFolder} | ||
| 163 | + onVisibleChange={setCreateFolder} | ||
| 164 | + > | ||
| 118 | <Button type="link" size="small"> | 165 | <Button type="link" size="small"> |
| 119 | 새 폴더 | 166 | 새 폴더 |
| 120 | </Button> | 167 | </Button> |
| 168 | + </Popover> | ||
| 121 | </div> | 169 | </div> |
| 122 | </div> | 170 | </div> |
| 123 | <Table | 171 | <Table | ... | ... |
-
Please register or login to post a comment