-
Notifications
You must be signed in to change notification settings - Fork 16
feat(fe): make container and file upload component for TCManage page #3579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ojongii
wants to merge
6
commits into
main
Choose a base branch
from
t2720-make-container-and-file-upload-component-for-TCManage-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+289
−313
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d459fb
feat(fe): make container and file upload component for TCManage page
fa21110
chore(fe): remove unnecessary styles
5be81a3
chore(fe): remove FileUpload from TcAutoTab and TcOutputTab
01bf392
Merge branch 'main' into t2720-make-container-and-file-upload-compone…
sONg20NOW 316c742
fix(fe): fix uploaded file design
ojongii ad6af10
chore(fe): fix typecheck error
ojongii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 0 additions & 3 deletions
3
apps/frontend/app/(client)/(main)/(create)/problem/create/_components/CheckerPage.tsx
This file was deleted.
Oops, something went wrong.
125 changes: 125 additions & 0 deletions
125
apps/frontend/app/(client)/(main)/(create)/problem/create/_components/FileUpload.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| 'use client' | ||
|
|
||
| import { cn } from '@/libs/utils' | ||
| import InfoIconGray from '@/public/icons/info-icon-gray.svg' | ||
| import TrashIcon from '@/public/icons/trashcan2-gray.svg' | ||
| import { useRef, useState } from 'react' | ||
| import { AiFillFile } from 'react-icons/ai' | ||
| import { TbCode } from 'react-icons/tb' | ||
|
|
||
| interface FileUploadProps { | ||
| primaryText: string | ||
| secondaryText: string | ||
| onFilesChange: (files: File[]) => void | ||
| multiple?: boolean | ||
| className?: string | ||
| } | ||
|
|
||
| function formatFileSize(bytes: number): string { | ||
| if (bytes < 1024) { | ||
| return `${bytes}B` | ||
| } | ||
| if (bytes < 1024 * 1024) { | ||
| return `${(bytes / 1024).toFixed(1)}KB` | ||
| } | ||
| return `${(bytes / (1024 * 1024)).toFixed(1)}MB` | ||
| } | ||
|
|
||
| export function FileUpload({ | ||
| primaryText, | ||
| secondaryText, | ||
| onFilesChange, | ||
| multiple, | ||
| className | ||
| }: FileUploadProps) { | ||
| const [files, setFiles] = useState<File[]>([]) | ||
| const inputRef = useRef<HTMLInputElement | null>(null) | ||
|
|
||
| const handleFiles = (incoming: FileList | null) => { | ||
| if (!incoming) { | ||
| return | ||
| } | ||
| const next = Array.from(incoming) | ||
| setFiles(next) | ||
| onFilesChange(next) | ||
| } | ||
|
|
||
| const removeFile = (index: number) => { | ||
| const next = files.filter((_, i) => i !== index) | ||
| setFiles(next) | ||
| onFilesChange(next) | ||
| } | ||
|
|
||
| return ( | ||
| <div className={cn('flex flex-col gap-2', className)}> | ||
| {files.length > 0 && ( | ||
| <ul className="flex flex-col gap-2"> | ||
| {files.map((f, i) => { | ||
| const isZip = f.name.endsWith('.zip') | ||
| return ( | ||
| <li | ||
| key={`${f.name}-${i}`} | ||
| className="flex items-center justify-between rounded-[12px] px-4 py-3 shadow-[0_4px_20px_0_rgba(53,78,116,0.10)]" | ||
| > | ||
| <div className="flex items-center gap-3"> | ||
| <div className="border-line bg-color-neutral-99 grid size-12 place-items-center rounded-[6.4px] border-[0.8px]"> | ||
| {isZip ? ( | ||
| <TbCode | ||
| size={24} | ||
| className="text-color-cool-neutral-50" | ||
| /> | ||
| ) : ( | ||
| <AiFillFile | ||
| size={24} | ||
| className="text-color-cool-neutral-50" | ||
| /> | ||
| )} | ||
| </div> | ||
| <div className="flex flex-col"> | ||
| <span className="text-sub1_sb_18 mb-[2px]">{f.name}</span> | ||
| <span className="text-sub4_sb_14 text-color-cool-neutral-50"> | ||
| {formatFileSize(f.size)} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| <button | ||
| type="button" | ||
| onClick={() => removeFile(i)} | ||
| className="border-color-neutral-90 bg-color-neutral-99 flex items-center justify-center rounded-full border px-4 py-[10px]" | ||
| > | ||
| <TrashIcon className="h-4 w-4" /> | ||
| </button> | ||
| </li> | ||
| ) | ||
| })} | ||
| </ul> | ||
| )} | ||
| {files.length === 0 && ( | ||
| <div | ||
| onClick={() => inputRef.current?.click()} | ||
| onDragOver={(e) => e.preventDefault()} | ||
| onDrop={(e) => { | ||
| e.preventDefault() | ||
| handleFiles(e.dataTransfer.files) | ||
| }} | ||
| className="bg-color-neutral-99 flex cursor-pointer flex-col items-center justify-center rounded-[12px] py-20" | ||
| > | ||
| <input | ||
| ref={inputRef} | ||
| type="file" | ||
| multiple={multiple} | ||
| className="hidden" | ||
| onChange={(e) => handleFiles(e.target.files)} | ||
| /> | ||
| <div className="flex flex-col items-center gap-[10px]"> | ||
| <InfoIconGray className="mb-2" height={24} width={24} /> | ||
| <div className="text-body1_m_16 text-color-cool-neutral-50 whitespace-pre-wrap text-center"> | ||
| <p>{primaryText}</p> | ||
| <p>{secondaryText}</p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
16 changes: 0 additions & 16 deletions
16
apps/frontend/app/(client)/(main)/(create)/problem/create/_components/GeneratorPage.tsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onDrop을 통해 여러 파일이 한꺼번에 들어올 수 있으므로, multiple 옵션이 false인 경우에는 첫 번째 파일만 선택되도록 로직을 보강하는 것이 안전합니다.