diff --git a/client/src/App.test.tsx b/client/src/App.test.tsx deleted file mode 100644 index 2a68616..0000000 --- a/client/src/App.test.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react'; -import { render, screen } from '@testing-library/react'; -import App from './App'; - -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/client/src/App.tsx b/client/src/App.tsx index 8530d96..c2a219c 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,23 +1,70 @@ -import React from 'react'; +import React, { useState } from 'react'; import './App.css'; -import DiscRow from './components/DiscRow'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { selectDiscs, useAppSelector } from "./store" import { solid } from '@fortawesome/fontawesome-svg-core/import.macro' -import { selectDiscs, useAppSelector } from './store'; +import ResourcePackCustomizer from './components/ResourcePackCustomizer'; +import { CreatePackPayload, createPack, Disc } from './api'; + +// TODO: Add waiting icon while creation is taking place function App() { - const discs = useAppSelector(selectDiscs) + const [description, setDescription] = useState("") + + const store = useAppSelector(selectDiscs) + async function onClick() { + const discs: Record = {} + for (var disc of store.discs) { + if (disc.title || disc.description || disc.youtubeUrl) { + const payloadDisc: Disc = {} + if (disc.title) { + payloadDisc.title = disc.title + } + if (disc.description) { + payloadDisc.description = disc.description + } + if (disc.youtubeUrl) { + payloadDisc.youtubeUrl = disc.youtubeUrl + } + discs[disc.resourceName] = payloadDisc + } + } + + const info: CreatePackPayload = { discs } + if (description.length > 0) { + info.description = description + } + + const blob = await createPack(info) + if (blob) { + downloadBlob(blob, "music-pack.zip") + } + } + + function downloadBlob(blob: Blob, filename: string) { + const url = window.URL.createObjectURL(new Blob([blob])) + const link = document.createElement("a") + link.href = url + link.setAttribute("download", filename) + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + } return (
-
- { discs.discs.map((disc, idx) => { return }) } +
+