mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat(frontend): show recent listens
This commit is contained in:
parent
32dcd84964
commit
49bff95ea5
12 changed files with 217 additions and 16 deletions
|
|
@ -1,4 +1,7 @@
|
|||
import { User } from "./user";
|
||||
import { Listen } from "./entities/listen";
|
||||
import { Pagination } from "./entities/pagination";
|
||||
import { PaginationOptions } from "./entities/pagination-options";
|
||||
import { User } from "./entities/user";
|
||||
|
||||
export class UnauthenticatedError extends Error {}
|
||||
|
||||
|
|
@ -38,3 +41,29 @@ export const getUsersMe = async (): Promise<User> => {
|
|||
const user: User = await res.json();
|
||||
return user;
|
||||
};
|
||||
|
||||
export const getRecentListens = async (
|
||||
options: PaginationOptions = { page: 1, limit: 10 }
|
||||
): Promise<Pagination<Listen>> => {
|
||||
const { page, limit } = options;
|
||||
|
||||
const res = await fetch(`/api/v1/listens?page=${page}&limit=${limit}`, {
|
||||
headers: getDefaultHeaders(),
|
||||
});
|
||||
|
||||
switch (res.status) {
|
||||
case 200: {
|
||||
break;
|
||||
}
|
||||
case 401: {
|
||||
throw new UnauthenticatedError(`No token or token expired`);
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unable to getRecentListens: ${res.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
const listens: Pagination<Listen> = await res.json();
|
||||
console.log("getRecentListens", { listens });
|
||||
return listens;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue