add community page
This commit is contained in:
1
enjoy/src/renderer/components/posts/index.ts
Normal file
1
enjoy/src/renderer/components/posts/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './posts';
|
||||
37
enjoy/src/renderer/components/posts/posts.tsx
Normal file
37
enjoy/src/renderer/components/posts/posts.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { Client } from "@/api";
|
||||
import { AppSettingsProviderContext } from "@renderer/context";
|
||||
import { t } from "i18next";
|
||||
|
||||
export const Posts = () => {
|
||||
const { apiUrl, user } = useContext(AppSettingsProviderContext);
|
||||
const [posts, setPosts] = useState<PostType[]>([]);
|
||||
|
||||
const client = new Client({
|
||||
baseUrl: apiUrl,
|
||||
accessToken: user.accessToken,
|
||||
});
|
||||
|
||||
const fetchPosts = async () => {
|
||||
client.posts().then(
|
||||
(res) => {
|
||||
setPosts(res.posts);
|
||||
},
|
||||
(err) => {
|
||||
console.error(err);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchPosts();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
{posts.length === 0 && (
|
||||
<div className="text-center text-gray-500">{t("noOneSharedYet")}</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user