Skip to content

Commit

Permalink
Simplify the router id 🪪.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarty committed Jun 4, 2024
1 parent 750ea3d commit 384c8fb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
35 changes: 16 additions & 19 deletions src/containers/GfxContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import ResourceMetadata from '../components/ResourceMetadata';
import GfxCanvasContainer from './GfxCanvasContainer';

const GfxContainer = ({ titlegfx, costumegfx, roomgfx }) => {
const isTitleGfx = !!useMatch('/titlegfx/:gfcId');
const isCostumeGfx = !!useMatch('/costumegfx/:gfcId');
const isRoomGfx = !!useMatch('/roomgfx/:gfcId');
const { gfcId } = useParams();
const isTitleGfx = !!useMatch('/titlegfx/:id');
const isCostumeGfx = !!useMatch('/costumegfx/:id');
const isRoomGfx = !!useMatch('/roomgfx/:id');
const { id } = useParams();

const currentGfcId =
typeof gfcId === 'undefined' ? null : parseInt(gfcId, 10);
const currentId = typeof id === 'undefined' ? null : parseInt(id, 10);
const gfc = isTitleGfx
? titlegfx[currentGfcId]
? titlegfx[currentId]
: isCostumeGfx
? costumegfx[currentGfcId]
: roomgfx[currentGfcId];
? costumegfx[currentId]
: roomgfx[currentId];

if (!gfc) {
return null;
Expand All @@ -31,31 +30,29 @@ const GfxContainer = ({ titlegfx, costumegfx, roomgfx }) => {
<PrimaryColumn>
<TitleGfxList
gfx={titlegfx}
currentId={isTitleGfx ? currentGfcId : null}
currentId={isTitleGfx ? currentId : null}
/>
<CostumeGfxList
gfx={costumegfx}
currentId={isCostumeGfx ? currentGfcId : null}
currentId={isCostumeGfx ? currentId : null}
/>
<RoomGfxList
gfx={roomgfx}
currentId={isRoomGfx ? currentGfcId : null}
currentId={isRoomGfx ? currentId : null}
/>
</PrimaryColumn>
<Main>
<MainHeader
title={
currentGfcId === null
currentId === null
? 'Graphics'
: isTitleGfx
? `Title graphics tileset ${currentGfcId}`
? `Title graphics tileset ${currentId}`
: isCostumeGfx
? `Costume graphics tileset ${currentGfcId}`
: `Room graphics tileset ${currentGfcId}`
? `Costume graphics tileset ${currentId}`
: `Room graphics tileset ${currentId}`
}>
{currentGfcId !== null && (
<ResourceMetadata metadata={gfc.metadata} />
)}
{currentId !== null && <ResourceMetadata metadata={gfc.metadata} />}
</MainHeader>
<GfxCanvasContainer
gfx={gfc.gfx}
Expand Down
8 changes: 4 additions & 4 deletions src/containers/ResourceExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const ResourceExplorer = () => {
/>
}>
<Route
path=":gfcId"
path=":id"
element={
<GfxContainer
titlegfx={resources.titles}
Expand All @@ -87,7 +87,7 @@ const ResourceExplorer = () => {
/>
}>
<Route
path=":gfcId"
path=":id"
element={
<GfxContainer
titlegfx={resources.titles}
Expand All @@ -107,7 +107,7 @@ const ResourceExplorer = () => {
/>
}>
<Route
path=":gfcId"
path=":id"
element={
<GfxContainer
titlegfx={resources.titles}
Expand All @@ -130,7 +130,7 @@ const ResourceExplorer = () => {
path="/scripts"
element={<ScriptContainer scripts={resources.scripts} />}>
<Route
path=":scriptId"
path=":id"
element={<ScriptContainer scripts={resources.scripts} />}
/>
</Route>
Expand Down
4 changes: 3 additions & 1 deletion src/containers/RoomsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const RoomsContainer = ({ rooms, titles, roomgfx, globdata }) => {

const currentId = typeof id === 'undefined' ? null : parseInt(id, 10);
const baseTiles = roomgfx?.find(({ metadata }) => metadata.id === 0);
let roomgfc = roomgfx?.find(({ metadata }) => metadata.id === room?.tileset);
const roomgfc = roomgfx?.find(
({ metadata }) => metadata.id === room?.tileset,
);

useEffect(() => {
const room =
Expand Down
10 changes: 4 additions & 6 deletions src/containers/ScriptContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ import ScriptsList from '../components/ScriptsList';
import Script from '../components/Script';

const ScriptContainer = ({ scripts }) => {
const { scriptId } = useParams();

const currentScriptId =
typeof scriptId === 'undefined' ? null : parseInt(scriptId, 10);
const { id } = useParams();

const currentId = typeof id === 'undefined' ? null : parseInt(id, 10);
const script =
scripts.find(({ metadata }) => metadata.id === currentScriptId) || null;
scripts.find(({ metadata }) => metadata.id === currentId) || null;

return (
<>
<PrimaryColumn>
<ScriptsList
scripts={scripts}
currentId={currentScriptId}
currentId={currentId}
/>
</PrimaryColumn>
<Main>
Expand Down

0 comments on commit 384c8fb

Please sign in to comment.