From 7e40aa188979311e706154dfcf52e47975f99cde Mon Sep 17 00:00:00 2001 From: Elad Rosenheim Date: Tue, 23 Apr 2024 17:55:24 +0300 Subject: Revalidation & Blobs pages, tweaks (#8) * added blobs.astro page * updated blobs * updated index.astro and npm dependencies * updated api blobs * Revalidation example WIP * Revalidation by tag example * Update revalidation.astro * Image CDN fixes * Text fixes * updated colors (#9) * updated colors * updated README.md * updated Layout.astro bg color * updated template colors * Inline Inter font * Inline noise.png * Remove remaining "Astro.js" --------- Co-authored-by: TomasBankauskas --- src/pages/blobs/_components/NewShape.tsx | 60 +++++++++++++++++++++ src/pages/blobs/_components/ShapeEditor.tsx | 18 +++++++ src/pages/blobs/_components/ShapePreview.tsx | 19 +++++++ src/pages/blobs/_components/StoredShapes.tsx | 78 ++++++++++++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 src/pages/blobs/_components/NewShape.tsx create mode 100644 src/pages/blobs/_components/ShapeEditor.tsx create mode 100644 src/pages/blobs/_components/ShapePreview.tsx create mode 100644 src/pages/blobs/_components/StoredShapes.tsx (limited to 'src/pages/blobs/_components') diff --git a/src/pages/blobs/_components/NewShape.tsx b/src/pages/blobs/_components/NewShape.tsx new file mode 100644 index 0000000..05f9e6f --- /dev/null +++ b/src/pages/blobs/_components/NewShape.tsx @@ -0,0 +1,60 @@ +import { useState, useEffect } from 'react'; +import type { Dispatch, SetStateAction } from 'react'; +import ShapePreview from './ShapePreview.tsx'; +import { generateBlob } from '../../../utils'; +import type { BlobProps } from '../../../types.ts'; + +interface Props { + setLastMutationTime?: Dispatch>; +} + +export default function NewShape(props: Props) { + const { setLastMutationTime } = props; + const [blobData, setBlobData] = useState(); + const [wasUploaded, setWasUploaded] = useState(false); + + const randomizeBlob = () => { + setBlobData(generateBlob()); + setWasUploaded(false); + }; + + const uploadBlob = async () => { + const response = await fetch('/api/blobs', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(blobData.parameters) + }); + const data = await response.json(); + if (data.message) { + console.log(data.message); + } + setWasUploaded(true); + setLastMutationTime(Date.now()); + }; + + useEffect(() => { + if (!blobData) { + randomizeBlob(); + } + }, [blobData]); + + return ( + <> +

New Random Shape

+
+
+ {blobData && {blobData.parameters?.name}} +
+
{blobData && }
+
+
+ + +
+ + ); +} diff --git a/src/pages/blobs/_components/ShapeEditor.tsx b/src/pages/blobs/_components/ShapeEditor.tsx new file mode 100644 index 0000000..9a339cc --- /dev/null +++ b/src/pages/blobs/_components/ShapeEditor.tsx @@ -0,0 +1,18 @@ +import { useState } from 'react'; +import NewShape from './NewShape.tsx'; +import StoredShapes from './StoredShapes.tsx'; + +export default function ShapeEditor() { + const [lastMutationTime, setLastMutationTime] = useState(null); + + return ( +
+
+ +
+
+ +
+
+ ); +} diff --git a/src/pages/blobs/_components/ShapePreview.tsx b/src/pages/blobs/_components/ShapePreview.tsx new file mode 100644 index 0000000..a00d2bc --- /dev/null +++ b/src/pages/blobs/_components/ShapePreview.tsx @@ -0,0 +1,19 @@ +import { randomInt } from '../../../utils.ts'; +import type { BlobProps } from '../../../types.ts'; + +export default function ShapePreview(props: BlobProps) { + const { svgPath, parameters } = props; + const gradientId = `gradient-${randomInt(10_000_000, 100_000_000)}`; + + return ( + + + + + + + + + + ); +} diff --git a/src/pages/blobs/_components/StoredShapes.tsx b/src/pages/blobs/_components/StoredShapes.tsx new file mode 100644 index 0000000..e870ef5 --- /dev/null +++ b/src/pages/blobs/_components/StoredShapes.tsx @@ -0,0 +1,78 @@ +import { useState, useEffect } from 'react'; +import ShapePreview from './ShapePreview.tsx'; +import { generateBlob } from '../../../utils'; +import type { BlobProps } from '../../../types.ts'; + +interface Props { + lastMutationTime: number; +} + +export default function StoredShapes(props: Props) { + const { lastMutationTime } = props; + const [keys, setKeys] = useState([]); + const [selectedKey, setSelectedKey] = useState(null); + const [previewData, setPreviewData] = useState(null); + + const getBlobKeyList = async () => { + console.log('Fetching keys...'); + const response = await fetch('/api/blobs', { + method: 'GET', + headers: { 'Content-Type': 'application/json' } + }); + const data = await response.json(); + if (data.keys) { + setKeys(data.keys); + } + }; + + const getBlobByKey = async (key: string) => { + setSelectedKey(key); + const params = new URLSearchParams({ key }); + const response = await fetch(`/api/blob/?${params}`, { + method: 'GET' + }); + const data = await response.json(); + if (data.blob) { + setPreviewData(generateBlob(data.blob)); + } + }; + + useEffect(() => { + getBlobKeyList(); + }, [lastMutationTime]); + + return ( + <> +

Objects in Blob Store

+
+
+ {keys?.length ? ( +
+ {keys.map((keyName) => ( + + ))} +
+ ) : ( + Please upload some shapes! + )} +
+ {previewData && ( +
+ +
+ )} +
+ + ); +} -- cgit v1.2.3