diff --git a/bun.lockb b/bun.lockb index eb74852..a987da2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 5872e64..5b2ba76 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@emotion/styled": "^11.14.0", "@mui/icons-material": "^6.3.1", "@mui/material": "^6.3.1", + "html2canvas": "^1.4.1", "react": "^18.3.1", "react-dom": "^18.3.1", "zustand": "^5.0.3" diff --git a/src/App.tsx b/src/App.tsx index 8fca888..bdd2da5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,6 @@ import { DndContext, DragEndEvent } from '@dnd-kit/core'; import { GitHub } from '@mui/icons-material'; +import html2canvas from 'html2canvas'; import { useRef } from 'react'; import { useShallow } from 'zustand/shallow'; import './App.scss'; @@ -15,6 +16,8 @@ const App = () => { useShallow(state => [state.images, state.addTierImage, state.tierLevels, state.editTierImage]), ); + const tierListRef = useRef(null); + const uploadBtn = useRef(null); const clickUpload = () => { @@ -35,13 +38,32 @@ const App = () => { } }; + const handleDownloadImage = async () => { + if (!tierListRef.current) return; + const el = tierListRef.current; + const canvas = await html2canvas(el); + + const data = canvas.toDataURL('image/png', 1.0); + const link = document.createElement('a'); + + if (typeof link.download === 'string') { + link.href = data; + link.download = 'tierlist.png'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } else { + window.open(data); + } + }; + return (
NwTierList
-
+
{tierLevels.map(tier_level => ( { ))}
)} -
- Add photo - { - console.log(event.target.files); - if (event.target.files) { - const upload_images: tierImage[] = []; - for (let i = 0; i < event.target.files.length; i++) { - const url = URL.createObjectURL(event.target.files[i]); - upload_images.push({ - url: url, - name: event.target.files[i].name.replace('.jpeg', ''), - category: '', - }); - } - handleAdd(upload_images); - } - }} - /> -
+
+ Add photo + { + console.log(event.target.files); + if (event.target.files) { + const upload_images: tierImage[] = []; + for (let i = 0; i < event.target.files.length; i++) { + const url = URL.createObjectURL(event.target.files[i]); + upload_images.push({ + url: url, + name: event.target.files[i].name.replace('.jpeg', ''), + category: '', + }); + } + handleAdd(upload_images); + } + }} + /> +
+
+ Export as PNG +
-
+
{tierImages .filter(image => image.category === name) .map((image, index) => (