@arch-cadre/blog-module 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/index.d.ts +38 -5
- package/dist/actions/index.js +149 -0
- package/dist/components/BlogStatsWidget.d.ts +1 -2
- package/dist/components/BlogStatsWidget.js +17 -0
- package/dist/components/RecentCommentsWidget.d.ts +1 -2
- package/dist/components/RecentCommentsWidget.js +24 -0
- package/dist/components/RecentPostsWidget.d.ts +1 -2
- package/dist/components/RecentPostsWidget.js +24 -0
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/button.js +33 -0
- package/dist/components/ui/card.js +12 -0
- package/dist/components/ui/input.js +8 -0
- package/dist/components/ui/table.js +16 -0
- package/dist/components/ui/textarea.js +8 -0
- package/dist/index.js +98 -0
- package/dist/lib/{utils.mjs → utils.js} +1 -1
- package/dist/lib/validation.d.ts +2 -2
- package/dist/lib/validation.js +11 -0
- package/dist/navigation.js +21 -0
- package/dist/routes.js +55 -0
- package/dist/schema.js +60 -0
- package/dist/ui/views.d.ts +5 -6
- package/dist/ui/views.js +119 -0
- package/package.json +11 -17
- package/src/actions/index.d.ts +67 -0
- package/src/actions/index.js +149 -0
- package/src/actions/index.ts +157 -0
- package/src/components/BlogStatsWidget.d.ts +1 -0
- package/src/components/BlogStatsWidget.js +17 -0
- package/src/components/BlogStatsWidget.tsx +46 -0
- package/src/components/RecentCommentsWidget.d.ts +1 -0
- package/src/components/RecentCommentsWidget.js +24 -0
- package/src/components/RecentCommentsWidget.tsx +71 -0
- package/src/components/RecentPostsWidget.d.ts +1 -0
- package/src/components/RecentPostsWidget.js +24 -0
- package/src/components/RecentPostsWidget.tsx +68 -0
- package/src/components/ui/button.d.ts +11 -0
- package/src/components/ui/button.js +33 -0
- package/src/components/ui/button.tsx +56 -0
- package/src/components/ui/card.d.ts +6 -0
- package/src/components/ui/card.js +12 -0
- package/src/components/ui/card.tsx +51 -0
- package/src/components/ui/input.d.ts +5 -0
- package/src/components/ui/input.js +8 -0
- package/{dist/components/ui/input.mjs → src/components/ui/input.tsx} +17 -13
- package/src/components/ui/table.d.ts +8 -0
- package/src/components/ui/table.js +16 -0
- package/src/components/ui/table.tsx +83 -0
- package/src/components/ui/textarea.d.ts +5 -0
- package/src/components/ui/textarea.js +8 -0
- package/{dist/components/ui/textarea.mjs → src/components/ui/textarea.tsx} +16 -12
- package/src/index.d.ts +3 -0
- package/src/index.js +98 -0
- package/{dist/index.mjs → src/index.ts} +44 -18
- package/src/lib/utils.d.ts +2 -0
- package/src/lib/utils.js +5 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/validation.d.ts +24 -0
- package/src/lib/validation.js +11 -0
- package/{dist/lib/validation.mjs → src/lib/validation.ts} +5 -2
- package/src/navigation.d.ts +2 -0
- package/src/navigation.js +21 -0
- package/{dist/navigation.mjs → src/navigation.ts} +9 -7
- package/src/routes.d.ts +3 -0
- package/src/routes.js +55 -0
- package/{dist/routes.mjs → src/routes.tsx} +30 -24
- package/src/schema.d.ts +736 -0
- package/src/schema.js +60 -0
- package/src/schema.ts +67 -0
- package/src/styles/globals.css +123 -0
- package/src/ui/views.d.ts +15 -0
- package/src/ui/views.js +119 -0
- package/src/ui/views.tsx +538 -0
- package/dist/actions/index.cjs +0 -158
- package/dist/actions/index.mjs +0 -121
- package/dist/components/BlogStatsWidget.cjs +0 -45
- package/dist/components/BlogStatsWidget.mjs +0 -13
- package/dist/components/RecentCommentsWidget.cjs +0 -47
- package/dist/components/RecentCommentsWidget.mjs +0 -28
- package/dist/components/RecentPostsWidget.cjs +0 -47
- package/dist/components/RecentPostsWidget.mjs +0 -28
- package/dist/components/ui/button.cjs +0 -53
- package/dist/components/ui/button.mjs +0 -44
- package/dist/components/ui/card.cjs +0 -46
- package/dist/components/ui/card.mjs +0 -35
- package/dist/components/ui/input.cjs +0 -23
- package/dist/components/ui/table.cjs +0 -66
- package/dist/components/ui/table.mjs +0 -59
- package/dist/components/ui/textarea.cjs +0 -21
- package/dist/index.cjs +0 -100
- package/dist/lib/utils.cjs +0 -11
- package/dist/lib/validation.cjs +0 -16
- package/dist/navigation.cjs +0 -23
- package/dist/routes.cjs +0 -74
- package/dist/schema.cjs +0 -62
- package/dist/schema.mjs +0 -53
- package/dist/styles/globals.css +0 -1
- package/dist/ui/views.cjs +0 -448
- package/dist/ui/views.mjs +0 -232
- /package/{dist → src}/intl.d.ts +0 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { assignPermissionToRole, createPermission, db, getRoles, permissionsTable, } from "@arch-cadre/core/server";
|
|
2
|
+
import { inArray, sql } from "drizzle-orm";
|
|
3
|
+
import manifest from "../manifest.json" with { type: "json" };
|
|
4
|
+
import BlogStatsWidget from "./components/BlogStatsWidget.js";
|
|
5
|
+
import RecentCommentsWidget from "./components/RecentCommentsWidget.js";
|
|
6
|
+
import RecentPostsWidget from "./components/RecentPostsWidget.js";
|
|
7
|
+
import { navigation } from "./navigation.js";
|
|
8
|
+
import { privateRoutes, publicRoutes } from "./routes.js";
|
|
9
|
+
const BLOG_PERMISSIONS = [
|
|
10
|
+
{ name: "post:create", description: "Allow creating blog posts" },
|
|
11
|
+
{ name: "post:update", description: "Allow updating blog posts" },
|
|
12
|
+
{ name: "post:delete", description: "Allow deleting blog posts" },
|
|
13
|
+
{ name: "comment:create", description: "Allow creating comments" },
|
|
14
|
+
{ name: "comment:update", description: "Allow updating comments" },
|
|
15
|
+
{ name: "comment:delete", description: "Allow deleting comments" },
|
|
16
|
+
];
|
|
17
|
+
// --- Module Definition ---
|
|
18
|
+
const blogModule = {
|
|
19
|
+
manifest: manifest,
|
|
20
|
+
init: async () => {
|
|
21
|
+
console.log("[BlogModule] ready.");
|
|
22
|
+
},
|
|
23
|
+
widgets: [
|
|
24
|
+
{
|
|
25
|
+
id: "blog-stats",
|
|
26
|
+
name: "Blog Stats",
|
|
27
|
+
area: "dashboard-stats",
|
|
28
|
+
component: BlogStatsWidget,
|
|
29
|
+
priority: 20,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "recent-posts",
|
|
33
|
+
name: "Recent Posts",
|
|
34
|
+
area: "dashboard-main",
|
|
35
|
+
component: RecentPostsWidget,
|
|
36
|
+
priority: 20,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "recent-comments",
|
|
40
|
+
name: "Recent Comments",
|
|
41
|
+
area: "dashboard-main",
|
|
42
|
+
component: RecentCommentsWidget,
|
|
43
|
+
priority: 30,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
onEnable: async () => {
|
|
47
|
+
console.log("[BlogModule] enabling and registering permissions...");
|
|
48
|
+
try {
|
|
49
|
+
// 1. Create permissions
|
|
50
|
+
for (const perm of BLOG_PERMISSIONS) {
|
|
51
|
+
await createPermission(perm.name, perm.description);
|
|
52
|
+
}
|
|
53
|
+
// 2. Assign to admin role
|
|
54
|
+
const roles = await getRoles();
|
|
55
|
+
const adminRole = roles.find((r) => r.name === "admin");
|
|
56
|
+
if (adminRole) {
|
|
57
|
+
const blogPermNames = BLOG_PERMISSIONS.map((p) => p.name);
|
|
58
|
+
const blogPerms = await db
|
|
59
|
+
.select()
|
|
60
|
+
.from(permissionsTable)
|
|
61
|
+
.where(inArray(permissionsTable.name, blogPermNames));
|
|
62
|
+
for (const p of blogPerms) {
|
|
63
|
+
await assignPermissionToRole(adminRole.id, p.id);
|
|
64
|
+
}
|
|
65
|
+
console.log("[BlogModule] Permissions assigned to admin role.");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error("[BlogModule] Error during permission registration:", error);
|
|
70
|
+
}
|
|
71
|
+
console.log("[BlogModule] enabled.");
|
|
72
|
+
},
|
|
73
|
+
onDisable: async () => {
|
|
74
|
+
console.log("[Blog] onDisable: Cleaning up tables and permissions...");
|
|
75
|
+
try {
|
|
76
|
+
// 1. Remove permissions (cascades to role-permission mappings)
|
|
77
|
+
const blogPermNames = BLOG_PERMISSIONS.map((p) => p.name);
|
|
78
|
+
await db
|
|
79
|
+
.delete(permissionsTable)
|
|
80
|
+
.where(inArray(permissionsTable.name, blogPermNames));
|
|
81
|
+
console.log("[BlogModule] Permissions and mappings removed.");
|
|
82
|
+
// 2. Drop tables
|
|
83
|
+
const tables = ["blog_posts", "blog_comments"];
|
|
84
|
+
for (const table of tables) {
|
|
85
|
+
await db.execute(sql.raw(`DROP TABLE IF EXISTS ${table} CASCADE`));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
console.error("[Blog] onDisable Error:", e);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
routes: {
|
|
93
|
+
public: publicRoutes,
|
|
94
|
+
private: privateRoutes,
|
|
95
|
+
},
|
|
96
|
+
navigation: navigation,
|
|
97
|
+
};
|
|
98
|
+
export default blogModule;
|
|
@@ -3,62 +3,78 @@ import {
|
|
|
3
3
|
createPermission,
|
|
4
4
|
db,
|
|
5
5
|
getRoles,
|
|
6
|
-
permissionsTable
|
|
6
|
+
permissionsTable,
|
|
7
7
|
} from "@arch-cadre/core/server";
|
|
8
|
+
import type { IModule } from "@arch-cadre/modules";
|
|
8
9
|
import { inArray, sql } from "drizzle-orm";
|
|
9
10
|
import manifest from "../manifest.json" with { type: "json" };
|
|
10
|
-
import BlogStatsWidget from "./components/BlogStatsWidget.
|
|
11
|
-
import RecentCommentsWidget from "./components/RecentCommentsWidget.
|
|
12
|
-
import RecentPostsWidget from "./components/RecentPostsWidget.
|
|
13
|
-
import { navigation } from "./navigation.
|
|
14
|
-
import { privateRoutes, publicRoutes } from "./routes.
|
|
11
|
+
import BlogStatsWidget from "./components/BlogStatsWidget.js";
|
|
12
|
+
import RecentCommentsWidget from "./components/RecentCommentsWidget.js";
|
|
13
|
+
import RecentPostsWidget from "./components/RecentPostsWidget.js";
|
|
14
|
+
import { navigation } from "./navigation.js";
|
|
15
|
+
import { privateRoutes, publicRoutes } from "./routes.js";
|
|
16
|
+
|
|
15
17
|
const BLOG_PERMISSIONS = [
|
|
16
18
|
{ name: "post:create", description: "Allow creating blog posts" },
|
|
17
19
|
{ name: "post:update", description: "Allow updating blog posts" },
|
|
18
20
|
{ name: "post:delete", description: "Allow deleting blog posts" },
|
|
19
21
|
{ name: "comment:create", description: "Allow creating comments" },
|
|
20
22
|
{ name: "comment:update", description: "Allow updating comments" },
|
|
21
|
-
{ name: "comment:delete", description: "Allow deleting comments" }
|
|
23
|
+
{ name: "comment:delete", description: "Allow deleting comments" },
|
|
22
24
|
];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
|
|
26
|
+
// --- Module Definition ---
|
|
27
|
+
const blogModule: IModule = {
|
|
28
|
+
manifest: manifest as any,
|
|
29
|
+
|
|
25
30
|
init: async () => {
|
|
26
31
|
console.log("[BlogModule] ready.");
|
|
27
32
|
},
|
|
33
|
+
|
|
28
34
|
widgets: [
|
|
29
35
|
{
|
|
30
36
|
id: "blog-stats",
|
|
31
37
|
name: "Blog Stats",
|
|
32
38
|
area: "dashboard-stats",
|
|
33
39
|
component: BlogStatsWidget,
|
|
34
|
-
priority: 20
|
|
40
|
+
priority: 20,
|
|
35
41
|
},
|
|
36
42
|
{
|
|
37
43
|
id: "recent-posts",
|
|
38
44
|
name: "Recent Posts",
|
|
39
45
|
area: "dashboard-main",
|
|
40
46
|
component: RecentPostsWidget,
|
|
41
|
-
priority: 20
|
|
47
|
+
priority: 20,
|
|
42
48
|
},
|
|
43
49
|
{
|
|
44
50
|
id: "recent-comments",
|
|
45
51
|
name: "Recent Comments",
|
|
46
52
|
area: "dashboard-main",
|
|
47
53
|
component: RecentCommentsWidget,
|
|
48
|
-
priority: 30
|
|
49
|
-
}
|
|
54
|
+
priority: 30,
|
|
55
|
+
},
|
|
50
56
|
],
|
|
57
|
+
|
|
51
58
|
onEnable: async () => {
|
|
52
59
|
console.log("[BlogModule] enabling and registering permissions...");
|
|
60
|
+
|
|
53
61
|
try {
|
|
62
|
+
// 1. Create permissions
|
|
54
63
|
for (const perm of BLOG_PERMISSIONS) {
|
|
55
64
|
await createPermission(perm.name, perm.description);
|
|
56
65
|
}
|
|
66
|
+
|
|
67
|
+
// 2. Assign to admin role
|
|
57
68
|
const roles = await getRoles();
|
|
58
69
|
const adminRole = roles.find((r) => r.name === "admin");
|
|
70
|
+
|
|
59
71
|
if (adminRole) {
|
|
60
72
|
const blogPermNames = BLOG_PERMISSIONS.map((p) => p.name);
|
|
61
|
-
const blogPerms = await db
|
|
73
|
+
const blogPerms = await db
|
|
74
|
+
.select()
|
|
75
|
+
.from(permissionsTable)
|
|
76
|
+
.where(inArray(permissionsTable.name, blogPermNames));
|
|
77
|
+
|
|
62
78
|
for (const p of blogPerms) {
|
|
63
79
|
await assignPermissionToRole(adminRole.id, p.id);
|
|
64
80
|
}
|
|
@@ -67,17 +83,24 @@ const blogModule = {
|
|
|
67
83
|
} catch (error) {
|
|
68
84
|
console.error(
|
|
69
85
|
"[BlogModule] Error during permission registration:",
|
|
70
|
-
error
|
|
86
|
+
error,
|
|
71
87
|
);
|
|
72
88
|
}
|
|
89
|
+
|
|
73
90
|
console.log("[BlogModule] enabled.");
|
|
74
91
|
},
|
|
92
|
+
|
|
75
93
|
onDisable: async () => {
|
|
76
94
|
console.log("[Blog] onDisable: Cleaning up tables and permissions...");
|
|
77
95
|
try {
|
|
96
|
+
// 1. Remove permissions (cascades to role-permission mappings)
|
|
78
97
|
const blogPermNames = BLOG_PERMISSIONS.map((p) => p.name);
|
|
79
|
-
await db
|
|
98
|
+
await db
|
|
99
|
+
.delete(permissionsTable)
|
|
100
|
+
.where(inArray(permissionsTable.name, blogPermNames));
|
|
80
101
|
console.log("[BlogModule] Permissions and mappings removed.");
|
|
102
|
+
|
|
103
|
+
// 2. Drop tables
|
|
81
104
|
const tables = ["blog_posts", "blog_comments"];
|
|
82
105
|
for (const table of tables) {
|
|
83
106
|
await db.execute(sql.raw(`DROP TABLE IF EXISTS ${table} CASCADE`));
|
|
@@ -86,10 +109,13 @@ const blogModule = {
|
|
|
86
109
|
console.error("[Blog] onDisable Error:", e);
|
|
87
110
|
}
|
|
88
111
|
},
|
|
112
|
+
|
|
89
113
|
routes: {
|
|
90
114
|
public: publicRoutes,
|
|
91
|
-
private: privateRoutes
|
|
115
|
+
private: privateRoutes,
|
|
92
116
|
},
|
|
93
|
-
|
|
117
|
+
|
|
118
|
+
navigation: navigation,
|
|
94
119
|
};
|
|
120
|
+
|
|
95
121
|
export default blogModule;
|
package/src/lib/utils.js
ADDED
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const postSchema: z.ZodObject<{
|
|
3
|
+
title: z.ZodString;
|
|
4
|
+
content: z.ZodString;
|
|
5
|
+
slug: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
title: string;
|
|
8
|
+
slug: string;
|
|
9
|
+
content: string;
|
|
10
|
+
}, {
|
|
11
|
+
title: string;
|
|
12
|
+
slug: string;
|
|
13
|
+
content: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const commentSchema: z.ZodObject<{
|
|
16
|
+
content: z.ZodString;
|
|
17
|
+
postId: z.ZodString;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
content: string;
|
|
20
|
+
postId: string;
|
|
21
|
+
}, {
|
|
22
|
+
content: string;
|
|
23
|
+
postId: string;
|
|
24
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// --- Validation Schemas ---
|
|
3
|
+
export const postSchema = z.object({
|
|
4
|
+
title: z.string().min(3, "Title must be at least 3 characters"),
|
|
5
|
+
content: z.string().min(10, "Content must be at least 10 characters"),
|
|
6
|
+
slug: z.string().min(3, "Slug is required"),
|
|
7
|
+
});
|
|
8
|
+
export const commentSchema = z.object({
|
|
9
|
+
content: z.string().min(2, "Comment is too short"),
|
|
10
|
+
postId: z.string().uuid(),
|
|
11
|
+
});
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
// --- Validation Schemas ---
|
|
2
4
|
export const postSchema = z.object({
|
|
3
5
|
title: z.string().min(3, "Title must be at least 3 characters"),
|
|
4
6
|
content: z.string().min(10, "Content must be at least 10 characters"),
|
|
5
|
-
slug: z.string().min(3, "Slug is required")
|
|
7
|
+
slug: z.string().min(3, "Slug is required"),
|
|
6
8
|
});
|
|
9
|
+
|
|
7
10
|
export const commentSchema = z.object({
|
|
8
11
|
content: z.string().min(2, "Comment is too short"),
|
|
9
|
-
postId: z.string().uuid()
|
|
12
|
+
postId: z.string().uuid(),
|
|
10
13
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { i18n } from "@arch-cadre/intl";
|
|
2
|
+
export const navigation = {
|
|
3
|
+
public: [
|
|
4
|
+
{
|
|
5
|
+
title: i18n("Blog"),
|
|
6
|
+
url: "/blog",
|
|
7
|
+
icon: "solar:pen-2-broken",
|
|
8
|
+
},
|
|
9
|
+
],
|
|
10
|
+
admin: {
|
|
11
|
+
[i18n("CMS")]: [
|
|
12
|
+
{
|
|
13
|
+
title: i18n("Blog Manager"),
|
|
14
|
+
url: "/blog",
|
|
15
|
+
icon: "solar:posts-carousel-vertical-broken",
|
|
16
|
+
roles: ["admin"],
|
|
17
|
+
permissions: ["post:create", "post:update", "post:delete"],
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { i18n } from "@arch-cadre/intl";
|
|
2
|
-
|
|
2
|
+
import type { ModuleNavigation } from "@arch-cadre/modules";
|
|
3
|
+
|
|
4
|
+
export const navigation: ModuleNavigation = {
|
|
3
5
|
public: [
|
|
4
6
|
{
|
|
5
7
|
title: i18n("Blog"),
|
|
6
8
|
url: "/blog",
|
|
7
|
-
icon: "solar:pen-2-broken"
|
|
8
|
-
}
|
|
9
|
+
icon: "solar:pen-2-broken",
|
|
10
|
+
},
|
|
9
11
|
],
|
|
10
12
|
admin: {
|
|
11
13
|
[i18n("CMS")]: [
|
|
@@ -14,8 +16,8 @@ export const navigation = {
|
|
|
14
16
|
url: "/blog",
|
|
15
17
|
icon: "solar:posts-carousel-vertical-broken",
|
|
16
18
|
roles: ["admin"],
|
|
17
|
-
permissions: ["post:create", "post:update", "post:delete"]
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
}
|
|
19
|
+
permissions: ["post:create", "post:update", "post:delete"],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
21
23
|
};
|
package/src/routes.d.ts
ADDED
package/src/routes.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getCurrentSession } from "@arch-cadre/core/server";
|
|
3
|
+
import { getComments, getPostById, getPostBySlug, getPosts } from "./actions/index.js";
|
|
4
|
+
import { BlogAdminPage, BlogListPage, CreatePostForm, EditPostForm, PostDetailPage, } from "./ui/views.js";
|
|
5
|
+
export const publicRoutes = [
|
|
6
|
+
{
|
|
7
|
+
path: "/blog",
|
|
8
|
+
component: async () => {
|
|
9
|
+
const posts = await getPosts();
|
|
10
|
+
return _jsx(BlogListPage, { posts: posts });
|
|
11
|
+
},
|
|
12
|
+
auth: false,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
path: "/blog/:slug",
|
|
16
|
+
component: async ({ params }) => {
|
|
17
|
+
const { slug } = await params;
|
|
18
|
+
const post = await getPostBySlug(slug);
|
|
19
|
+
const comments = post ? await getComments(post.id) : [];
|
|
20
|
+
const session = await getCurrentSession();
|
|
21
|
+
return (_jsx(PostDetailPage, { post: post, comments: comments, currentUser: session?.user }));
|
|
22
|
+
},
|
|
23
|
+
auth: false,
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
export const privateRoutes = [
|
|
27
|
+
{
|
|
28
|
+
path: "/blog",
|
|
29
|
+
component: async () => {
|
|
30
|
+
const posts = await getPosts();
|
|
31
|
+
return _jsx(BlogAdminPage, { posts: posts });
|
|
32
|
+
},
|
|
33
|
+
auth: true,
|
|
34
|
+
roles: ["admin"],
|
|
35
|
+
permissions: ["post:create", "post:update", "post:delete"],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
path: "/blog/new",
|
|
39
|
+
component: CreatePostForm,
|
|
40
|
+
auth: true,
|
|
41
|
+
roles: ["admin"],
|
|
42
|
+
permissions: ["post:create"],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
path: "/blog/edit/:id",
|
|
46
|
+
component: async ({ params }) => {
|
|
47
|
+
const { id } = await params;
|
|
48
|
+
const post = await getPostById(id);
|
|
49
|
+
return _jsx(EditPostForm, { post: post });
|
|
50
|
+
},
|
|
51
|
+
auth: true,
|
|
52
|
+
roles: ["admin"],
|
|
53
|
+
permissions: ["post:update"],
|
|
54
|
+
},
|
|
55
|
+
];
|
|
@@ -1,68 +1,74 @@
|
|
|
1
1
|
import { getCurrentSession } from "@arch-cadre/core/server";
|
|
2
|
+
import type {
|
|
3
|
+
PrivateRouteDefinition,
|
|
4
|
+
PublicRouteDefinition,
|
|
5
|
+
} from "@arch-cadre/modules";
|
|
2
6
|
import * as React from "react";
|
|
3
|
-
import { getComments, getPostById, getPostBySlug, getPosts } from "./actions/index.
|
|
7
|
+
import { getComments, getPostById, getPostBySlug, getPosts } from "./actions/index.js";
|
|
4
8
|
import {
|
|
5
9
|
BlogAdminPage,
|
|
6
10
|
BlogListPage,
|
|
7
11
|
CreatePostForm,
|
|
8
12
|
EditPostForm,
|
|
9
|
-
PostDetailPage
|
|
10
|
-
} from "./ui/views.
|
|
11
|
-
|
|
13
|
+
PostDetailPage,
|
|
14
|
+
} from "./ui/views.js";
|
|
15
|
+
|
|
16
|
+
export const publicRoutes: PublicRouteDefinition[] = [
|
|
12
17
|
{
|
|
13
18
|
path: "/blog",
|
|
14
19
|
component: async () => {
|
|
15
20
|
const posts = await getPosts();
|
|
16
|
-
return
|
|
21
|
+
return <BlogListPage posts={posts} />;
|
|
17
22
|
},
|
|
18
|
-
auth: false
|
|
23
|
+
auth: false,
|
|
19
24
|
},
|
|
20
25
|
{
|
|
21
26
|
path: "/blog/:slug",
|
|
22
|
-
component: async ({ params }) => {
|
|
27
|
+
component: async ({ params }: any) => {
|
|
23
28
|
const { slug } = await params;
|
|
24
29
|
const post = await getPostBySlug(slug);
|
|
25
30
|
const comments = post ? await getComments(post.id) : [];
|
|
26
31
|
const session = await getCurrentSession();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
post
|
|
31
|
-
comments
|
|
32
|
-
currentUser
|
|
33
|
-
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<PostDetailPage
|
|
35
|
+
post={post}
|
|
36
|
+
comments={comments}
|
|
37
|
+
currentUser={session?.user}
|
|
38
|
+
/>
|
|
34
39
|
);
|
|
35
40
|
},
|
|
36
|
-
auth: false
|
|
37
|
-
}
|
|
41
|
+
auth: false,
|
|
42
|
+
},
|
|
38
43
|
];
|
|
39
|
-
|
|
44
|
+
|
|
45
|
+
export const privateRoutes: PrivateRouteDefinition[] = [
|
|
40
46
|
{
|
|
41
47
|
path: "/blog",
|
|
42
48
|
component: async () => {
|
|
43
49
|
const posts = await getPosts();
|
|
44
|
-
return
|
|
50
|
+
return <BlogAdminPage posts={posts} />;
|
|
45
51
|
},
|
|
46
52
|
auth: true,
|
|
47
53
|
roles: ["admin"],
|
|
48
|
-
permissions: ["post:create", "post:update", "post:delete"]
|
|
54
|
+
permissions: ["post:create", "post:update", "post:delete"],
|
|
49
55
|
},
|
|
50
56
|
{
|
|
51
57
|
path: "/blog/new",
|
|
52
58
|
component: CreatePostForm,
|
|
53
59
|
auth: true,
|
|
54
60
|
roles: ["admin"],
|
|
55
|
-
permissions: ["post:create"]
|
|
61
|
+
permissions: ["post:create"],
|
|
56
62
|
},
|
|
57
63
|
{
|
|
58
64
|
path: "/blog/edit/:id",
|
|
59
|
-
component: async ({ params }) => {
|
|
65
|
+
component: async ({ params }: any) => {
|
|
60
66
|
const { id } = await params;
|
|
61
67
|
const post = await getPostById(id);
|
|
62
|
-
return
|
|
68
|
+
return <EditPostForm post={post} />;
|
|
63
69
|
},
|
|
64
70
|
auth: true,
|
|
65
71
|
roles: ["admin"],
|
|
66
|
-
permissions: ["post:update"]
|
|
67
|
-
}
|
|
72
|
+
permissions: ["post:update"],
|
|
73
|
+
},
|
|
68
74
|
];
|