diff --git a/app/User/News/[newsId]/page.tsx b/app/User/News/[newsId]/page.tsx
new file mode 100644
index 0000000..7cc3f72
--- /dev/null
+++ b/app/User/News/[newsId]/page.tsx
@@ -0,0 +1,15 @@
+import NewsDetails from '@/components/News/NewsDetails';
+import React from 'react'
+
+function page({params}: {params : any}) {
+ const id = Number(params.newsId);
+ console.log(id);
+
+ return (
+
+
+
+ )
+}
+
+export default page
\ No newline at end of file
diff --git a/app/User/News/page.tsx b/app/User/News/page.tsx
index cb2be10..0c17162 100644
--- a/app/User/News/page.tsx
+++ b/app/User/News/page.tsx
@@ -1,7 +1,11 @@
-import React from 'react'
+import News from "@/components/News/News";
+import React from "react";
export default function page() {
return (
- page
- )
+ //
+
+ );
}
diff --git a/app/globals.css b/app/globals.css
index df8bcd4..26398b0 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -119,3 +119,7 @@
src: url(../assets/fonts/ttf/iranyekanwebregularfanum.ttf);
}
+.news-description img{
+ max-width: 700px;
+ width: 100%;
+}
\ No newline at end of file
diff --git a/components/News/News.tsx b/components/News/News.tsx
new file mode 100644
index 0000000..c621ba3
--- /dev/null
+++ b/components/News/News.tsx
@@ -0,0 +1,88 @@
+"use client";
+import React, { useEffect, useState } from "react";
+import { useQuery } from "@tanstack/react-query";
+import Image from "next/image";
+import Link from "next/link";
+import { convertFullTime } from "@/lib/utils";
+import { useRouter } from "next/navigation";
+import { getNews } from "@/utils/CitizenNews";
+import { ThreeDots } from "react-loader-spinner";
+
+interface News {
+ id: string;
+ title: string;
+ url: string;
+ imageFile: {
+ id: string;
+ url: string;
+ url2: string;
+ url3: string;
+ url4: string;
+ alternateText: string;
+ title: string;
+ mediaType: 0;
+ };
+ created: string;
+ isDeleted: boolean;
+}
+
+function News() {
+ const router = useRouter();
+ const [news, setNews] = useState(null);
+ const { data, isLoading, isError, isSuccess, refetch } = useQuery({
+ queryKey: ["News"],
+ queryFn: () => getNews(),
+ });
+
+ useEffect(() => {
+ if (data) {
+ console.log(data);
+ console.log(data.data);
+ console.log(data.data[0]);
+ setNews(data.data);
+ }
+ }, [data]);
+
+ if (isError) {
+ return Error loading data
;
+ }
+
+ return (
+
+ {isLoading ? (
+
+
+
+ ) : (
+ <>
+ {isSuccess &&
+ news?.map((item: any) => (
+
+
+ {item.title}
+
+
+ ))}
+ >
+ )}
+
+ );
+}
+
+export default News;
diff --git a/components/News/NewsDetails.tsx b/components/News/NewsDetails.tsx
new file mode 100644
index 0000000..9f61255
--- /dev/null
+++ b/components/News/NewsDetails.tsx
@@ -0,0 +1,65 @@
+"use client";
+import { convertFullTime } from "@/lib/utils";
+import { getSingleNews } from "@/utils/CitizenNews";
+import { useQuery } from "@tanstack/react-query";
+import { useParams } from "next/navigation";
+import React, { useEffect, useState } from "react";
+
+interface NewsDetails {
+ id: string;
+ title: string;
+ description: string;
+ url: string;
+ imageFile: {
+ id: string;
+ url: string;
+ url2: string;
+ url3: string;
+ url4: string;
+ alternateText: string;
+ title: string;
+ mediaType: 0;
+ };
+ created: string;
+ isDeleted: boolean;
+}
+
+interface NewsProps {
+ id: number;
+}
+
+const NewsDetails: React.FC = ({ id }) => {
+// const NewsDetails: React.FC = () => {
+ // const id = Number(useParams());
+// const { id } = useParams();
+
+ const [details, setDetails] = useState(null);
+ const { data, isLoading, isError, isSuccess, refetch } = useQuery({
+ queryKey: ["NewsDetails", id],
+ queryFn: () => getSingleNews(id),
+ });
+
+ useEffect(() => {
+ if (data) {
+ console.log(data);
+ console.log(data.data);
+ console.log(data.data[0]);
+ setDetails(data.data);
+ }
+ }, [data]);
+
+ return (
+
+
+
{details?.title}
+
{convertFullTime(details?.created)}
+
+
+
+ );
+};
+
+export default NewsDetails;
diff --git a/utils/CitizenNews.ts b/utils/CitizenNews.ts
new file mode 100644
index 0000000..599791a
--- /dev/null
+++ b/utils/CitizenNews.ts
@@ -0,0 +1,22 @@
+import axios from "axios";
+import { getCookie } from "cookies-next";
+axios.defaults.baseURL = process.env.NEXT_PUBLIC_BASE_URL_APP;
+
+axios.interceptors.request.use(function (config) {
+ const token = getCookie("Shahrbin_Token");
+ config.headers.Authorization = token ? `Bearer ${token}` : "";
+ return config;
+});
+
+// Get News
+export async function getNews() {
+ const data = await axios.get(`/api/CitizenNews/News`);
+ return data.data;
+}
+
+// Get News {ID}
+export async function getSingleNews(id: number) {
+ // export async function getSingleNews(id : any) {
+ const data = await axios.get(`/api/CitizenNews/${id}`);
+ return data.data;
+}