add community page

This commit is contained in:
an-lee
2024-01-11 17:10:00 +08:00
parent 551b848ade
commit 94d4a0a338
19 changed files with 604 additions and 33 deletions

View File

@@ -0,0 +1 @@
export * from './posts';

View 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>
);
};