diff --git a/run.env.local b/run.env.local
new file mode 100644
index 00000000..3e93d529
--- /dev/null
+++ b/run.env.local
@@ -0,0 +1 @@
+bun --env-file=.env.local run --bun dev
\ No newline at end of file
diff --git a/run.prisma.env.local b/run.prisma.env.local
new file mode 100644
index 00000000..57a64842
--- /dev/null
+++ b/run.prisma.env.local
@@ -0,0 +1,3 @@
+bun --env-file=.env.local prisma db push
+bun --env-file=.env.local prisma db seed
+bun --env-file=.env.local run --bun build
\ No newline at end of file
diff --git a/src/app/api/forum/[id]/route.ts b/src/app/api/forum/[id]/route.ts
new file mode 100644
index 00000000..9a18775f
--- /dev/null
+++ b/src/app/api/forum/[id]/route.ts
@@ -0,0 +1,54 @@
+import backendLogger from "@/util/backendLogger";
+import { NextResponse } from "next/server";
+
+export { GET };
+
+async function GET(request: Request, { params }: { params: { id: string } }) {
+ try {
+ const { id } = params;
+
+ const data = await prisma.forum_Posting.findUnique({
+ where: {
+ id: id,
+ },
+ select: {
+ id: true,
+ diskusi: true,
+ isActive: true,
+ createdAt: true,
+ authorId: true,
+ Author: {
+ select: {
+ id: true,
+ username: true,
+ Profile: true,
+ },
+ },
+
+ _count: {
+ select: {
+ Forum_Komentar: true,
+ },
+ },
+ ForumMaster_StatusPosting: true,
+ forumMaster_StatusPostingId: true,
+ },
+ });
+
+ return NextResponse.json({
+ success: true,
+ message: "Success get data",
+ data: data,
+ });
+ } catch (error) {
+ backendLogger.error("Error get data forum", error);
+ return NextResponse.json(
+ {
+ success: false,
+ message: "Error get data forum",
+ reason: (error as Error).message,
+ },
+ { status: 500 }
+ );
+ }
+}
diff --git a/src/app/api/forum/forumku/[id]/route.ts b/src/app/api/forum/forumku/[id]/route.ts
new file mode 100644
index 00000000..4c430580
--- /dev/null
+++ b/src/app/api/forum/forumku/[id]/route.ts
@@ -0,0 +1,122 @@
+import { NextResponse } from "next/server";
+
+export { GET };
+
+async function GET(request: Request, { params }: { params: { id: string } }) {
+ try {
+ let fixData;
+ const { id } = params;
+ const { searchParams } = new URL(request.url);
+ const page = searchParams.get("page");
+ const takeData = 5;
+ const skipData = Number(page) * takeData - takeData;
+
+ console.log("id", id)
+ console.log("page >", page)
+
+ if (!page) {
+ fixData = await prisma.forum_Posting.findMany({
+ orderBy: {
+ createdAt: "desc",
+ },
+ where: {
+ authorId: id,
+ isActive: true,
+ },
+ select: {
+ id: true,
+ diskusi: true,
+ createdAt: true,
+ isActive: true,
+ authorId: true,
+ Author: {
+ select: {
+ id: true,
+ username: true,
+ Profile: {
+ select: {
+ id: true,
+ name: true,
+ imageId: true,
+ },
+ },
+ },
+ },
+ Forum_Komentar: {
+ where: {
+ isActive: true,
+ },
+ },
+ ForumMaster_StatusPosting: {
+ select: {
+ id: true,
+ status: true,
+ },
+ },
+ forumMaster_StatusPostingId: true,
+ },
+ });
+ } else {
+ fixData = await prisma.forum_Posting.findMany({
+ take: takeData,
+ skip: skipData,
+ orderBy: {
+ createdAt: "desc",
+ },
+ where: {
+ authorId: id,
+ isActive: true,
+ },
+ select: {
+ id: true,
+ diskusi: true,
+ createdAt: true,
+ isActive: true,
+ authorId: true,
+ Author: {
+ select: {
+ id: true,
+ username: true,
+ Profile: {
+ select: {
+ id: true,
+ name: true,
+ imageId: true,
+ },
+ },
+ },
+ },
+ Forum_Komentar: {
+ where: {
+ isActive: true,
+ },
+ },
+ ForumMaster_StatusPosting: {
+ select: {
+ id: true,
+ status: true,
+ },
+ },
+ forumMaster_StatusPostingId: true,
+ },
+ });
+ }
+
+ return NextResponse.json({
+ success: true,
+ message: "Berhasil mendapatkan data",
+ data: fixData,
+ });
+ } catch (error) {
+ return NextResponse.json(
+ {
+ success: false,
+ message: "Gagal mendapatkan data",
+ error: (error as Error).message,
+ },
+ {
+ status: 500,
+ }
+ );
+ }
+}
diff --git a/src/app/api/forum/route.ts b/src/app/api/forum/route.ts
index 9188747e..6c53c6d2 100644
--- a/src/app/api/forum/route.ts
+++ b/src/app/api/forum/route.ts
@@ -9,9 +9,10 @@ export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const page = searchParams.get("page");
const search = searchParams.get("search");
- const takeData = 4
+ const takeData = 5;
const skipData = Number(page) * takeData - takeData;
+
if (!page) {
fixData = await prisma.forum_Posting.findMany({
orderBy: {
diff --git a/src/app/dev/forum/edit/posting/[id]/page.tsx b/src/app/dev/forum/edit/posting/[id]/page.tsx
index 292059f4..726a9ff6 100644
--- a/src/app/dev/forum/edit/posting/[id]/page.tsx
+++ b/src/app/dev/forum/edit/posting/[id]/page.tsx
@@ -1,13 +1,10 @@
import { Forum_EditPosting } from "@/app_modules/forum";
-import { forum_getOnePostingById } from "@/app_modules/forum/fun/get/get_one_posting_by_id";
-export default async function Page({ params }: { params: { id: string } }) {
- let postingId = params.id;
- const dataPosting = await forum_getOnePostingById(postingId)
+export default async function Page() {
return (
<>
-
+
>
);
}
diff --git a/src/app/dev/forum/forumku/[id]/layout.tsx b/src/app/dev/forum/forumku/[id]/layout.tsx
index 1043a279..8e0ddbea 100644
--- a/src/app/dev/forum/forumku/[id]/layout.tsx
+++ b/src/app/dev/forum/forumku/[id]/layout.tsx
@@ -1,22 +1,14 @@
import { LayoutForum_Forumku } from "@/app_modules/forum";
-import { user_getOneByUserId } from "@/app_modules/home/fun/get/get_one_user_by_id";
import React from "react";
export default async function Layout({
children,
- params,
}: {
children: React.ReactNode;
- params: { id: string };
}) {
- const authorId = params.id;
- const dataAuthor = await user_getOneByUserId(authorId);
-
return (
<>
-
- {children}
-
+ {children}
>
);
}
diff --git a/src/app/dev/forum/forumku/[id]/page.tsx b/src/app/dev/forum/forumku/[id]/page.tsx
index b4d4391f..81cdd338 100644
--- a/src/app/dev/forum/forumku/[id]/page.tsx
+++ b/src/app/dev/forum/forumku/[id]/page.tsx
@@ -34,8 +34,6 @@ export default async function Page({ params }: { params: { id: string } }) {
return (
<>
diff --git a/src/app/zCoba/skeleton/page.tsx b/src/app/zCoba/skeleton/page.tsx
index 83058314..5e0c03ad 100644
--- a/src/app/zCoba/skeleton/page.tsx
+++ b/src/app/zCoba/skeleton/page.tsx
@@ -6,7 +6,7 @@ import {
UIGlobal_LayoutTamplate,
} from "@/app_modules/_global/ui";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
-import { Button, Grid, Skeleton, Stack } from "@mantine/core";
+import { Button, Center, Grid, Group, Skeleton, Stack } from "@mantine/core";
import Link from "next/link";
export default function Voting_ComponentSkeletonViewPuh() {
@@ -15,13 +15,34 @@ export default function Voting_ComponentSkeletonViewPuh() {
}
>
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {/*
{Array.from({ length: 4 }).map((_, i) => (
))}
-
+ */}
>
);
diff --git a/src/app_modules/auth/invalid_user/view.tsx b/src/app_modules/auth/invalid_user/view.tsx
index 737c74b1..fddda4a7 100644
--- a/src/app_modules/auth/invalid_user/view.tsx
+++ b/src/app_modules/auth/invalid_user/view.tsx
@@ -2,11 +2,13 @@
import { MainColor } from "@/app_modules/_global/color";
import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui";
-import { Button, Stack, Text, Title } from "@mantine/core";
+import { Button, Stack, Title } from "@mantine/core";
import { useRouter } from "next/navigation";
+import { useState } from "react";
export default function InvalidUser() {
const router = useRouter();
+ const [isLoading, setIsLoading] = useState(false);
const deleteCookie = async () => {
const sessionKey = process.env.NEXT_PUBLIC_BASE_SESSION_KEY!;
if (!sessionKey) {
@@ -14,12 +16,15 @@ export default function InvalidUser() {
}
try {
+ setIsLoading(true);
await fetch("/api/auth/logout", {
method: "GET",
});
router.push("/login");
} catch (error) {
console.error("Gagal menghapus cookie:", error);
+ } finally {
+ setIsLoading(false);
}
};
@@ -32,6 +37,8 @@ export default function InvalidUser() {
Invalid User
" || diskusi === "" || diskusi.length > 500
- ? ""
- : `1px solid ${AccentColor.yellow}`,
backgroundColor:
- diskusi === "
" || diskusi === "" || diskusi.length > 500
+ diskusi === "
" ||
+ diskusi === "" ||
+ diskusi.length >= maxLength
? ""
: MainColor.yellow,
}}
disabled={
- diskusi === "
" || diskusi === "" || diskusi.length > 500
+ diskusi === "
" ||
+ diskusi === "" ||
+ diskusi.length >= maxLength
? true
: false
}
loaderPosition="center"
- loading={loading ? true : false}
+ loading={loading}
radius={"xl"}
+ c={"black"}
onClick={() => {
onUpdate();
}}
diff --git a/src/app_modules/forum/forumku/index.tsx b/src/app_modules/forum/forumku/index.tsx
index 82bfeb22..6c437185 100644
--- a/src/app_modules/forum/forumku/index.tsx
+++ b/src/app_modules/forum/forumku/index.tsx
@@ -1,9 +1,7 @@
"use client";
import { RouterForum } from "@/lib/router_hipmi/router_forum";
-import {
- AccentColor
-} from "@/app_modules/_global/color/color_pallet";
+import { AccentColor } from "@/app_modules/_global/color/color_pallet";
import { MODEL_USER } from "@/app_modules/home/model/interface";
import {
ActionIcon,
@@ -14,91 +12,149 @@ import {
Text,
rem,
} from "@mantine/core";
-import { useWindowScroll } from "@mantine/hooks";
+import { useShallowEffect, useWindowScroll } from "@mantine/hooks";
import { IconPencilPlus, IconSearchOff } from "@tabler/icons-react";
import _ from "lodash";
import { ScrollOnly } from "next-scroll-loader";
-import { useRouter } from "next/navigation";
+import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import ComponentForum_ForumkuMainCardView from "../component/forumku_component/forumku_view";
import { forum_getAllPostingByAuhtorId } from "../fun/get/get_list_posting_by_author_id";
import { MODEL_FORUM_POSTING } from "../model/interface";
import ComponentForum_ViewForumProfile from "./forum_profile";
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
+import { apiGetUserById } from "@/app_modules/_global/lib/api_user";
+import backendLogger from "@/util/backendLogger";
+import { clientLogger } from "@/util/clientLogger";
+import { apiGetForumkuById } from "../component/api_fetch_forum";
+import {
+ Forum_SkeletonCard,
+ Forum_SkeletonForumku,
+} from "../component/skeleton_view";
+import { data } from "autoprefixer";
+import { Forum_ComponentIsDataEmpty } from "../component/other_component";
export default function Forum_Forumku({
- auhtorSelectedData,
- dataPosting,
totalPosting,
userLoginId,
}: {
- auhtorSelectedData: MODEL_USER;
- dataPosting: MODEL_FORUM_POSTING[];
totalPosting: number;
userLoginId: string;
}) {
const router = useRouter();
- const [data, setData] = useState(dataPosting);
+ const params = useParams<{ id: string }>();
+ const userId = params.id;
+ const [dataUser, setDataUser] = useState(null);
+ const [dataPosting, setDataPosting] = useState([]);
const [activePage, setActivePage] = useState(1);
- const [scroll, scrollTo] = useWindowScroll();
- const [loadingCreate, setLoadingCreate] = useState(false);
+ useShallowEffect(() => {
+ const handleLoadDataUser = async () => {
+ try {
+ const response = await apiGetUserById({
+ id: userId,
+ });
+
+ if (response) {
+ console.log("response", response);
+ setDataUser(response.data);
+ }
+ } catch (error) {
+ clientLogger.error("Error get user", error);
+ }
+ };
+
+ handleLoadDataUser();
+ }, []);
+
+ useShallowEffect(() => {
+ handleLoadDataForum();
+ }, []);
+
+ const handleLoadDataForum = async () => {
+ try {
+ const response = await apiGetForumkuById({
+ id: userId,
+ page: "1",
+ });
+
+ if (response.success) {
+ setDataPosting(response.data);
+ setActivePage(1);
+ }
+ } catch (error) {
+ clientLogger.error("Error get data forum");
+ setDataPosting([]);
+ }
+ };
+
+ const handleMoreData = async () => {
+ try {
+ const nextPage = activePage + 1;
+
+ const response = await apiGetForumkuById({
+ id: userId,
+ page: `${nextPage}`,
+ });
+
+ if (response.success) {
+ setActivePage(nextPage);
+ return response.data;
+ } else {
+ return null;
+ }
+ } catch (error) {
+ clientLogger.error("Error get data forum");
+ return null;
+ }
+ };
return (
<>
- {userLoginId === auhtorSelectedData.id && (
-
- )}
-
-
+ {!dataUser ? (
+
+ ) : (
+
+ )}
- {_.isEmpty(data) ? (
-
-
-
-
- Tidak ada data
-
-
-
+ {!dataPosting.length ? (
+
+ ) : _.isEmpty(dataPosting) ? (
+
) : (
// --- Main component --- //
(
)}
- data={data}
- setData={setData}
- moreData={async () => {
- const loadData = await forum_getAllPostingByAuhtorId({
- page: activePage + 1,
- authorId: auhtorSelectedData.id,
- });
- setActivePage((val) => val + 1);
-
- return loadData;
- }}
+ data={dataPosting}
+ setData={setDataPosting}
+ moreData={handleMoreData}
>
{(item) => (
{
- setData(val);
+ setDataPosting(val);
}}
- allData={data}
+ allData={dataPosting}
/>
)}
)}
+
+ {userLoginId === dataUser?.id && (
+
+ )}
>
);
}
diff --git a/src/app_modules/forum/forumku/layout.tsx b/src/app_modules/forum/forumku/layout.tsx
index 83db14b8..34c6c3bd 100644
--- a/src/app_modules/forum/forumku/layout.tsx
+++ b/src/app_modules/forum/forumku/layout.tsx
@@ -7,10 +7,8 @@ import React from "react";
export default function LayoutForum_Forumku({
children,
- username,
}: {
children: React.ReactNode;
- username: string;
}) {
return (
<>
diff --git a/src/app_modules/forum/fun/edit/fun_edit_posting_by_id.ts b/src/app_modules/forum/fun/edit/fun_edit_posting_by_id.ts
index 5027e0e8..0bcff152 100644
--- a/src/app_modules/forum/fun/edit/fun_edit_posting_by_id.ts
+++ b/src/app_modules/forum/fun/edit/fun_edit_posting_by_id.ts
@@ -7,16 +7,22 @@ export async function forum_funEditPostingById(
postingId: string,
diskusi: string
) {
- const updt = await prisma.forum_Posting.update({
- where: {
- id: postingId,
- },
- data: {
- diskusi: diskusi,
- },
- });
+ try {
+ const updt = await prisma.forum_Posting.update({
+ where: {
+ id: postingId,
+ },
+ data: {
+ diskusi: diskusi,
+ },
+ });
- if (!updt) return { status: 400, message: "Gagal update" };
- revalidatePath("/dev/forum/main");
- return { status: 200, message: "Berhasil update" };
+ if (!updt) {
+ return { success: false, message: "Update gagal", status: 400 }; // Plain object dengan status
+ }
+ revalidatePath("/dev/forum/main");
+ return { success: true, message: "Berhasil update", status: 200 }; // Plain object dengan status
+ } catch (error) {
+ return { success: false, message: "Update error", status: 500 }; // Plain object dengan status
+ }
}
diff --git a/src/app_modules/forum/main/beranda.tsx b/src/app_modules/forum/main/beranda.tsx
index 35b3db29..0c919e56 100644
--- a/src/app_modules/forum/main/beranda.tsx
+++ b/src/app_modules/forum/main/beranda.tsx
@@ -1,65 +1,92 @@
"use client";
-import { RouterForum } from "@/lib/router_hipmi/router_forum";
-import { AccentColor } from "@/app_modules/_global/color/color_pallet";
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
-import mqtt_client from "@/util/mqtt_client";
-import {
- Affix,
- Button,
- Center,
- Loader,
- Stack,
- Text,
- TextInput,
- rem,
-} from "@mantine/core";
-import { useShallowEffect, useWindowScroll } from "@mantine/hooks";
-import { IconSearchOff } from "@tabler/icons-react";
+import { RouterForum } from "@/lib/router_hipmi/router_forum";
+import { clientLogger } from "@/util/clientLogger";
+import { Affix, Center, Loader, Stack, TextInput, rem } from "@mantine/core";
+import { useShallowEffect } from "@mantine/hooks";
import _ from "lodash";
import { ScrollOnly } from "next-scroll-loader";
-import { useRouter } from "next/navigation";
import { useState } from "react";
-import ComponentForum_BerandaCardView from "../component/main_component/card_view";
-import { forum_new_getAllPosting } from "../fun/get/new_get_all_posting";
-import { MODEL_FORUM_POSTING } from "../model/interface";
import { apiGetAllForum } from "../component/api_fetch_forum";
-import { clientLogger } from "@/util/clientLogger";
-import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
+import { ButtonUpdateBeranda } from "../component/button/button_update_beranda";
+import ComponentForum_BerandaCardView from "../component/main_component/card_view";
+import { Forum_ComponentIsDataEmpty } from "../component/other_component";
+import { Forum_SkeletonCard } from "../component/skeleton_view";
+import { MODEL_FORUM_POSTING } from "../model/interface";
+import mqtt_client from "@/util/mqtt_client";
export default function Forum_Beranda({
userLoginId,
}: {
userLoginId: string;
}) {
- const router = useRouter();
- const [scroll, scrollTo] = useWindowScroll();
-
- const [data, setData] = useState(null);
+ const [data, setData] = useState([]);
const [activePage, setActivePage] = useState(1);
const [isSearch, setIsSearch] = useState("");
const [isNewPost, setIsNewPost] = useState(false);
const [countNewPost, setCountNewPost] = useState(0);
+ const [hasMore, setHasMore] = useState(true);
+ const [isLoading, setIsLoading] = useState(false);
useShallowEffect(() => {
handleLoadData(isSearch);
}, [isSearch]);
const handleLoadData = async (isSearch: string) => {
+ setIsLoading(true);
try {
const response = await apiGetAllForum({
- page: `${activePage}`,
+ page: "1",
search: isSearch,
});
if (response) {
setData(response.data);
+ setActivePage(1);
+ setHasMore(response.data.length > 0);
}
} catch (error) {
clientLogger.error("Error get data forum", error);
+ setData([]);
+ setHasMore(false);
+ } finally {
+ setIsLoading(false);
}
};
+ const handleMoreData = async () => {
+ if (!hasMore || isLoading) return null;
+
+ try {
+ const nextPage = activePage + 1;
+
+ const response = await apiGetAllForum({
+ page: `${nextPage}`,
+ search: isSearch,
+ });
+
+ if (response?.data && response.data.length > 0) {
+ setActivePage(nextPage);
+ setHasMore(response.data.length > 0);
+ return response.data;
+ } else {
+ setHasMore(false);
+ return null;
+ }
+ } catch (error) {
+ clientLogger.error("Error get data forum", error);
+ setHasMore(false);
+ return null;
+ }
+ };
+
+ const hanldeSearch = async (text: string) => {
+ setIsSearch(text);
+ setActivePage(1);
+ setHasMore(true);
+ };
+
useShallowEffect(() => {
mqtt_client.subscribe("Forum_create_new");
mqtt_client.subscribe("Forum_ganti_status");
@@ -109,12 +136,6 @@ export default function Forum_Beranda({
});
}, [countNewPost, data]);
- async function onSearch(text: string) {
- setIsSearch(text);
- setActivePage(1);
-
- }
-
return (
<>
{isNewPost && (
@@ -140,24 +161,14 @@ export default function Forum_Beranda({
radius={"xl"}
placeholder="Topik forum apa yang anda cari hari ini ?"
onChange={(val) => {
- onSearch(val.currentTarget.value);
+ hanldeSearch(val.currentTarget.value);
}}
/>
- {!data ? (
-
-
-
-
+ {!data.length && isLoading ? (
+
) : _.isEmpty(data) ? (
-
-
-
-
- Tidak ada data
-
-
-
+
) : (
// --- Main component --- //
{
- try {
- const nextPage = activePage + 1;
- const response = await apiGetAllForum({
- page: `${nextPage}`,
- search: isSearch,
- });
-
- if (response) {
- setActivePage((val) => val + 1);
- return response.data;
- }
- } catch (error) {
- clientLogger.error("Error get data forum", error);
- }
- }}
+ moreData={handleMoreData}
>
{(item) => (
);
}
-
-function ButtonUpdateBeranda({
- countNewPost,
- onSetData,
- onSetIsNewPost,
- onSetCountNewPosting,
-}: {
- countNewPost: number;
- onSetData: (val: any) => void;
- onSetIsNewPost: (val: any) => void;
- onSetCountNewPosting: (val: any) => void;
-}) {
- const [scroll, scrollTo] = useWindowScroll();
- const [isLoading, setIsLoading] = useState(false);
-
- async function onLoadData() {
- setIsLoading(true);
- const loadData = await forum_new_getAllPosting({ page: 1 });
-
- if (loadData) {
- onSetData(loadData);
- onSetIsNewPost(false);
- setIsLoading(false);
- onSetCountNewPosting(0);
- }
- }
-
- return (
- <>
-
- 0 ? 0.5 : 0.8}
- onClick={() => onLoadData()}
- >
- Update beranda + {countNewPost}
-
-
- >
- );
-}