-
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
Showing
9 changed files
with
208 additions
and
154 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
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 |
---|---|---|
@@ -1,22 +1,85 @@ | ||
import React from "react"; | ||
"use client"; | ||
import React, { ChangeEvent, useState } from "react"; | ||
import { BlockType, useBlock } from "@/hooks/toggle"; | ||
import Image from "next/image"; | ||
|
||
export default function BlockDisplayCard() { | ||
interface UploaderProps { | ||
blockType: BlockType; | ||
} | ||
|
||
const Uploader = ({ blockType }: UploaderProps) => { | ||
const { updateFiles } = useBlock(); | ||
const [selectedFile, setSelectedFile] = useState<File | null>(null); | ||
function handleFileChange(event: ChangeEvent<HTMLInputElement>) { | ||
const file = event.target.files?.[0]; | ||
if (file) { | ||
const fileUrl = URL.createObjectURL(file); | ||
updateFiles(blockType, [fileUrl]); | ||
} | ||
} | ||
return ( | ||
<div className="relative w-full h-96 mx-auto max-w-5xl border-2 rounded-lg p-4 border-pink-500"> | ||
<div className="relative w-full h-96 mx-auto max-w-5xl border-2 rounded-lg p-4 border-pink-500"> | ||
<label | ||
htmlFor="dropzone-file" | ||
htmlFor={`${blockType}-file`} | ||
className="relative p-3 bg-gray-200 flex flex-col justify-center w-full max-w-5xl mx-auto h-full rounded-lg border-gray-300 cursor-pointer" | ||
> | ||
<div className="z-30 flex flex-col items-center justify-center pt-5 pb-6 space-y-8"> | ||
<div className="flex flex-col text-base items-center justify-center space-y-3"> | ||
<p className="mb-2"> | ||
Drag and drop media, or | ||
Drag and drop {blockType}, or | ||
<span className="border-b border-black mx-1">Browse</span> | ||
</p> | ||
</div> | ||
</div> | ||
</label> | ||
<input id="dropzone-file" type="file" className="hidden" /> | ||
<input | ||
id={`${blockType}-file`} | ||
type="file" | ||
className="hidden" | ||
onChange={handleFileChange} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default function BlockDisplayCard() { | ||
const { boardData, onOpenBlock, setDrawerOpen } = useBlock(); | ||
|
||
const handleFileClick = (blockKey: BlockType) => { | ||
onOpenBlock(blockKey); | ||
setDrawerOpen(true); | ||
}; | ||
|
||
return ( | ||
<div className="w-full space-y-6"> | ||
{Object.keys(boardData).map((blockKey) => { | ||
const block = boardData[blockKey as BlockType]; | ||
if (typeof block === "object" && block !== null && "files" in block) { | ||
return block.files.length > 0 ? ( | ||
block.files.map((file, index) => ( | ||
<div | ||
onClick={() => handleFileClick(blockKey as BlockType)} | ||
className="relative w-full h-screen mx-auto max-w-5xl border-2 rounded-lg p-4 border-pink-500" | ||
> | ||
<Image | ||
key={`${blockKey}-${index}`} | ||
src={file} | ||
alt={blockKey} | ||
fill | ||
className="w-96 h-96" | ||
/> | ||
</div> | ||
)) | ||
) : ( | ||
<div | ||
onClick={() => handleFileClick(blockKey as BlockType)} | ||
className="relative w-full h-screen mx-auto max-w-5xl border-2 rounded-lg p-4 border-pink-500" | ||
> | ||
<Uploader blockType={blockKey as BlockType} /> | ||
</div> | ||
); | ||
} | ||
})} | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,23 +1,40 @@ | ||
import React from "react"; | ||
|
||
export default function MediaUpload() { | ||
interface MediaUploadProps { | ||
mediaType: "image" | "video"; | ||
mediaSrcUrl: string; | ||
} | ||
|
||
export default function MediaUpload({ | ||
mediaType, | ||
mediaSrcUrl, | ||
}: MediaUploadProps) { | ||
return ( | ||
<div> | ||
<label htmlFor="file" className="block font-medium my-3 py-2 pt-4"> | ||
Media | ||
</label> | ||
<div className="flex flex-col items-center w-full bg-gray-100 max-w-lg p-5 mx-auto text-center border cursor-pointer rounded-lg"> | ||
{mediaType === "image" ? ( | ||
<img src={mediaSrcUrl} /> | ||
) : ( | ||
<video src={mediaSrcUrl} /> | ||
)} | ||
</div> | ||
|
||
<label | ||
htmlFor="dropzone-file" | ||
className="flex flex-col items-center w-full bg-gray-100 max-w-lg p-5 mx-auto text-center border cursor-pointer rounded-lg" | ||
> | ||
<div className="py-2 px-5 me-2 w-11/12 my-2 font-medium text-sm focus:outline-none bg-white rounded-full border border-gray-200"> | ||
Select media | ||
</div> | ||
{!mediaSrcUrl && ( | ||
<label | ||
htmlFor="dropzone-file" | ||
className="flex flex-col items-center w-full bg-gray-100 max-w-lg p-5 mx-auto text-center border cursor-pointer rounded-lg" | ||
> | ||
<div className="py-2 px-5 me-2 w-11/12 my-2 font-medium text-sm focus:outline-none bg-white rounded-full border border-gray-200"> | ||
Select media | ||
</div> | ||
|
||
<p className="text-sm text-gray-500">or drop media to upload</p> | ||
<input id="dropzone-file" type="file" className="hidden" /> | ||
</label> | ||
<p className="text-sm text-gray-500">or drop media to upload</p> | ||
<input id="dropzone-file" type="file" className="hidden" /> | ||
</label> | ||
)} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.