From b811678062c49868b5cb93544e6a42abf0a538f3 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Sat, 9 Apr 2022 16:18:24 +0000 Subject: [PATCH] feat: add upload audio modal --- src/components/DiscRow.tsx | 9 +++++- src/components/UploadAudioModal.css | 6 ++++ src/components/UploadAudioModal.tsx | 47 +++++++++++++++++++++++++++++ src/store/discs.ts | 7 ++++- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/components/UploadAudioModal.css create mode 100644 src/components/UploadAudioModal.tsx diff --git a/src/components/DiscRow.tsx b/src/components/DiscRow.tsx index 6d4b513..9bc88e2 100644 --- a/src/components/DiscRow.tsx +++ b/src/components/DiscRow.tsx @@ -8,6 +8,7 @@ import { setDescription, setTitle } from "../store/discs" import { useState } from "react" import "./DiscRow.css" +import UploadAudioModal from "./UploadAudioModal" interface DiscRowProps { discId: number @@ -18,6 +19,7 @@ function DiscRow({ discId }: DiscRowProps) { const disc = discs.discs[discId] const [showEditName, setShowEditName] = useState(false); + const [showUploadAudio, setShowUploadAudio] = useState(false); const dispatch = useAppDispatch() function onReset() { @@ -33,7 +35,7 @@ function DiscRow({ discId }: DiscRowProps) { -
@@ -49,6 +51,11 @@ function DiscRow({ discId }: DiscRowProps) { onClose={() => setShowEditName(false)} discId={discId} /> + setShowUploadAudio(false)} + discId={discId} + />
) } diff --git a/src/components/UploadAudioModal.css b/src/components/UploadAudioModal.css new file mode 100644 index 0000000..827e01a --- /dev/null +++ b/src/components/UploadAudioModal.css @@ -0,0 +1,6 @@ +.checkbox-group { + display: flex; + flex-direction: row; + align-items: center; + margin-top: 1rem; +} diff --git a/src/components/UploadAudioModal.tsx b/src/components/UploadAudioModal.tsx new file mode 100644 index 0000000..06e9c1f --- /dev/null +++ b/src/components/UploadAudioModal.tsx @@ -0,0 +1,47 @@ +import { selectDiscs, useAppDispatch, useAppSelector } from "../store" +import { setAudioUrl } from "../store/discs" +import { useState } from "react" +import Modal from "./Modal" +import "./UploadAudioModal.css" + +interface UploadAudioModalProps { + discId: number + show: boolean + onClose: { (): void } +} + +function UploadAudioModal({ discId, show, onClose }: UploadAudioModalProps) { + const discs = useAppSelector(selectDiscs) + const disc = discs.discs[discId] + + const [url, setUrl] = useState(""); + const [updateDescription, setUpdateDescription] = useState(true); + + const dispatch = useAppDispatch() + async function onModalClose() { + onClose() + dispatch(setAudioUrl({ + id: discId, + audioUrl: url + })) + } + + return + + setUrl(e.target.value)} + type="text" + value={url} + /> +
+ + setUpdateDescription(e.target.checked)} + type="checkbox" + checked={updateDescription} + /> +
+
+} + +export default UploadAudioModal diff --git a/src/store/discs.ts b/src/store/discs.ts index c318faf..b1a776c 100644 --- a/src/store/discs.ts +++ b/src/store/discs.ts @@ -3,6 +3,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit' export interface Disc { title?: string description?: string + audioUrl?: string defaultTitle: string defaultDescription: string icon: string @@ -86,10 +87,14 @@ export const discsSlice = createSlice({ setDescription: (state, action: PayloadAction<{ id: number, description: string }>) => { const { id, description } = action.payload; state.discs[id].description = description + }, + setAudioUrl: (state, action: PayloadAction<{ id: number, audioUrl: string }>) => { + const { id, audioUrl } = action.payload; + state.discs[id].audioUrl = audioUrl } } }) -export const { setTitle, setDescription } = discsSlice.actions +export const { setTitle, setDescription, setAudioUrl } = discsSlice.actions export default discsSlice.reducer