Skip to content

Commit

Permalink
fix(ProjectEditor): Use an object instead of an array for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Apr 22, 2022
1 parent 8b2fc88 commit 110d8c9
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 54 deletions.
33 changes: 33 additions & 0 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
interface ButtonProps {
children: React.ReactNode;
onClick: React.MouseEventHandler<HTMLButtonElement>;
title?: string;

className?: string;
}

export default function Button ({
children,
onClick,
title,

className
}: ButtonProps) {
return (
<button
className={`
whitespace-nowrap px-4 py-2 rounded-lg
text-gray-300 flex justify-center items-center
bg-gray-900 bg-opacity-20
border border-gray-900
transition-all
${className ? className : ""}
`}

onClick={onClick}
title={title}
>
{children}
</button>
);
}
49 changes: 14 additions & 35 deletions src/components/ProjectEditor/CardEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { ProjectData, ProjectDataSample } from "@/types/Project";
import type { ProjectData } from "@/types/Project";
import type { ChangeEvent } from "react";

// Stores
import { useUnsavedProjectStore } from "@/stores/unsaved_project";

// Components
import Button from "@/components/Button";
import Select from "@/components/Select";
import Input from "@/components/Input";
import { Fragment } from "react";
Expand Down Expand Up @@ -84,21 +85,14 @@ export default function CardEditor ({
)}
</Select>

<button
className="
whitespace-nowrap px-4 py-2 rounded-lg
text-gray-300
hover:bg-blue-600
bg-gray-900 bg-opacity-20
border border-gray-900 hover:border-blue-500
transition-all
"
<Button
className="hover:bg-blue-600 hover:border-blue-500"

onClick={addToSelector}
title={`Add a ${type} to the project`}
>
<HiOutlinePlus size={18} />
</button>
</Button>
</div>

{children}
Expand All @@ -110,49 +104,34 @@ export default function CardEditor ({
? (
<Fragment>
{target.id !== 0 && (
<button
className="
px-4 py-2 rounded-lg w-full flex justify-center
text-gray-300 hover:text-blue-600
bg-gray-900 bg-opacity-20 hover:bg-opacity-60
border border-gray-900 hover:border-blue-600
"
<Button
className="hover:bg-blue-600 hover:border-blue-500 w-full"

title={`Move the current ${type} up`}
onClick={upItem}
>
<HiArrowUp size={18} />
</button>
</Button>
)}

<button
className="
px-4 py-2 rounded-lg w-full flex justify-center
text-gray-300 hover:text-pink-600
bg-gray-900 bg-opacity-20 hover:bg-opacity-60
border border-gray-900 hover:border-pink-600
"
<Button
className="hover:text-pink-600 hover:border-pink-600 w-full"

title={`Remove the current ${type}`}
onClick={removeFromSelector}
>
<HiOutlineTrash size={18} />
</button>
</Button>

{launchpad && target.id !== ((type === "launchpad" ? data.launchpads : launchpad.pages).length - 1) && (
<button
className="
px-4 py-2 rounded-lg w-full flex justify-center
text-gray-300 hover:text-blue-600
bg-gray-900 bg-opacity-20 hover:bg-opacity-60
border border-gray-900 hover:border-blue-600
"
<Button
className="hover:bg-blue-600 hover:border-blue-500 w-full"

title={`Move the current ${type} down`}
onClick={downItem}
>
<HiArrowDown size={18} />
</button>
</Button>
)}
</Fragment>
)
Expand Down
8 changes: 7 additions & 1 deletion src/components/ProjectEditor/LaunchpadPageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ export default function LaunchpadPageEditor ({
downItem={downLaunchpadPage}
>

<div className="w-full aspect-square bg-gray-400">
<div className="
w-full aspect-square rounded-md
bg-gray-400 bg-opacity-20
border border-gray-400
flex justify-center items-center
">

</div>
</CardEditor>
Expand Down
27 changes: 9 additions & 18 deletions src/components/ProjectEditor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import type {
ProjectDataSample
} from "@/types/Project";

import {
ChangeEvent,
useState
Expand All @@ -14,6 +10,7 @@ import { useUnsavedProjectStore } from "@/stores/unsaved_project";
// ProjectEditor's components
import LaunchpadEditor from "./LaunchpadEditor";
import LaunchpadPageEditor from "./LaunchpadPageEditor";
import LaunchpadSampleEditor from "./LaunchpadSampleEditor";

export default function ProjectEditor () {
const log = logger("/:slug~ProjectEditor");
Expand Down Expand Up @@ -112,7 +109,7 @@ export default function ProjectEditor () {
// Add a new page to the current launchpad.
const index = data_copy.launchpads[currentLaunchpadSelected].pages.length;
const name = `Page ${index}`;
data_copy.launchpads[currentLaunchpadSelected].pages.push({ name, samples: [] });
data_copy.launchpads[currentLaunchpadSelected].pages.push({ name, samples: {} });

setData(data_copy);
setCurrentPadSelected(undefined);
Expand Down Expand Up @@ -166,12 +163,13 @@ export default function ProjectEditor () {
/** Short-hand for `currentPadSelected` with data. */
const sample = (launchpad && page && typeof currentPadSelected !== "undefined") ? {
...page.samples[currentPadSelected],
id: currentPadSelected
id: currentPadSelected,
isAssigned: !! page.samples[currentPadSelected]
} : null;

return (
<div>
<div className="flex flex-row flex-wrap gap-4">
<div className="flex flex-row flex-wrap gap-4 mb-4">
<LaunchpadEditor
setCurrentLaunchpadSelected={setCurrentLaunchpadSelected}
handleLaunchpadSelection={handleLaunchpadSelection}
Expand All @@ -197,21 +195,14 @@ export default function ProjectEditor () {
)}
</div>

{sample && (
<PadEditor
{launchpad && sample && page && (
<LaunchpadSampleEditor
page={page}
sample={sample}
launchpad={launchpad}
/>
)}
</div>
);
}

const PadEditor = ({ sample }: { sample: ProjectDataSample & { id: number } }) => {
return (
<div>
<p>
Viewing sample from note {sample.id}
</p>
</div>
);
};

0 comments on commit 110d8c9

Please sign in to comment.