Skip to content

Commit

Permalink
Dynamic Assignment: Page Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiah-carlson committed Sep 14, 2023
1 parent 8968b40 commit eaf231e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions www/src/configs/modules/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {default as Default} from "../default";
export {default as Concert} from "../concert";
2 changes: 2 additions & 0 deletions www/src/configs/modules/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {default as Default} from "../default";
export {default as Concert} from "../concert";
10 changes: 5 additions & 5 deletions www/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Switch, render } from 'solid-js/web';
import { Router, Route, Routes, hashIntegration } from "@solidjs/router";

import './index.css';
import * as Page from './pages/Production';
import { Pages } from './pages/Production';

const root = document.getElementById('root');

Expand All @@ -19,10 +19,10 @@ const rootPage = import.meta.env.VITE_ROOT_PAGE ?? "default"
render(() => (
<Router source={routerSrc}>
<Routes>
<For each={Object.entries(Page)}>{
(pg, i)=> <Switch fallback={<Route path={`/${pg[0].toLowerCase()}`} component={pg[1]}/>}>
<Match when={pg[0].toLowerCase() == rootPage}>
<Route path="/" component={pg[1]}/>
<For each={Pages}>{
(pg, i)=> <Switch fallback={<Route path={`/${pg.name.toLowerCase()}`} component={pg.func}/>}>
<Match when={pg.name.toLowerCase() == rootPage}>
<Route path="/" component={pg.func}/>
</Match>
</Switch>
}</For>
Expand Down
16 changes: 7 additions & 9 deletions www/src/pages/Production.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import Abstract from './Abstract';

import defaultCfg from '../configs/default';// <-- Change config file
import concertCfg from '../configs/concert';
import * as Configs from "../configs/modules/production"

export function Default() {// <-- Change function name
return (<Abstract conf={defaultCfg}/>);// <-- Match config import
};

export function Concert() {
return (<Abstract conf={concertCfg}/>);
};
export const Pages = Object.entries(Configs).map((cfg)=>{
return {
name: cfg[0],
func: ()=>{return (<Abstract conf={cfg[1]}/>);}
}
});

0 comments on commit eaf231e

Please sign in to comment.