Feature/swr for library screens (#186)

* Wrap data fetching in library and manga screen with swr for better dev and user experience. Refactor some API calls and data handling. Add manual refresh to manga detail.

* Fix manga card layout

* Fix refresh button position on small screens

* Revert "Fix manga card layout"

This reverts commit d85da3d8385e1ef64feed1789e4cd4591c8bd563.

* Fix manga not setting title

* Move chapters loading to Manga component, join data fetching, add auto online fetch if fetched data is old

* Revert some changes
This commit is contained in:
Valter Martinek
2022-11-02 10:42:02 +01:00
committed by GitHub
parent 14a9ffa558
commit 6f8755fa05
12 changed files with 345 additions and 319 deletions

View File

@@ -14,9 +14,11 @@ const { hostname, port, protocol } = window.location;
let inferredPort;
if (port === '3000') { inferredPort = '4567'; } else { inferredPort = port; }
const baseURL = storage.getItem('serverBaseURL', `${protocol}//${hostname}:${inferredPort}`);
const client = axios.create({
// baseURL must not have traling slash
baseURL: storage.getItem('serverBaseURL', `${protocol}//${hostname}:${inferredPort}`),
baseURL,
});
client.interceptors.request.use((config) => {
@@ -27,3 +29,14 @@ client.interceptors.request.use((config) => {
});
export default client;
export async function fetcher<T = any>(path: string) {
const res = await client.get(path);
if (res.status !== 200) {
throw new Error(res.statusText);
}
if (res.headers['content-type'] !== 'application/json') {
throw new Error('Response is not json');
}
return res.data as T;
}