From e04867efb77b60f751d053e24bafb98844b3b0b2 Mon Sep 17 00:00:00 2001 From: Kamil M <116840531+proxima812@users.noreply.github.com> Date: Tue, 10 Sep 2024 03:46:42 +0500 Subject: [PATCH] 1 --- src/components/Logo.astro | 18 ++ src/components/TG.astro | 38 +++ src/components/ZOOM.astro | 25 ++ src/layouts/Base.astro | 31 +- src/pages/admin.astro | 429 +++++++++++++------------- src/pages/api/addPost.json.ts | 4 - src/pages/api/updatePost/[id].json.ts | 19 +- src/pages/index.astro | 91 +++++- src/pages/signin.astro | 2 +- src/pages/signup.astro | 2 +- 10 files changed, 414 insertions(+), 245 deletions(-) create mode 100644 src/components/Logo.astro create mode 100644 src/components/TG.astro create mode 100644 src/components/ZOOM.astro diff --git a/src/components/Logo.astro b/src/components/Logo.astro new file mode 100644 index 0000000..da7ecef --- /dev/null +++ b/src/components/Logo.astro @@ -0,0 +1,18 @@ +--- + +--- + + + + + diff --git a/src/components/TG.astro b/src/components/TG.astro new file mode 100644 index 0000000..b5f68f2 --- /dev/null +++ b/src/components/TG.astro @@ -0,0 +1,38 @@ +--- + +--- + + + + + + + + + + + + + + + + diff --git a/src/components/ZOOM.astro b/src/components/ZOOM.astro new file mode 100644 index 0000000..034f445 --- /dev/null +++ b/src/components/ZOOM.astro @@ -0,0 +1,25 @@ +--- + +--- + + + + + + + + + + + + diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index c301588..9815d34 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -1,8 +1,10 @@ --- +import Logo from "@/components/Logo.astro" + const user = Astro.locals.user --- - + @@ -10,17 +12,20 @@ const user = Astro.locals.user Astro - -
-
+ +
+
+ { user ? ( -
+
diff --git a/src/pages/admin.astro b/src/pages/admin.astro index a76c9d0..79cb58e 100644 --- a/src/pages/admin.astro +++ b/src/pages/admin.astro @@ -1,4 +1,5 @@ --- +import Base from "@/layouts/Base.astro" import { db, Post, User, eq } from "astro:db" import { marked } from "marked" @@ -17,238 +18,250 @@ const posts = await db .where(eq(User.id, userId)) --- - - - - - - - Astro - - + +
Назад -

Привет, {user.username}!

- -
- + Привет, {user.username}! +
+
+ +
+ +
+
+ + name={"Link Description".toLowerCase().replace(" ", "-")}> +

до 100 символов

+
+ +
+ - - -
- -
- { - posts && - posts.map(post => ( -
-
-
- - -
-
- - -
-
- - -
- -
- - -
+
+ + +
+ +
+ { + posts && + posts.map(post => ( +
+
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
-
- )) +
+ + )) + } + + + + + - - + + - - - - + } + } catch (e) { + if (e instanceof Error) { + alert(e.message) + } + console.error(e) + } + }) + diff --git a/src/pages/api/addPost.json.ts b/src/pages/api/addPost.json.ts index 027bbbe..01c2f6e 100644 --- a/src/pages/api/addPost.json.ts +++ b/src/pages/api/addPost.json.ts @@ -23,10 +23,6 @@ export const POST: APIRoute = async ({ request, locals }) => { ) } - // const res = await db.insert(Post).values({ - // title: sanitize(title), - // description: sanitize(description), - // }) const res = await db.insert(Post).values({ title: title, diff --git a/src/pages/api/updatePost/[id].json.ts b/src/pages/api/updatePost/[id].json.ts index 991ba1d..10fe1dd 100644 --- a/src/pages/api/updatePost/[id].json.ts +++ b/src/pages/api/updatePost/[id].json.ts @@ -2,33 +2,38 @@ import type { APIRoute } from "astro" import { Post, db, eq } from "astro:db" export const PATCH: APIRoute = async ({ params, request }) => { - const { title, description } = await request.json() + const { title, description, link } = await request.json() const id = Number(params.id) - if (!id || !title || !description) { + if (!id || !title || !description || !link) { return new Response( JSON.stringify({ message: "Please provide all required fields.", success: false, }), { - status: 404, + status: 400, // Используйте 400 для ошибок клиента }, ) } try { - const res = await db.update(Post).set({ title, description, link }).where(eq(Post.id, id)) + // Выполните обновление поста в базе данных + const updateResult = await db + .update(Post) + .set({ title, description, link }) + .where(eq(Post.id, id)) - if (res) { + // Проверьте, что обновление прошло успешно + if (updateResult) { return new Response( JSON.stringify({ - message: "success", + message: "Post updated successfully", success: true, }), ) } else { - throw new Error("Update failed") + throw new Error("Update failed, no rows affected") } } catch (e) { console.error(e) diff --git a/src/pages/index.astro b/src/pages/index.astro index 0eb2a54..bbeffa8 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -3,6 +3,9 @@ import { Post, User, asc, db, eq } from "astro:db" import { marked } from "marked" import Layout from "../layouts/Base.astro" +import TG from "@/components/TG.astro" +import ZOOM from "@/components/ZOOM.astro" + // вовод с именами пользователей которые добавили пост const postsList = await db .select() @@ -14,21 +17,85 @@ const postsList = await db --- +
+

+ Ищите группы по интересу и по вашим задачам 👋 +

+

+ 12-ти шаговые группы, проекты и материалы разных зависимостей (сообществ) и направлений. +

+
+
{ postsList && - postsList.map((post: any) => ( - - )) + postsList + .sort((a, b) => b.Post.id - a.Post.id) + .map((post, index) => ( + + )) }
+ +
diff --git a/src/pages/signin.astro b/src/pages/signin.astro index 281b00d..8831ee3 100644 --- a/src/pages/signin.astro +++ b/src/pages/signin.astro @@ -3,7 +3,7 @@ import Base from "@/layouts/Base.astro" --- -
+

-
+