diff --git a/defaults/interfaces.ts b/defaults/interfaces.ts new file mode 100644 index 0000000..8b33c66 --- /dev/null +++ b/defaults/interfaces.ts @@ -0,0 +1,8 @@ +export interface AppProperties { + name: string; + icon: string; + pages: Record; + adminOnly: string[]; +} + +export type EmptyObject = Record; diff --git a/defaults/makeIndex.ts b/defaults/makeIndex.ts new file mode 100644 index 0000000..4205b03 --- /dev/null +++ b/defaults/makeIndex.ts @@ -0,0 +1,10 @@ +import { EmptyObject } from "$root/defaults/interfaces.ts"; + +export default function makeIndex< + IndexProps = EmptyObject, +>(basePath: string) { + return async function Index(props: IndexProps) { + const index = (await import(`${basePath}/partials/index.tsx`)).Index; + return index(props); + }; +} diff --git a/defaults/makePartials.tsx b/defaults/makePartials.tsx new file mode 100644 index 0000000..786ae68 --- /dev/null +++ b/defaults/makePartials.tsx @@ -0,0 +1,23 @@ +import { JSX } from "preact"; +import { Partial } from "$fresh/runtime.ts"; +import { RouteConfig } from "$fresh/server.ts"; + +export function getConfig(): RouteConfig { + return { + skipAppWrapper: true, + skipInheritedLayouts: true, + }; +} + +// deno-lint-ignore no-explicit-any +export function makePartials( + page: (props: Props) => JSX.Element, +) { + return function WrappedElements(props: Props): JSX.Element { + return ( + + {page(props)} + + ); + }; +} diff --git a/deno.json b/deno.json index ef4b243..adc5a39 100644 --- a/deno.json +++ b/deno.json @@ -28,7 +28,8 @@ "preact/": "https://esm.sh/preact@10.22.0/", "@preact/signals": "https://esm.sh/*@preact/signals@1.2.2", "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1", - "$std/": "https://deno.land/std@0.216.0/" + "$std/": "https://deno.land/std@0.216.0/", + "$root/": "./" }, "compilerOptions": { "jsx": "react-jsx", diff --git a/fresh.config.ts b/fresh.config.ts index 783c68c..e6c4033 100644 --- a/fresh.config.ts +++ b/fresh.config.ts @@ -4,6 +4,6 @@ export default defineConfig({ server: { cert: await Deno.readTextFile("certs/cert.pem"), key: await Deno.readTextFile("certs/key.pem"), - port: 443 - } + port: 443, + }, }); diff --git a/fresh.gen.ts b/fresh.gen.ts index 1bcdb76..dad4883 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -2,8 +2,13 @@ // This file SHOULD be checked into source version control. // This file is automatically updated during development when running `dev.ts`. +import * as $_apps_layout from "./routes/(apps)/_layout.tsx"; import * as $_apps_mobility_index from "./routes/(apps)/mobility/index.tsx"; import * as $_apps_notes_index from "./routes/(apps)/notes/index.tsx"; +import * as $_apps_notes_partials_admin_courses from "./routes/(apps)/notes/partials/(admin)/courses.tsx"; +import * as $_apps_notes_partials_admin_students from "./routes/(apps)/notes/partials/(admin)/students.tsx"; +import * as $_apps_notes_partials_index from "./routes/(apps)/notes/partials/index.tsx"; +import * as $_apps_notes_partials_notes from "./routes/(apps)/notes/partials/notes.tsx"; import * as $_404 from "./routes/_404.tsx"; import * as $_app from "./routes/_app.tsx"; import * as $_middleware from "./routes/_middleware.ts"; @@ -14,12 +19,20 @@ import * as $login from "./routes/login.tsx"; import * as $logout from "./routes/logout.tsx"; import * as $Counter from "./islands/Counter.tsx"; import * as $_islands_AppNavigator from "./routes/(_islands)/AppNavigator.tsx"; +import * as $_islands_Navbar from "./routes/(_islands)/Navbar.tsx"; import type { Manifest } from "$fresh/server.ts"; const manifest = { routes: { + "./routes/(apps)/_layout.tsx": $_apps_layout, "./routes/(apps)/mobility/index.tsx": $_apps_mobility_index, "./routes/(apps)/notes/index.tsx": $_apps_notes_index, + "./routes/(apps)/notes/partials/(admin)/courses.tsx": + $_apps_notes_partials_admin_courses, + "./routes/(apps)/notes/partials/(admin)/students.tsx": + $_apps_notes_partials_admin_students, + "./routes/(apps)/notes/partials/index.tsx": $_apps_notes_partials_index, + "./routes/(apps)/notes/partials/notes.tsx": $_apps_notes_partials_notes, "./routes/_404.tsx": $_404, "./routes/_app.tsx": $_app, "./routes/_middleware.ts": $_middleware, @@ -32,6 +45,7 @@ const manifest = { islands: { "./islands/Counter.tsx": $Counter, "./routes/(_islands)/AppNavigator.tsx": $_islands_AppNavigator, + "./routes/(_islands)/Navbar.tsx": $_islands_Navbar, }, baseUrl: import.meta.url, } satisfies Manifest; diff --git a/readme.md b/readme.md index fe301d2..6c3c91c 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,4 @@ # ✨ PolyMPR ✨ -The ✨ Poly Module de Pilotage des Ressources ✨ is the ultimate tool to handle various HR task in the INFO department. \ No newline at end of file +The ✨ Poly Module de Pilotage des Ressources ✨ is the ultimate tool to handle +various HR task in the INFO department. diff --git a/routes/(_components)/Footer.tsx b/routes/(_components)/Footer.tsx index 014638f..f71930f 100644 --- a/routes/(_components)/Footer.tsx +++ b/routes/(_components)/Footer.tsx @@ -1,11 +1,12 @@ -type FooterProps = Record; +import { EmptyObject } from "$root/defaults/interfaces.ts"; + +type FooterProps = EmptyObject; export default function Footer(_props: FooterProps) { return (

- © 2025 PolyMPR -{" "} - About + © 2025 PolyMPR - About

); diff --git a/routes/(_components)/PartialLink.tsx b/routes/(_components)/PartialLink.tsx new file mode 100644 index 0000000..1f6e380 --- /dev/null +++ b/routes/(_components)/PartialLink.tsx @@ -0,0 +1,13 @@ +interface PartialLinkProps { + link: string; + partial: string; + display: string; +} + +export default function PartialLink(props: PartialLinkProps) { + return ( + + {props.display} + + ); +} diff --git a/routes/(_islands)/AppNavigator.tsx b/routes/(_islands)/AppNavigator.tsx index 7f23cb2..4618a55 100644 --- a/routes/(_islands)/AppNavigator.tsx +++ b/routes/(_islands)/AppNavigator.tsx @@ -1,8 +1,4 @@ -export interface AppProperties { - name: string; - icon: string; - hint: string; -} +import { AppProperties } from "$root/defaults/interfaces.ts"; type AppNavigatorProps = { apps: Record; diff --git a/routes/(_islands)/Navbar.tsx b/routes/(_islands)/Navbar.tsx new file mode 100644 index 0000000..3428f2d --- /dev/null +++ b/routes/(_islands)/Navbar.tsx @@ -0,0 +1,29 @@ +import PartialLink from "$root/routes/(_components)/PartialLink.tsx"; +import { JSX } from "preact/jsx-runtime"; + +type NavbarProps = { + currentApp: string; + pages: Record; +}; + +export default function Navbar(props: NavbarProps) { + const links: JSX.Element[] = []; + + for (const page in props.pages) { + links.push( + , + ); + } + + return ( + + ); +} diff --git a/routes/(apps)/_layout.tsx b/routes/(apps)/_layout.tsx new file mode 100644 index 0000000..7852df6 --- /dev/null +++ b/routes/(apps)/_layout.tsx @@ -0,0 +1,25 @@ +import { FreshContext } from "$fresh/server.ts"; +import { Partial } from "$fresh/runtime.ts"; +import { State } from "$root/routes/_middleware.ts"; +import { AppProperties } from "$root/defaults/interfaces.ts"; +import Navbar from "$root/routes/(_islands)/Navbar.tsx"; + +export default async function AppLayout( + request: Request, + context: FreshContext, +) { + const pathname = new URL(request.url).pathname; + const currentApp = pathname.split("/")[1]; + const properties: AppProperties = (await import( + `./${currentApp}/(_props)/props.ts` + )).default; + + return ( +
+ + + + +
+ ); +} diff --git a/routes/(apps)/notes/(_props)/props.ts b/routes/(apps)/notes/(_props)/props.ts index 7c203a6..c814a4d 100644 --- a/routes/(apps)/notes/(_props)/props.ts +++ b/routes/(apps)/notes/(_props)/props.ts @@ -1,9 +1,16 @@ -import { AppProperties } from "../../../(_islands)/AppNavigator.tsx"; +import { AppProperties } from "$root/defaults/interfaces.ts"; const properties: AppProperties = { name: "PolyNotes", icon: "school", + pages: { + index: "Homepage", + notes: "Notes", + courses: "Courses management", + students: "Students management", + }, + adminOnly: ["courses", "students"], hint: "Gestionnaire de note" }; -export default properties; \ No newline at end of file +export default properties; diff --git a/routes/(apps)/notes/index.tsx b/routes/(apps)/notes/index.tsx index ddfcc34..1d82f7f 100644 --- a/routes/(apps)/notes/index.tsx +++ b/routes/(apps)/notes/index.tsx @@ -1,12 +1,2 @@ -type ModulesProps = Record; - -export default function Modules(_props: ModulesProps) { - return ( - <> -

All PolyMPR modules

- - - ); -} \ No newline at end of file +import makeIndex from "$root/defaults/makeIndex.ts"; +export default makeIndex(import.meta.dirname!); diff --git a/routes/(apps)/notes/partials/(admin)/courses.tsx b/routes/(apps)/notes/partials/(admin)/courses.tsx new file mode 100644 index 0000000..9d361cf --- /dev/null +++ b/routes/(apps)/notes/partials/(admin)/courses.tsx @@ -0,0 +1,17 @@ +import { Partial } from "$fresh/runtime.ts"; +import { RouteConfig } from "$fresh/server.ts"; + +type ModulesProps = Record; + +export const config: RouteConfig = { + skipAppWrapper: true, + skipInheritedLayouts: true, +}; + +export default function Modules(_props: ModulesProps) { + return ( + + notes + + ); +} diff --git a/routes/(apps)/notes/partials/(admin)/students.tsx b/routes/(apps)/notes/partials/(admin)/students.tsx new file mode 100644 index 0000000..9d361cf --- /dev/null +++ b/routes/(apps)/notes/partials/(admin)/students.tsx @@ -0,0 +1,17 @@ +import { Partial } from "$fresh/runtime.ts"; +import { RouteConfig } from "$fresh/server.ts"; + +type ModulesProps = Record; + +export const config: RouteConfig = { + skipAppWrapper: true, + skipInheritedLayouts: true, +}; + +export default function Modules(_props: ModulesProps) { + return ( + + notes + + ); +} diff --git a/routes/(apps)/notes/partials/index.tsx b/routes/(apps)/notes/partials/index.tsx new file mode 100644 index 0000000..cd6763c --- /dev/null +++ b/routes/(apps)/notes/partials/index.tsx @@ -0,0 +1,10 @@ +import { getConfig, makePartials } from "$root/defaults/makePartials.tsx"; + +type NotesIndexProps = Record; + +export function Index(_props: NotesIndexProps) { + return bip boup; +} + +export const config = getConfig(); +export default makePartials(Index); diff --git a/routes/(apps)/notes/partials/notes.tsx b/routes/(apps)/notes/partials/notes.tsx new file mode 100644 index 0000000..9d361cf --- /dev/null +++ b/routes/(apps)/notes/partials/notes.tsx @@ -0,0 +1,17 @@ +import { Partial } from "$fresh/runtime.ts"; +import { RouteConfig } from "$fresh/server.ts"; + +type ModulesProps = Record; + +export const config: RouteConfig = { + skipAppWrapper: true, + skipInheritedLayouts: true, +}; + +export default function Modules(_props: ModulesProps) { + return ( + + notes + + ); +} diff --git a/routes/_app.tsx b/routes/_app.tsx index 31218a7..f9c96ac 100644 --- a/routes/_app.tsx +++ b/routes/_app.tsx @@ -1,8 +1,7 @@ import { FreshContext } from "$fresh/server.ts"; -import { Partial } from "$fresh/runtime.ts"; -import { State } from "./_middleware.ts"; -import Header from "./(_components)/Header.tsx"; -import Footer from "./(_components)/Footer.tsx"; +import { State } from "$root/routes/_middleware.ts"; +import Header from "$root/routes/(_components)/Header.tsx"; +import Footer from "$root/routes/(_components)/Footer.tsx"; // deno-lint-ignore require-await export default async function App( @@ -20,13 +19,12 @@ export default async function App( +
- - - +