mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
fix(frontend/Blog) fix compatibility with new backend
This commit is contained in:
3 files changed
+26
-30
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import React from 'react';
|
||||
import Link from 'next/link';
|
||||
import { Card, CardBody, CardHeader } from '@nextui-org/card';
|
||||
import { Divider } from '@nextui-org/react';
|
||||
|
||||
@@ -8,23 +7,29 @@ type Props = {
|
||||
}
|
||||
|
||||
function BlogPostCard({ post }: Props) {
|
||||
const name = (post as any)['name'];
|
||||
const { title, desc } = (post as any)['meta'] as { title: string, desc: string };
|
||||
let title = (post as any)['title'];
|
||||
let summary = (post as any)['summary'];
|
||||
let last_update = (post as any)['last_update'];
|
||||
|
||||
return (
|
||||
|
||||
<div>
|
||||
{/*todo: to be update*/ }
|
||||
{/*<Link href={ `/blog/${ name }` }>*/}
|
||||
{/*<Link href={ `/blog/${ name }` }>*/ }
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<p className={ 'font-bold' }>{ title }</p>
|
||||
</CardHeader>
|
||||
<Divider />
|
||||
<CardBody>
|
||||
{ desc }
|
||||
{ summary }
|
||||
</CardBody>
|
||||
<Divider />
|
||||
<CardBody>
|
||||
{ last_update }
|
||||
</CardBody>
|
||||
</Card>
|
||||
{/*</Link>*/}
|
||||
{/*</Link>*/ }
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
import { Result } from '@/app/public/type/Result';
|
||||
|
||||
export default async function fetch_posts_list(): Promise<Result<JSON[], Error>> {
|
||||
const response = await fetch(`${ process.env.BLOG_ENDPOINT }/posts/idx.json`);
|
||||
export default async function fetch_posts_list(): Promise<any> {
|
||||
const response = await fetch(`http://localhost:${ process.env.BACKEND_PORT }/api/get/post_list`);
|
||||
if (!response.ok) {
|
||||
return {
|
||||
ok: false,
|
||||
error: new Error(response.statusText)
|
||||
};
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
const res = await response.json();
|
||||
const posts = res['idx'].filter((posts: { type: string }) => posts.type === 'md');
|
||||
return {
|
||||
ok: true,
|
||||
value: posts
|
||||
};
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
|
||||
+11
-10
@@ -4,26 +4,27 @@ import BlogPostCard from '@/app/blog/BlogPostCard';
|
||||
|
||||
async function Blog() {
|
||||
|
||||
try {
|
||||
const res = await fetch_posts_list();
|
||||
if (!res.ok) {
|
||||
console.log(res.error);
|
||||
return;
|
||||
}
|
||||
const posts = res.value;
|
||||
|
||||
console.log(posts);
|
||||
|
||||
let posts = res['posts'];
|
||||
return (
|
||||
|
||||
// blog list
|
||||
<ul className={ 'flex flex-col items-center w-full max-w-[1024px]' }>
|
||||
{ posts.map((post, key) => (
|
||||
{ posts.map((post: JSON, key: React.Key | null | undefined) => (
|
||||
<li key={ key } className={ 'my-3.5 mx-7 w-[80%]' }>
|
||||
<BlogPostCard post={ post } />
|
||||
</li>)
|
||||
) }
|
||||
</ul>
|
||||
);
|
||||
} catch (e: any) {
|
||||
return (
|
||||
<>
|
||||
{ e.toString() }
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Blog;
|
||||
Reference in new issue
Block a user