@arch-cadre/blog-module 1.0.13 → 1.0.15
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.cjs +158 -0
- package/dist/actions/index.d.ts +4 -37
- package/dist/actions/index.mjs +121 -0
- package/dist/components/BlogStatsWidget.cjs +45 -0
- package/dist/components/BlogStatsWidget.d.ts +2 -1
- package/dist/components/BlogStatsWidget.mjs +13 -0
- package/dist/components/RecentCommentsWidget.cjs +47 -0
- package/dist/components/RecentCommentsWidget.d.ts +2 -1
- package/dist/components/RecentCommentsWidget.mjs +28 -0
- package/dist/components/RecentPostsWidget.cjs +47 -0
- package/dist/components/RecentPostsWidget.d.ts +2 -1
- package/dist/components/RecentPostsWidget.mjs +28 -0
- package/dist/components/ui/button.cjs +54 -0
- package/dist/components/ui/button.mjs +47 -0
- package/dist/components/ui/card.cjs +47 -0
- package/dist/components/ui/card.mjs +36 -0
- package/dist/components/ui/input.cjs +24 -0
- package/dist/components/ui/input.mjs +17 -0
- package/dist/components/ui/table.cjs +68 -0
- package/dist/components/ui/table.mjs +65 -0
- package/dist/components/ui/textarea.cjs +22 -0
- package/dist/components/ui/textarea.mjs +16 -0
- package/dist/index.cjs +100 -0
- package/dist/index.mjs +95 -0
- package/dist/intl.d.ts +7 -0
- package/dist/lib/utils.cjs +11 -0
- package/dist/lib/{utils.js → utils.mjs} +1 -1
- package/dist/lib/validation.cjs +16 -0
- package/dist/lib/validation.d.ts +2 -2
- package/dist/lib/validation.mjs +10 -0
- package/dist/navigation.cjs +23 -0
- package/dist/navigation.mjs +21 -0
- package/dist/routes.cjs +74 -0
- package/dist/routes.mjs +68 -0
- package/dist/schema.cjs +62 -0
- package/dist/schema.mjs +53 -0
- package/dist/styles/globals.css +1 -0
- package/dist/ui/views.cjs +448 -0
- package/dist/ui/views.d.ts +6 -5
- package/dist/ui/views.mjs +232 -0
- package/package.json +14 -10
- package/dist/actions/index.js +0 -149
- package/dist/components/BlogStatsWidget.js +0 -17
- package/dist/components/RecentCommentsWidget.js +0 -24
- package/dist/components/RecentPostsWidget.js +0 -24
- package/dist/components/ui/button.js +0 -33
- package/dist/components/ui/card.js +0 -12
- package/dist/components/ui/input.js +0 -8
- package/dist/components/ui/table.js +0 -16
- package/dist/components/ui/textarea.js +0 -8
- package/dist/index.js +0 -98
- package/dist/lib/validation.js +0 -11
- package/dist/navigation.js +0 -21
- package/dist/routes.js +0 -55
- package/dist/schema.js +0 -60
- package/dist/ui/views.js +0 -119
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use server";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createComment = createComment;
|
|
8
|
+
exports.createPost = createPost;
|
|
9
|
+
exports.deletePost = deletePost;
|
|
10
|
+
exports.getComments = getComments;
|
|
11
|
+
exports.getPostById = getPostById;
|
|
12
|
+
exports.getPostBySlug = getPostBySlug;
|
|
13
|
+
exports.getPosts = getPosts;
|
|
14
|
+
exports.updatePost = updatePost;
|
|
15
|
+
var _server = require("@arch-cadre/core/server");
|
|
16
|
+
var _drizzleOrm = require("drizzle-orm");
|
|
17
|
+
var _cache = require("next/cache");
|
|
18
|
+
var _validation = require("../lib/validation.cjs");
|
|
19
|
+
var _schema = require("../schema.cjs");
|
|
20
|
+
async function createPost(data) {
|
|
21
|
+
try {
|
|
22
|
+
const {
|
|
23
|
+
user
|
|
24
|
+
} = await (0, _server.getCurrentSession)();
|
|
25
|
+
if (!user) throw new Error("Unauthorized");
|
|
26
|
+
const validated = _validation.postSchema.parse(data);
|
|
27
|
+
await _server.db.insert(_schema.postsTable).values({
|
|
28
|
+
...validated,
|
|
29
|
+
authorId: user.id
|
|
30
|
+
});
|
|
31
|
+
(0, _cache.revalidatePath)("/blog");
|
|
32
|
+
return {
|
|
33
|
+
success: true
|
|
34
|
+
};
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error("[BlogModule:Actions] createPost failed:", error);
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
error: error.message
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function getPosts() {
|
|
44
|
+
try {
|
|
45
|
+
return await _server.db.select({
|
|
46
|
+
id: _schema.postsTable.id,
|
|
47
|
+
title: _schema.postsTable.title,
|
|
48
|
+
slug: _schema.postsTable.slug,
|
|
49
|
+
content: _schema.postsTable.content,
|
|
50
|
+
createdAt: _schema.postsTable.createdAt,
|
|
51
|
+
author: {
|
|
52
|
+
name: _server.userTable.name
|
|
53
|
+
}
|
|
54
|
+
}).from(_schema.postsTable).innerJoin(_server.userTable, (0, _drizzleOrm.eq)(_schema.postsTable.authorId, _server.userTable.id)).orderBy((0, _drizzleOrm.desc)(_schema.postsTable.createdAt));
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error("[BlogModule:Actions] getPosts failed:", error);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function getPostBySlug(slug) {
|
|
61
|
+
try {
|
|
62
|
+
const [post] = await _server.db.select({
|
|
63
|
+
id: _schema.postsTable.id,
|
|
64
|
+
title: _schema.postsTable.title,
|
|
65
|
+
slug: _schema.postsTable.slug,
|
|
66
|
+
content: _schema.postsTable.content,
|
|
67
|
+
createdAt: _schema.postsTable.createdAt,
|
|
68
|
+
author: {
|
|
69
|
+
name: _server.userTable.name
|
|
70
|
+
}
|
|
71
|
+
}).from(_schema.postsTable).innerJoin(_server.userTable, (0, _drizzleOrm.eq)(_schema.postsTable.authorId, _server.userTable.id)).where((0, _drizzleOrm.eq)(_schema.postsTable.slug, slug));
|
|
72
|
+
return post || null;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error("[BlogModule:Actions] getPostBySlug failed:", error);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function getPostById(id) {
|
|
79
|
+
try {
|
|
80
|
+
const [post] = await _server.db.select().from(_schema.postsTable).where((0, _drizzleOrm.eq)(_schema.postsTable.id, id));
|
|
81
|
+
return post || null;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error("[BlogModule:Actions] getPostById failed:", error);
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function getComments(postId) {
|
|
88
|
+
try {
|
|
89
|
+
return await _server.db.select({
|
|
90
|
+
id: _schema.commentsTable.id,
|
|
91
|
+
content: _schema.commentsTable.content,
|
|
92
|
+
createdAt: _schema.commentsTable.createdAt,
|
|
93
|
+
author: {
|
|
94
|
+
name: _server.userTable.name,
|
|
95
|
+
image: _server.userTable.image
|
|
96
|
+
}
|
|
97
|
+
}).from(_schema.commentsTable).innerJoin(_server.userTable, (0, _drizzleOrm.eq)(_schema.commentsTable.authorId, _server.userTable.id)).where((0, _drizzleOrm.eq)(_schema.commentsTable.postId, postId)).orderBy((0, _drizzleOrm.desc)(_schema.commentsTable.createdAt));
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error("[BlogModule:Actions] getComments failed:", error);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function createComment(data) {
|
|
104
|
+
try {
|
|
105
|
+
const {
|
|
106
|
+
user
|
|
107
|
+
} = await (0, _server.getCurrentSession)();
|
|
108
|
+
if (!user) throw new Error("Must be logged in to comment");
|
|
109
|
+
const validated = _validation.commentSchema.parse(data);
|
|
110
|
+
await _server.db.insert(_schema.commentsTable).values({
|
|
111
|
+
content: validated.content,
|
|
112
|
+
postId: validated.postId,
|
|
113
|
+
authorId: user.id
|
|
114
|
+
});
|
|
115
|
+
(0, _cache.revalidatePath)(`/blog`);
|
|
116
|
+
return {
|
|
117
|
+
success: true
|
|
118
|
+
};
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("[BlogModule:Actions] createComment failed:", error);
|
|
121
|
+
return {
|
|
122
|
+
success: false,
|
|
123
|
+
error: error.message
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function deletePost(id) {
|
|
128
|
+
try {
|
|
129
|
+
await _server.db.delete(_schema.postsTable).where((0, _drizzleOrm.eq)(_schema.postsTable.id, id));
|
|
130
|
+
(0, _cache.revalidatePath)("/blog");
|
|
131
|
+
return {
|
|
132
|
+
success: true
|
|
133
|
+
};
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error("[BlogModule:Actions] deletePost failed:", error);
|
|
136
|
+
return {
|
|
137
|
+
success: false,
|
|
138
|
+
error: error.message
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function updatePost(id, data) {
|
|
143
|
+
try {
|
|
144
|
+
const validated = _validation.postSchema.parse(data);
|
|
145
|
+
await _server.db.update(_schema.postsTable).set(validated).where((0, _drizzleOrm.eq)(_schema.postsTable.id, id));
|
|
146
|
+
(0, _cache.revalidatePath)("/blog");
|
|
147
|
+
(0, _cache.revalidatePath)(`/blog/${validated.slug}`);
|
|
148
|
+
return {
|
|
149
|
+
success: true
|
|
150
|
+
};
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error("[BlogModule:Actions] updatePost failed:", error);
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
error: error.message
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -7,43 +7,10 @@ export declare function createPost(data: z.infer<typeof postSchema>): Promise<{
|
|
|
7
7
|
success: boolean;
|
|
8
8
|
error: any;
|
|
9
9
|
}>;
|
|
10
|
-
export declare function getPosts(): Promise<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
content: string;
|
|
15
|
-
createdAt: Date;
|
|
16
|
-
author: {
|
|
17
|
-
name: string;
|
|
18
|
-
};
|
|
19
|
-
}[]>;
|
|
20
|
-
export declare function getPostBySlug(slug: string): Promise<{
|
|
21
|
-
id: string;
|
|
22
|
-
title: string;
|
|
23
|
-
slug: string;
|
|
24
|
-
content: string;
|
|
25
|
-
createdAt: Date;
|
|
26
|
-
author: {
|
|
27
|
-
name: string;
|
|
28
|
-
};
|
|
29
|
-
}>;
|
|
30
|
-
export declare function getPostById(id: string): Promise<{
|
|
31
|
-
id: string;
|
|
32
|
-
title: string;
|
|
33
|
-
slug: string;
|
|
34
|
-
content: string;
|
|
35
|
-
authorId: string;
|
|
36
|
-
createdAt: Date;
|
|
37
|
-
}>;
|
|
38
|
-
export declare function getComments(postId: string): Promise<{
|
|
39
|
-
id: string;
|
|
40
|
-
content: string;
|
|
41
|
-
createdAt: Date;
|
|
42
|
-
author: {
|
|
43
|
-
name: string;
|
|
44
|
-
image: string | null;
|
|
45
|
-
};
|
|
46
|
-
}[]>;
|
|
10
|
+
export declare function getPosts(): Promise<any>;
|
|
11
|
+
export declare function getPostBySlug(slug: string): Promise<any>;
|
|
12
|
+
export declare function getPostById(id: string): Promise<any>;
|
|
13
|
+
export declare function getComments(postId: string): Promise<any>;
|
|
47
14
|
export declare function createComment(data: z.infer<typeof commentSchema>): Promise<{
|
|
48
15
|
success: boolean;
|
|
49
16
|
error?: undefined;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { db, getCurrentSession, userTable } from "@arch-cadre/core/server";
|
|
3
|
+
import { desc, eq } from "drizzle-orm";
|
|
4
|
+
import { revalidatePath } from "next/cache";
|
|
5
|
+
import { commentSchema, postSchema } from "../lib/validation.mjs";
|
|
6
|
+
import { commentsTable, postsTable } from "../schema.mjs";
|
|
7
|
+
export async function createPost(data) {
|
|
8
|
+
try {
|
|
9
|
+
const { user } = await getCurrentSession();
|
|
10
|
+
if (!user) throw new Error("Unauthorized");
|
|
11
|
+
const validated = postSchema.parse(data);
|
|
12
|
+
await db.insert(postsTable).values({
|
|
13
|
+
...validated,
|
|
14
|
+
authorId: user.id
|
|
15
|
+
});
|
|
16
|
+
revalidatePath("/blog");
|
|
17
|
+
return { success: true };
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error("[BlogModule:Actions] createPost failed:", error);
|
|
20
|
+
return { success: false, error: error.message };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function getPosts() {
|
|
24
|
+
try {
|
|
25
|
+
return await db.select({
|
|
26
|
+
id: postsTable.id,
|
|
27
|
+
title: postsTable.title,
|
|
28
|
+
slug: postsTable.slug,
|
|
29
|
+
content: postsTable.content,
|
|
30
|
+
createdAt: postsTable.createdAt,
|
|
31
|
+
author: {
|
|
32
|
+
name: userTable.name
|
|
33
|
+
}
|
|
34
|
+
}).from(postsTable).innerJoin(userTable, eq(postsTable.authorId, userTable.id)).orderBy(desc(postsTable.createdAt));
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error("[BlogModule:Actions] getPosts failed:", error);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export async function getPostBySlug(slug) {
|
|
41
|
+
try {
|
|
42
|
+
const [post] = await db.select({
|
|
43
|
+
id: postsTable.id,
|
|
44
|
+
title: postsTable.title,
|
|
45
|
+
slug: postsTable.slug,
|
|
46
|
+
content: postsTable.content,
|
|
47
|
+
createdAt: postsTable.createdAt,
|
|
48
|
+
author: {
|
|
49
|
+
name: userTable.name
|
|
50
|
+
}
|
|
51
|
+
}).from(postsTable).innerJoin(userTable, eq(postsTable.authorId, userTable.id)).where(eq(postsTable.slug, slug));
|
|
52
|
+
return post || null;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error("[BlogModule:Actions] getPostBySlug failed:", error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export async function getPostById(id) {
|
|
59
|
+
try {
|
|
60
|
+
const [post] = await db.select().from(postsTable).where(eq(postsTable.id, id));
|
|
61
|
+
return post || null;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error("[BlogModule:Actions] getPostById failed:", error);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export async function getComments(postId) {
|
|
68
|
+
try {
|
|
69
|
+
return await db.select({
|
|
70
|
+
id: commentsTable.id,
|
|
71
|
+
content: commentsTable.content,
|
|
72
|
+
createdAt: commentsTable.createdAt,
|
|
73
|
+
author: {
|
|
74
|
+
name: userTable.name,
|
|
75
|
+
image: userTable.image
|
|
76
|
+
}
|
|
77
|
+
}).from(commentsTable).innerJoin(userTable, eq(commentsTable.authorId, userTable.id)).where(eq(commentsTable.postId, postId)).orderBy(desc(commentsTable.createdAt));
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error("[BlogModule:Actions] getComments failed:", error);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export async function createComment(data) {
|
|
84
|
+
try {
|
|
85
|
+
const { user } = await getCurrentSession();
|
|
86
|
+
if (!user) throw new Error("Must be logged in to comment");
|
|
87
|
+
const validated = commentSchema.parse(data);
|
|
88
|
+
await db.insert(commentsTable).values({
|
|
89
|
+
content: validated.content,
|
|
90
|
+
postId: validated.postId,
|
|
91
|
+
authorId: user.id
|
|
92
|
+
});
|
|
93
|
+
revalidatePath(`/blog`);
|
|
94
|
+
return { success: true };
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("[BlogModule:Actions] createComment failed:", error);
|
|
97
|
+
return { success: false, error: error.message };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export async function deletePost(id) {
|
|
101
|
+
try {
|
|
102
|
+
await db.delete(postsTable).where(eq(postsTable.id, id));
|
|
103
|
+
revalidatePath("/blog");
|
|
104
|
+
return { success: true };
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error("[BlogModule:Actions] deletePost failed:", error);
|
|
107
|
+
return { success: false, error: error.message };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export async function updatePost(id, data) {
|
|
111
|
+
try {
|
|
112
|
+
const validated = postSchema.parse(data);
|
|
113
|
+
await db.update(postsTable).set(validated).where(eq(postsTable.id, id));
|
|
114
|
+
revalidatePath("/blog");
|
|
115
|
+
revalidatePath(`/blog/${validated.slug}`);
|
|
116
|
+
return { success: true };
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("[BlogModule:Actions] updatePost failed:", error);
|
|
119
|
+
return { success: false, error: error.message };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = BlogStatsWidget;
|
|
7
|
+
var _server = require("@arch-cadre/core/server");
|
|
8
|
+
var _server2 = require("@arch-cadre/intl/server");
|
|
9
|
+
var _ui = require("@arch-cadre/ui");
|
|
10
|
+
var _drizzleOrm = require("drizzle-orm");
|
|
11
|
+
var _lucideReact = require("lucide-react");
|
|
12
|
+
var React = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _schema = require("../schema.cjs");
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
async function BlogStatsWidget() {
|
|
17
|
+
const {
|
|
18
|
+
t
|
|
19
|
+
} = await (0, _server2.getTranslation)();
|
|
20
|
+
const [postsCount] = await _server.db.select({
|
|
21
|
+
count: (0, _drizzleOrm.sql)`count(*)`
|
|
22
|
+
}).from(_schema.postsTable);
|
|
23
|
+
const [commentsCount] = await _server.db.select({
|
|
24
|
+
count: (0, _drizzleOrm.sql)`count(*)`
|
|
25
|
+
}).from(_schema.commentsTable);
|
|
26
|
+
return /* @__PURE__ */React.createElement("div", {
|
|
27
|
+
className: "grid gap-4 md:grid-cols-2 lg:grid-cols-2"
|
|
28
|
+
}, /* @__PURE__ */React.createElement(_ui.Card, null, /* @__PURE__ */React.createElement(_ui.CardHeader, {
|
|
29
|
+
className: "flex flex-row items-center justify-between space-y-0 pb-2"
|
|
30
|
+
}, /* @__PURE__ */React.createElement(_ui.CardTitle, {
|
|
31
|
+
className: "text-sm font-medium"
|
|
32
|
+
}, t("Total Posts")), /* @__PURE__ */React.createElement(_lucideReact.FileText, {
|
|
33
|
+
className: "h-4 w-4 text-muted-foreground"
|
|
34
|
+
})), /* @__PURE__ */React.createElement(_ui.CardContent, null, /* @__PURE__ */React.createElement("div", {
|
|
35
|
+
className: "text-2xl font-bold"
|
|
36
|
+
}, postsCount?.count || 0))), /* @__PURE__ */React.createElement(_ui.Card, null, /* @__PURE__ */React.createElement(_ui.CardHeader, {
|
|
37
|
+
className: "flex flex-row items-center justify-between space-y-0 pb-2"
|
|
38
|
+
}, /* @__PURE__ */React.createElement(_ui.CardTitle, {
|
|
39
|
+
className: "text-sm font-medium"
|
|
40
|
+
}, t("Total Comments")), /* @__PURE__ */React.createElement(_lucideReact.MessageSquare, {
|
|
41
|
+
className: "h-4 w-4 text-muted-foreground"
|
|
42
|
+
})), /* @__PURE__ */React.createElement(_ui.CardContent, null, /* @__PURE__ */React.createElement("div", {
|
|
43
|
+
className: "text-2xl font-bold"
|
|
44
|
+
}, commentsCount?.count || 0))));
|
|
45
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export default function BlogStatsWidget(): Promise<React.JSX.Element>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { db } from "@arch-cadre/core/server";
|
|
2
|
+
import { getTranslation } from "@arch-cadre/intl/server";
|
|
3
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@arch-cadre/ui";
|
|
4
|
+
import { sql } from "drizzle-orm";
|
|
5
|
+
import { FileText, MessageSquare } from "lucide-react";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { commentsTable, postsTable } from "../schema.mjs";
|
|
8
|
+
export default async function BlogStatsWidget() {
|
|
9
|
+
const { t } = await getTranslation();
|
|
10
|
+
const [postsCount] = await db.select({ count: sql`count(*)` }).from(postsTable);
|
|
11
|
+
const [commentsCount] = await db.select({ count: sql`count(*)` }).from(commentsTable);
|
|
12
|
+
return /* @__PURE__ */ React.createElement("div", { className: "grid gap-4 md:grid-cols-2 lg:grid-cols-2" }, /* @__PURE__ */ React.createElement(Card, null, /* @__PURE__ */ React.createElement(CardHeader, { className: "flex flex-row items-center justify-between space-y-0 pb-2" }, /* @__PURE__ */ React.createElement(CardTitle, { className: "text-sm font-medium" }, t("Total Posts")), /* @__PURE__ */ React.createElement(FileText, { className: "h-4 w-4 text-muted-foreground" })), /* @__PURE__ */ React.createElement(CardContent, null, /* @__PURE__ */ React.createElement("div", { className: "text-2xl font-bold" }, postsCount?.count || 0))), /* @__PURE__ */ React.createElement(Card, null, /* @__PURE__ */ React.createElement(CardHeader, { className: "flex flex-row items-center justify-between space-y-0 pb-2" }, /* @__PURE__ */ React.createElement(CardTitle, { className: "text-sm font-medium" }, t("Total Comments")), /* @__PURE__ */ React.createElement(MessageSquare, { className: "h-4 w-4 text-muted-foreground" })), /* @__PURE__ */ React.createElement(CardContent, null, /* @__PURE__ */ React.createElement("div", { className: "text-2xl font-bold" }, commentsCount?.count || 0))));
|
|
13
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = RecentCommentsWidget;
|
|
7
|
+
var _server = require("@arch-cadre/core/server");
|
|
8
|
+
var _server2 = require("@arch-cadre/intl/server");
|
|
9
|
+
var _ui = require("@arch-cadre/ui");
|
|
10
|
+
var _drizzleOrm = require("drizzle-orm");
|
|
11
|
+
var React = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _schema = require("../schema.cjs");
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
async function RecentCommentsWidget() {
|
|
16
|
+
const {
|
|
17
|
+
t
|
|
18
|
+
} = await (0, _server2.getTranslation)();
|
|
19
|
+
const comments = await _server.db.select({
|
|
20
|
+
id: _schema.commentsTable.id,
|
|
21
|
+
content: _schema.commentsTable.content,
|
|
22
|
+
createdAt: _schema.commentsTable.createdAt,
|
|
23
|
+
author: {
|
|
24
|
+
name: _server.userTable.name,
|
|
25
|
+
image: _server.userTable.image
|
|
26
|
+
}
|
|
27
|
+
}).from(_schema.commentsTable).leftJoin(_server.userTable, (0, _drizzleOrm.eq)(_schema.commentsTable.authorId, _server.userTable.id)).orderBy((0, _drizzleOrm.desc)(_schema.commentsTable.createdAt)).limit(5);
|
|
28
|
+
return /* @__PURE__ */React.createElement(_ui.Card, null, /* @__PURE__ */React.createElement(_ui.CardHeader, null, /* @__PURE__ */React.createElement(_ui.CardTitle, null, t("Recent Comments")), /* @__PURE__ */React.createElement(_ui.CardDescription, null, t("What readers are saying about your posts."))), /* @__PURE__ */React.createElement(_ui.CardContent, {
|
|
29
|
+
className: "grid gap-8"
|
|
30
|
+
}, comments.map(comment => /* @__PURE__ */React.createElement("div", {
|
|
31
|
+
key: comment.id,
|
|
32
|
+
className: "flex items-center gap-4"
|
|
33
|
+
}, /* @__PURE__ */React.createElement(_ui.Avatar, {
|
|
34
|
+
className: "h-9 w-9"
|
|
35
|
+
}, /* @__PURE__ */React.createElement(_ui.AvatarImage, {
|
|
36
|
+
src: comment.author?.image || "",
|
|
37
|
+
alt: "Avatar"
|
|
38
|
+
}), /* @__PURE__ */React.createElement(_ui.AvatarFallback, null, comment.author?.name?.substring(0, 2).toUpperCase() || "CM")), /* @__PURE__ */React.createElement("div", {
|
|
39
|
+
className: "grid gap-1"
|
|
40
|
+
}, /* @__PURE__ */React.createElement("p", {
|
|
41
|
+
className: "text-sm font-medium leading-none line-clamp-1"
|
|
42
|
+
}, comment.content), /* @__PURE__ */React.createElement("p", {
|
|
43
|
+
className: "text-sm text-muted-foreground"
|
|
44
|
+
}, comment.author?.name || t("Anonymous"), " \u2022", " ", new Date(comment.createdAt).toLocaleDateString())))), comments.length === 0 && /* @__PURE__ */React.createElement("div", {
|
|
45
|
+
className: "text-center py-4 text-muted-foreground"
|
|
46
|
+
}, t("No comments yet."))));
|
|
47
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export default function RecentCommentsWidget(): Promise<React.JSX.Element>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { db, userTable } from "@arch-cadre/core/server";
|
|
2
|
+
import { getTranslation } from "@arch-cadre/intl/server";
|
|
3
|
+
import {
|
|
4
|
+
Avatar,
|
|
5
|
+
AvatarFallback,
|
|
6
|
+
AvatarImage,
|
|
7
|
+
Card,
|
|
8
|
+
CardContent,
|
|
9
|
+
CardDescription,
|
|
10
|
+
CardHeader,
|
|
11
|
+
CardTitle
|
|
12
|
+
} from "@arch-cadre/ui";
|
|
13
|
+
import { desc, eq } from "drizzle-orm";
|
|
14
|
+
import * as React from "react";
|
|
15
|
+
import { commentsTable } from "../schema.mjs";
|
|
16
|
+
export default async function RecentCommentsWidget() {
|
|
17
|
+
const { t } = await getTranslation();
|
|
18
|
+
const comments = await db.select({
|
|
19
|
+
id: commentsTable.id,
|
|
20
|
+
content: commentsTable.content,
|
|
21
|
+
createdAt: commentsTable.createdAt,
|
|
22
|
+
author: {
|
|
23
|
+
name: userTable.name,
|
|
24
|
+
image: userTable.image
|
|
25
|
+
}
|
|
26
|
+
}).from(commentsTable).leftJoin(userTable, eq(commentsTable.authorId, userTable.id)).orderBy(desc(commentsTable.createdAt)).limit(5);
|
|
27
|
+
return /* @__PURE__ */ React.createElement(Card, null, /* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(CardTitle, null, t("Recent Comments")), /* @__PURE__ */ React.createElement(CardDescription, null, t("What readers are saying about your posts."))), /* @__PURE__ */ React.createElement(CardContent, { className: "grid gap-8" }, comments.map((comment) => /* @__PURE__ */ React.createElement("div", { key: comment.id, className: "flex items-center gap-4" }, /* @__PURE__ */ React.createElement(Avatar, { className: "h-9 w-9" }, /* @__PURE__ */ React.createElement(AvatarImage, { src: comment.author?.image || "", alt: "Avatar" }), /* @__PURE__ */ React.createElement(AvatarFallback, null, comment.author?.name?.substring(0, 2).toUpperCase() || "CM")), /* @__PURE__ */ React.createElement("div", { className: "grid gap-1" }, /* @__PURE__ */ React.createElement("p", { className: "text-sm font-medium leading-none line-clamp-1" }, comment.content), /* @__PURE__ */ React.createElement("p", { className: "text-sm text-muted-foreground" }, comment.author?.name || t("Anonymous"), " \u2022", " ", new Date(comment.createdAt).toLocaleDateString())))), comments.length === 0 && /* @__PURE__ */ React.createElement("div", { className: "text-center py-4 text-muted-foreground" }, t("No comments yet."))));
|
|
28
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = RecentPostsWidget;
|
|
7
|
+
var _server = require("@arch-cadre/core/server");
|
|
8
|
+
var _server2 = require("@arch-cadre/intl/server");
|
|
9
|
+
var _ui = require("@arch-cadre/ui");
|
|
10
|
+
var _drizzleOrm = require("drizzle-orm");
|
|
11
|
+
var React = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _schema = require("../schema.cjs");
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
async function RecentPostsWidget() {
|
|
16
|
+
const {
|
|
17
|
+
t
|
|
18
|
+
} = await (0, _server2.getTranslation)();
|
|
19
|
+
const posts = await _server.db.select({
|
|
20
|
+
id: _schema.postsTable.id,
|
|
21
|
+
title: _schema.postsTable.title,
|
|
22
|
+
createdAt: _schema.postsTable.createdAt,
|
|
23
|
+
author: {
|
|
24
|
+
name: _server.userTable.name,
|
|
25
|
+
image: _server.userTable.image
|
|
26
|
+
}
|
|
27
|
+
}).from(_schema.postsTable).leftJoin(_server.userTable, (0, _drizzleOrm.eq)(_schema.postsTable.authorId, _server.userTable.id)).orderBy((0, _drizzleOrm.desc)(_schema.postsTable.createdAt)).limit(5);
|
|
28
|
+
return /* @__PURE__ */React.createElement(_ui.Card, null, /* @__PURE__ */React.createElement(_ui.CardHeader, null, /* @__PURE__ */React.createElement(_ui.CardTitle, null, t("Recent Posts")), /* @__PURE__ */React.createElement(_ui.CardDescription, null, t("The latest articles published on your blog."))), /* @__PURE__ */React.createElement(_ui.CardContent, {
|
|
29
|
+
className: "grid gap-8"
|
|
30
|
+
}, posts.map(post => /* @__PURE__ */React.createElement("div", {
|
|
31
|
+
key: post.id,
|
|
32
|
+
className: "flex items-center gap-4"
|
|
33
|
+
}, /* @__PURE__ */React.createElement(_ui.Avatar, {
|
|
34
|
+
className: "h-9 w-9"
|
|
35
|
+
}, /* @__PURE__ */React.createElement(_ui.AvatarImage, {
|
|
36
|
+
src: post.author?.image || "",
|
|
37
|
+
alt: "Avatar"
|
|
38
|
+
}), /* @__PURE__ */React.createElement(_ui.AvatarFallback, null, post.author?.name?.substring(0, 2).toUpperCase() || "AU")), /* @__PURE__ */React.createElement("div", {
|
|
39
|
+
className: "grid gap-1"
|
|
40
|
+
}, /* @__PURE__ */React.createElement("p", {
|
|
41
|
+
className: "text-sm font-medium leading-none"
|
|
42
|
+
}, post.title), /* @__PURE__ */React.createElement("p", {
|
|
43
|
+
className: "text-sm text-muted-foreground"
|
|
44
|
+
}, new Date(post.createdAt).toLocaleDateString())))), posts.length === 0 && /* @__PURE__ */React.createElement("div", {
|
|
45
|
+
className: "text-center py-4 text-muted-foreground"
|
|
46
|
+
}, t("No posts found."))));
|
|
47
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export default function RecentPostsWidget(): Promise<React.JSX.Element>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { db, userTable } from "@arch-cadre/core/server";
|
|
2
|
+
import { getTranslation } from "@arch-cadre/intl/server";
|
|
3
|
+
import {
|
|
4
|
+
Avatar,
|
|
5
|
+
AvatarFallback,
|
|
6
|
+
AvatarImage,
|
|
7
|
+
Card,
|
|
8
|
+
CardContent,
|
|
9
|
+
CardDescription,
|
|
10
|
+
CardHeader,
|
|
11
|
+
CardTitle
|
|
12
|
+
} from "@arch-cadre/ui";
|
|
13
|
+
import { desc, eq } from "drizzle-orm";
|
|
14
|
+
import * as React from "react";
|
|
15
|
+
import { postsTable } from "../schema.mjs";
|
|
16
|
+
export default async function RecentPostsWidget() {
|
|
17
|
+
const { t } = await getTranslation();
|
|
18
|
+
const posts = await db.select({
|
|
19
|
+
id: postsTable.id,
|
|
20
|
+
title: postsTable.title,
|
|
21
|
+
createdAt: postsTable.createdAt,
|
|
22
|
+
author: {
|
|
23
|
+
name: userTable.name,
|
|
24
|
+
image: userTable.image
|
|
25
|
+
}
|
|
26
|
+
}).from(postsTable).leftJoin(userTable, eq(postsTable.authorId, userTable.id)).orderBy(desc(postsTable.createdAt)).limit(5);
|
|
27
|
+
return /* @__PURE__ */ React.createElement(Card, null, /* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(CardTitle, null, t("Recent Posts")), /* @__PURE__ */ React.createElement(CardDescription, null, t("The latest articles published on your blog."))), /* @__PURE__ */ React.createElement(CardContent, { className: "grid gap-8" }, posts.map((post) => /* @__PURE__ */ React.createElement("div", { key: post.id, className: "flex items-center gap-4" }, /* @__PURE__ */ React.createElement(Avatar, { className: "h-9 w-9" }, /* @__PURE__ */ React.createElement(AvatarImage, { src: post.author?.image || "", alt: "Avatar" }), /* @__PURE__ */ React.createElement(AvatarFallback, null, post.author?.name?.substring(0, 2).toUpperCase() || "AU")), /* @__PURE__ */ React.createElement("div", { className: "grid gap-1" }, /* @__PURE__ */ React.createElement("p", { className: "text-sm font-medium leading-none" }, post.title), /* @__PURE__ */ React.createElement("p", { className: "text-sm text-muted-foreground" }, new Date(post.createdAt).toLocaleDateString())))), posts.length === 0 && /* @__PURE__ */ React.createElement("div", { className: "text-center py-4 text-muted-foreground" }, t("No posts found."))));
|
|
28
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buttonVariants = exports.Button = void 0;
|
|
7
|
+
var _reactSlot = require("@radix-ui/react-slot");
|
|
8
|
+
var _classVarianceAuthority = require("class-variance-authority");
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
var _utils = require("../../lib/utils.cjs");
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
|
+
const buttonVariants = exports.buttonVariants = (0, _classVarianceAuthority.cva)("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50", {
|
|
15
|
+
variants: {
|
|
16
|
+
variant: {
|
|
17
|
+
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
18
|
+
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
|
19
|
+
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
20
|
+
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
21
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
22
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
23
|
+
},
|
|
24
|
+
size: {
|
|
25
|
+
default: "h-9 px-4 py-2",
|
|
26
|
+
sm: "h-8 rounded-md px-3 text-xs",
|
|
27
|
+
lg: "h-10 rounded-md px-8",
|
|
28
|
+
icon: "size-9"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
defaultVariants: {
|
|
32
|
+
variant: "default",
|
|
33
|
+
size: "default"
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const Button = exports.Button = React.forwardRef(({
|
|
37
|
+
className,
|
|
38
|
+
variant,
|
|
39
|
+
size,
|
|
40
|
+
asChild = false,
|
|
41
|
+
...props
|
|
42
|
+
}, ref) => {
|
|
43
|
+
const Comp = asChild ? _reactSlot.Slot : "button";
|
|
44
|
+
return (0, _jsxRuntime.jsx)(Comp, {
|
|
45
|
+
className: (0, _utils.cn)(buttonVariants({
|
|
46
|
+
variant,
|
|
47
|
+
size,
|
|
48
|
+
className
|
|
49
|
+
})),
|
|
50
|
+
ref: ref,
|
|
51
|
+
...props
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
Button.displayName = "Button";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
2
|
+
import { cva } from "class-variance-authority";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { cn } from "../../lib/utils.mjs";
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default:
|
|
13
|
+
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
14
|
+
destructive:
|
|
15
|
+
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
|
16
|
+
outline:
|
|
17
|
+
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
18
|
+
secondary:
|
|
19
|
+
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
20
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
21
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
default: "h-9 px-4 py-2",
|
|
25
|
+
sm: "h-8 rounded-md px-3 text-xs",
|
|
26
|
+
lg: "h-10 rounded-md px-8",
|
|
27
|
+
icon: "size-9",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
defaultVariants: {
|
|
31
|
+
variant: "default",
|
|
32
|
+
size: "default",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
const Button = React.forwardRef(
|
|
37
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
38
|
+
const Comp = asChild ? Slot : "button";
|
|
39
|
+
return _jsx(Comp, {
|
|
40
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
41
|
+
ref: ref,
|
|
42
|
+
...props,
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
Button.displayName = "Button";
|
|
47
|
+
export { Button, buttonVariants };
|