diff --git a/pages/sticker-map.tsx b/pages/sticker-map/index.tsx similarity index 76% rename from pages/sticker-map.tsx rename to pages/sticker-map/index.tsx index 78f1622..0eef680 100644 --- a/pages/sticker-map.tsx +++ b/pages/sticker-map/index.tsx @@ -1,8 +1,10 @@ /* eslint-disable @next/next/no-img-element */ import { type FilePondFile } from "filepond"; +import { useRouter } from "next/router"; import { PropsWithChildren, useState } from "react"; import { FilePond } from "react-filepond"; +import { Button } from "@/common/components/Button"; import { Icon } from "@/common/components/CustomIcon"; import { Footer } from "@/common/components/Footer"; import { Input } from "@/common/components/Input"; @@ -11,9 +13,10 @@ import { cn } from "@/common/functions"; import "filepond/dist/filepond.min.css"; export const StickerMap = () => { + const router = useRouter(); const [files, setFiles] = useState([]); - const [imageSize, setImageSize] = useState(46); + const [imageSize, setImageSize] = useState(51); const [blackBorderSize, setBlackBorderSize] = useState(1); const [whiteBorderSize, setWhiteBorderSize] = useState(2); @@ -21,6 +24,18 @@ export const StickerMap = () => { setFiles(items.map((item) => item.file)); }; + const handleNavigateToPrint = () => { + router.push({ + pathname: "/sticker-map/print", + query: { + imageSize, + blackBorderSize, + whiteBorderSize, + files: files.map((file) => URL.createObjectURL(file)), + }, + }); + }; + return (
@@ -38,6 +53,7 @@ export const StickerMap = () => { }} id="image-size" label="Image Size" + min={0} placeholder="in mm" rightContent={mm} type="number" @@ -51,6 +67,7 @@ export const StickerMap = () => { }} id="black-border-size" label="Black Border Size" + min={0} placeholder="in mm" rightContent={x2 mm} type="number" @@ -64,6 +81,7 @@ export const StickerMap = () => { }} id="white-border-size" label="White Border Size" + min={0} placeholder="in mm" rightContent={x2 mm} type="number" @@ -72,7 +90,7 @@ export const StickerMap = () => { onChange={(e) => setWhiteBorderSize(e.target.valueAsNumber)} />
- {`LENGTH ${imageSize + blackBorderSize * 2 + whiteBorderSize * 2}mm (${Math.round(((imageSize + blackBorderSize * 2 + whiteBorderSize * 2) / 25.4) * 100) / 100}inch)`} + {`LENGTH ${imageSize}mm (${Math.round((imageSize / 25.4) * 100) / 100}inch)`} 25.4mm/inch @@ -82,19 +100,21 @@ export const StickerMap = () => {
{files.length > 0 ? ( files.map((file, index) => ( -
+
{`sticker-${index}`}
)) @@ -110,6 +130,10 @@ export const StickerMap = () => {
)}
+
+
+ +
); }; diff --git a/pages/sticker-map/print.tsx b/pages/sticker-map/print.tsx new file mode 100644 index 0000000..f47a712 --- /dev/null +++ b/pages/sticker-map/print.tsx @@ -0,0 +1,105 @@ +/* eslint-disable @next/next/no-img-element */ +import { useRouter } from "next/router"; +import { PropsWithChildren, useState } from "react"; + +import { Button } from "@/common/components/Button"; +import { cn } from "@/common/functions"; + +export const PrintPage = () => { + const [extraImage, setExtraImage] = useState([]); + + const { query } = useRouter(); + const { imageSize, blackBorderSize, whiteBorderSize, files } = query as { + imageSize: string; + blackBorderSize: string; + whiteBorderSize: string; + files: string[]; + }; + + if (!files || !imageSize || !blackBorderSize || !whiteBorderSize) { + return ( + + missing something. go back! + + ); + } + + const parentWidth = 210; + const parentHeight = 297; + const childSize = imageSize || "1"; + + const columns = Math.floor(parentWidth / Number(childSize)); + const rows = Math.floor(parentHeight / Number(childSize)); + + const imageCount = columns * rows; + + const countPerImage = imageCount / files.length; + + const renderImage = (file: string) => ( +
+
+ sticker +
+
+ ); + + return ( +
+
+
+ {files.length > 0 && + files.map((file) => + Array.from({ length: countPerImage }).map((_, index) => + renderImage(file), + ), + )} + {extraImage.length > 0 && extraImage.map((file) => renderImage(file))} +
+
+
+
+ + +
+ + The white space above is the A4 paper. + +
+
+ ); +}; + +PrintPage.layout = ({ children }: PropsWithChildren) => ( +
{children}
+); + +export default PrintPage;