Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
halituzan committed Nov 6, 2024
1 parent 76c525b commit fcaa23e
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 170 deletions.
7 changes: 1 addition & 6 deletions app/Components/Main/Pages/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ import Image from "next/image";
import Link from "next/link";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
type Props = {
data?: any;
};

const About = ({ data }: Props) => {
console.log("data", data);

const About = () => {
const [datas, setDatas] = useState<any>({});

const getData = async () => {
Expand Down
44 changes: 37 additions & 7 deletions app/Components/Main/Pages/Blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,50 @@ import { Icon } from "@iconify/react/dist/iconify.js";
import moment from "moment";
import Link from "next/link";
import { useRouter } from "next/router";
import { Suspense } from "react";
import { Suspense, useEffect, useState } from "react";
import Loading from "../../Patterns/Loading";
import Network from "@/utils/Network";

type Props = {
data: BlogPost[];
title: string;
isTagPage: boolean;
};

const Blog = ({ data, title, isTagPage }: Props) => {
console.log("data", data);

const Blog = ({ title, isTagPage }: Props) => {
const router = useRouter();
const { tag } = router.query;
const [datas, setDatas] = useState<BlogPost[]>([]);

const getData = async () => {
try {
const res = await Network.run(null, "GET", `/api/blogs`, null);
setDatas(res.data);
} catch (error) {
console.log(error);
}
};

const getTag = async () => {
try {
const res = await Network.run(
null,
"GET",
`/api/blogs/blogtags?tag=${tag}`,
null
);
setDatas(res.data);
} catch (error) {
console.log(error);
}
};

useEffect(() => {
if (isTagPage) {
getTag();
} else {
getData();
}
}, []);

return (
<Suspense fallback={<Loading />}>
Expand All @@ -40,13 +70,13 @@ const Blog = ({ data, title, isTagPage }: Props) => {
</Link>
<div>
<span className='font-bold'>{tag}</span> etiketi ile{" "}
<span className='font-bold'>({data.length})</span> adet içerik
<span className='font-bold'>({datas.length})</span> adet içerik
bulundu
</div>
</div>
)}

{data.map((item) => {
{datas.map((item: any) => {
return (
<article key={item._id} className='my-6'>
<Link href={`/blogs/${item.url + "-" + item.code}`}>
Expand Down
47 changes: 38 additions & 9 deletions app/Components/Main/Pages/BlogPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import moment from "moment";
import Link from "next/link";
import { useEffect, useState } from "react";
import Meta from "../../Patterns/Meta";
import { useRouter } from "next/router";

type Props = {
data: BlogPost;
code: string;
};
type Props = {};

const SingleBlogPost = ({}: Props) => {
const router = useRouter();

const [data, setDatas] = useState<any>({});

const SingleBlogPost = ({ data, code }: Props) => {
const [like, setLike] = useState(data.like);
const [like, setLike] = useState(0);
const { theme } = useTheme();
const getCount = async (endpoint: string) => {
setLike((prev) => prev + 1);
if (!router?.query.url || typeof router.query.url !== "string") {
return;
}
const code = router?.query?.url?.split("BP-")[1];
setLike((prev: number) => prev + 1);
try {
await Network.run(
null,
Expand All @@ -29,6 +35,29 @@ const SingleBlogPost = ({ data, code }: Props) => {
}
};

const getData = async () => {
if (!router?.query.url || typeof router.query.url !== "string") {
return;
}
const code = router?.query?.url?.split("BP-")[1];
try {
const res = await Network.run(
null,
"GET",
`/api/blogs/detail?code=${code}`,
null
);
setLike(res.data.like);
setDatas(res.data);
} catch (error) {
console.log(error);
}
};

useEffect(() => {
getData();
}, []);

useEffect(() => {
if (typeof window !== "undefined" && data.content) {
import("highlight.js").then((hljs) => {
Expand Down Expand Up @@ -66,7 +95,7 @@ const SingleBlogPost = ({ data, code }: Props) => {
</div>
<div className='flex justify-start items-center mr-2'>
<p className='text-sm flex items-center' role='author'>
{data.tags.map((i: TagProps) => (
{data.tags?.map((i: TagProps) => (
<Link
href={"/tags/" + i.url}
key={i._id}
Expand All @@ -82,7 +111,7 @@ const SingleBlogPost = ({ data, code }: Props) => {
</p>
</div>
</div>
<div className='mt-2 text-sm font-medium content-area'>
<div className='mt-2 text-sm font-medium content-area pr-4'>
<div dangerouslySetInnerHTML={{ __html: data.content }} />
</div>
</article>
Expand Down
1 change: 1 addition & 0 deletions app/Components/Patterns/Loading.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import React from "react";

type Props = {};
Expand Down
35 changes: 2 additions & 33 deletions pages/about/index.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
import About from "@/app/Components/Main/Pages/About";
import Loading from "@/app/Components/Patterns/Loading";
import Network from "@/utils/Network";
type Props = { data: any; messages: string };

const AboutPage = ({ data, messages }: Props) => {
console.log("data", data);

if (!data) {
return <Loading />;
}

return <About data={data} />;
const AboutPage = () => {
return <About />;
};

export default AboutPage;

export async function getServerSideProps(context: any) {
try {
const res = await Network.run(context, "GET", "/api/about/aboutget", null);

return {
props: {
data: res.data || [],
messages: "success",
},
};
} catch (error) {
console.log("error", error);

return {
props: {
data: [],
messages: "error",
},
};
}
}
44 changes: 1 addition & 43 deletions pages/blogs/[url].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import SingleBlogPost from "@/app/Components/Main/Pages/BlogPost";
import { BlogPost } from "@/app/Configs/types";
import Network from "@/utils/Network";

type Props = {
data: BlogPost;
Expand All @@ -11,50 +10,9 @@ type Props = {
const BlogsPost = ({ data, errorMessage, code }: Props) => {
return (
<div className='w-full'>
{errorMessage ? (
"Sayfaya Ulaşılamıyor"
) : (
<SingleBlogPost data={data} code={code} />
)}
{errorMessage ? "Sayfaya Ulaşılamıyor" : <SingleBlogPost />}
</div>
);
};

export default BlogsPost;

export async function getServerSideProps(context: any) {
const code = context.query.url.split("BP-")[1];

if (!code) {
return {
props: {
data: [],
errorMessage: true,
code: code,
},
};
}
try {
const res = await Network.run(
context,
"GET",
`/api/blogs/detail?code=${code}`,
null
);
return {
props: {
data: res.data || [],
errorMessage: res.data == null ? true : false,
code: code,
},
};
} catch (error) {
return {
props: {
data: [],
errorMessage: true,
code: code,
},
};
}
}
35 changes: 3 additions & 32 deletions pages/blogs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
import Blog from "@/app/Components/Main/Pages/Blog";
import Loading from "@/app/Components/Patterns/Loading";
import { BlogPost } from "@/app/Configs/types";
import Network from "@/utils/Network";

type Props = {
data: BlogPost[];
const BlogsPage = () => {
return <Blog title='Blog Post' isTagPage={false} />;
};

const BlogsPage = ({ data }: Props) => {
if (data.length == 0) {
return <Loading />;
}
return <Blog data={data} title='Blog Post' isTagPage={false} />;
};

export default BlogsPage;

export async function getServerSideProps(context: any) {
try {
const res = await Network.run(context, "GET", `/api/blogs`, null);

return {
props: {
data: res.data || [],
},
};
} catch (error) {
console.log("error", error);
return {
props: {
data: [],
},
};
}
}
export default BlogsPage;
42 changes: 2 additions & 40 deletions pages/tags/[tag].tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
import Blog from "@/app/Components/Main/Pages/Blog";
import { BlogPost } from "@/app/Configs/types";
import Network from "@/utils/Network";

type Props = {
data: BlogPost[];
errorMessage: boolean;
};

const TagsPage = ({ data, errorMessage }: Props) => {
return <Blog data={data} title='Tags Page' isTagPage={true} />;
const TagsPage = () => {
return <Blog title='Tags Page' isTagPage={true} />;
};

export default TagsPage;

export async function getServerSideProps(context: any) {
const { tag } = context.query;

if (!tag) {
return {
props: {},
};
}
try {
const res = await Network.run(
context,
"GET",
`/api/blogs/blogtags?tag=${tag}`,
null
);
return {
props: {
data: res.data || [],
errorMessage: res.data == null ? true : false,
},
};
} catch (error) {
return {
props: {
data: [],
errorMessage: true,
},
};
}
}

0 comments on commit fcaa23e

Please sign in to comment.