-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64b70e6
commit 556543b
Showing
12 changed files
with
139 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,36 @@ | ||
import { useState } from 'react'; | ||
import axios from 'axios'; | ||
import useGetWorkbookList from 'hooks/@query/workbook/useGetWorkbookList'; | ||
|
||
const WorkbookImageUpload = () => { | ||
const [selectedFile, setSelectedFile] = useState(null); | ||
const [uploading, setUploading] = useState(false); | ||
|
||
const handleFileChange = (e: any) => { | ||
setSelectedFile(e.target.files[0]); | ||
}; | ||
const workbookList = useGetWorkbookList({ title: '', description: '' }); | ||
console.log(workbookList); | ||
const lastWorkbook = workbookList?.content[workbookList?.content.length - 1]; | ||
const newId = lastWorkbook ? lastWorkbook.id + 1 : 1; | ||
console.log(newId); | ||
|
||
const handleUpload = () => { | ||
if (!selectedFile) return; | ||
|
||
setUploading(true); | ||
|
||
const formData = new FormData(); | ||
formData.append('file', selectedFile); | ||
}; | ||
return ( | ||
<div> | ||
<input type="file" onChange={handleFileChange} /> | ||
<button onClick={handleUpload} disabled={!selectedFile || uploading}> | ||
Upload Image | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default WorkbookImageUpload; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,29 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { updateWorkbook } from 'api/workbook'; | ||
|
||
interface UpdateWorkbookProps { | ||
handleIsLoading: (isLoading: boolean) => void; | ||
handleIsActive: (isActive: boolean) => void; | ||
} | ||
|
||
export const useUploadWorkbook = ({ | ||
handleIsLoading, | ||
handleIsActive, | ||
}: UpdateWorkbookProps) => { | ||
const queryClient = useQueryClient(); | ||
const { mutate: UpdateWorkbook } = useMutation(updateWorkbook, { | ||
onSuccess: () => { | ||
alert('문제집 정보 수정에 성공했습니다.'); | ||
queryClient.invalidateQueries(['workbook']); | ||
}, | ||
onError: () => { | ||
alert('문제집 정보 수정에 실패했습니다.'); | ||
}, | ||
onSettled: () => { | ||
handleIsActive(false); | ||
handleIsLoading(false); | ||
}, | ||
}); | ||
|
||
return UpdateWorkbook; | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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