refactor webApi

This commit is contained in:
an-lee
2024-01-11 17:36:23 +08:00
parent 94d4a0a338
commit 66cf3dd828
11 changed files with 62 additions and 52 deletions

View File

@@ -1,19 +1,13 @@
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 { webApi } = useContext(AppSettingsProviderContext);
const [posts, setPosts] = useState<PostType[]>([]);
const client = new Client({
baseUrl: apiUrl,
accessToken: user.accessToken,
});
const fetchPosts = async () => {
client.posts().then(
webApi.posts().then(
(res) => {
setPosts(res.posts);
},