From 78688515a6875d65e27474fe4db1a06b253bc7f1 Mon Sep 17 00:00:00 2001 From: Mikkel RINGAUD Date: Thu, 7 Apr 2022 06:53:18 +0200 Subject: [PATCH] Add launchpad pages --- src/components/ProjectEditor.tsx | 46 +++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/components/ProjectEditor.tsx b/src/components/ProjectEditor.tsx index 21e2e16..ceab969 100644 --- a/src/components/ProjectEditor.tsx +++ b/src/components/ProjectEditor.tsx @@ -30,14 +30,30 @@ export default function ProjectEditor ({ /** Index of the current used launchpad. */ const [currentLaunchpadSelected, setCurrentLaunchpadSelected] = useState(null); const handleLaunchpadSelection = (evt: ChangeEvent) => { + // Reset the page selector. + setCurrentLaunchpadPageSelected(null); + const index = evt.target.value; if (index === "none") { setCurrentLaunchpadSelected(null); return; } - + setCurrentLaunchpadSelected(parseInt(index)); }; + + /** Index of the current page used in current launchpad. */ + const [currentLaunchpadPageSelected, setCurrentLaunchpadPageSelected] = useState(null); + const handleLaunchpadPageSelection = (evt: ChangeEvent) => { + const index = evt.target.value; + if (index === "none") { + setCurrentLaunchpadPageSelected(null); + return; + } + + setCurrentLaunchpadPageSelected(parseInt(index)); + }; + const addLaunchpad = () => { const data_copy = { ...data }; @@ -61,6 +77,18 @@ export default function ProjectEditor ({ saveProjectLocally(data_copy); }; + const addLaunchpadPage = () => { + if (currentLaunchpadSelected === null) return; + const data_copy = { ...data }; + + // Add a new page to the current launchpad. + const index = data_copy.launchpads[currentLaunchpadSelected].pages.length + 1; + const name = `Page ${index}`; + data_copy.launchpads[currentLaunchpadSelected].pages.push({ name, samples: [] }); + + saveProjectLocally(data_copy); + }; + return (
@@ -96,6 +124,22 @@ export default function ProjectEditor ({ + + + +
}