|
3 | 3 | import { Pagination_Schema } from "@~/app.core/schema";
|
4 | 4 | import { Main_Layout } from "@~/app.layout/index";
|
5 | 5 | import { authorized } from "@~/app.middleware/authorized";
|
6 |
| -import type { App_Context } from "@~/app.middleware/context"; |
| 6 | +import { set_variables } from "@~/app.middleware/context/set_variables"; |
7 | 7 | import { Hono } from "hono";
|
8 | 8 | import { jsxRenderer } from "hono/jsx-renderer";
|
9 | 9 | import { P, match } from "ts-pattern";
|
10 | 10 | import moderation_router from "./:id/index";
|
11 |
| -import { Search_Schema } from "./context"; |
| 11 | +import { loadModerationsListPageVariables, Search_Schema, type ContextType } from "./context"; |
12 | 12 | import { Moderations_Page } from "./page";
|
13 | 13 |
|
14 | 14 | //
|
15 |
| -export default new Hono<App_Context>() |
| 15 | +export default new Hono<ContextType>() |
16 | 16 | .use(authorized())
|
17 | 17 |
|
18 | 18 | .route("/:id", moderation_router)
|
19 |
| - .get("/", jsxRenderer(Main_Layout), function GET({ render, req, set }) { |
20 |
| - const query = req.query(); |
| 19 | + .get( |
| 20 | + "/", |
| 21 | + jsxRenderer(Main_Layout), |
| 22 | + async function set_variables_middleware({ req, set }, next) { |
| 23 | + const query = req.query(); |
21 | 24 |
|
22 |
| - const search = match(Search_Schema.parse(query, { path: ["query"] })) |
23 |
| - .with( |
24 |
| - { search_email: P.not("") }, |
25 |
| - { search_siret: P.not("") }, |
26 |
| - (search) => ({ |
27 |
| - ...search, |
28 |
| - hide_join_organization: false, |
29 |
| - hide_non_verified_domain: false, |
30 |
| - processed_requests: true, |
31 |
| - }), |
32 |
| - ) |
33 |
| - .otherwise((search) => search); |
| 25 | + const search = match(Search_Schema.parse(query, { path: ["query"] })) |
| 26 | + .with( |
| 27 | + { search_email: P.not("") }, |
| 28 | + { search_siret: P.not("") }, |
| 29 | + (search) => ({ |
| 30 | + ...search, |
| 31 | + hide_join_organization: false, |
| 32 | + hide_non_verified_domain: false, |
| 33 | + processed_requests: true, |
| 34 | + }), |
| 35 | + ) |
| 36 | + .otherwise((search) => search); |
34 | 37 |
|
35 |
| - const pagination = match( |
36 |
| - Pagination_Schema.safeParse(query, { path: ["query"] }), |
37 |
| - ) |
38 |
| - .with({ success: true }, ({ data }) => data) |
39 |
| - .otherwise(() => Pagination_Schema.parse({})); |
| 38 | + const pagination = match( |
| 39 | + Pagination_Schema.safeParse(query, { path: ["query"] }), |
| 40 | + ) |
| 41 | + .with({ success: true }, ({ data }) => data) |
| 42 | + .otherwise(() => Pagination_Schema.parse({})); |
40 | 43 |
|
41 |
| - set("page_title", "Liste des moderations"); |
42 |
| - return render(<Moderations_Page pagination={pagination} search={search} />); |
43 |
| - }); |
| 44 | + const variables = await loadModerationsListPageVariables({ pagination, search }); |
| 45 | + set_variables(set, variables); |
| 46 | + return next(); |
| 47 | + }, |
| 48 | + function GET({ render, set, var: { pagination, search } }) { |
| 49 | + set("page_title", "Liste des moderations"); |
| 50 | + return render(<Moderations_Page pagination={pagination} search={search} />); |
| 51 | + }, |
| 52 | + ); |
44 | 53 |
|
45 | 54 | //
|
0 commit comments