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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user