diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-01-30 11:31:24 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-01-30 13:05:48 +0100 |
| commit | 0d4b61993cba37c180ac91e40a0fb362711de8de (patch) | |
| tree | f41dd68420b51766c1ca6fc1ee2c20dc5df830d1 /src/components/BackdropUpload.tsx | |
Initial implementation
Diffstat (limited to 'src/components/BackdropUpload.tsx')
| -rw-r--r-- | src/components/BackdropUpload.tsx | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/components/BackdropUpload.tsx b/src/components/BackdropUpload.tsx new file mode 100644 index 0000000..87fafb1 --- /dev/null +++ b/src/components/BackdropUpload.tsx @@ -0,0 +1,53 @@ +import React, { useRef } from "react"; +import { useStore } from "../store/store.ts"; + +export const BackdropUpload: React.FC = () => { + const backdropUrl = useStore((state) => state.backdropUrl); + const setBackdrop = useStore((state) => state.setBackdrop); + const fileInputRef = useRef<HTMLInputElement>(null); + + const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => { + const file = event.target.files?.[0]; + if (file) { + if (backdropUrl) { + URL.revokeObjectURL(backdropUrl); + } + const url = URL.createObjectURL(file); + setBackdrop(url); + } + }; + + const handleClear = () => { + if (backdropUrl) { + URL.revokeObjectURL(backdropUrl); + } + setBackdrop(null); + if (fileInputRef.current) { + fileInputRef.current.value = ""; + } + }; + + const handleButtonClick = () => { + fileInputRef.current?.click(); + }; + + return ( + <div className="backdrop-upload"> + <input + ref={fileInputRef} + type="file" + accept="image/png,image/jpeg,image/jpg,image/webp,image/gif" + onChange={handleFileChange} + style={{ display: "none" }} + /> + <button className="upload-backdrop" onClick={handleButtonClick}> + {backdropUrl ? "Change Backdrop" : "Upload Backdrop"} + </button> + {backdropUrl && ( + <button className="clear-backdrop" onClick={handleClear}> + Clear + </button> + )} + </div> + ); +}; |