start user page
This commit is contained in:
parent
90205a1243
commit
27cec4e77e
17 changed files with 401 additions and 82 deletions
|
@ -1,10 +1,15 @@
|
|||
export interface User {
|
||||
id: string;
|
||||
username: string;
|
||||
name: string;
|
||||
display_name: string | null;
|
||||
bio: string | null;
|
||||
avatar_urls: string[] | null;
|
||||
links: string[] | null;
|
||||
|
||||
names: FieldEntry[];
|
||||
pronouns: Pronoun[];
|
||||
members: PartialMember[];
|
||||
fields: Field[];
|
||||
}
|
||||
|
||||
export interface MeUser extends User {
|
||||
|
@ -12,6 +17,38 @@ export interface MeUser extends User {
|
|||
discord_username: string | null;
|
||||
}
|
||||
|
||||
export interface Field {
|
||||
name: string;
|
||||
entries: FieldEntry[];
|
||||
}
|
||||
|
||||
export interface FieldEntry {
|
||||
value: string;
|
||||
status: WordStatus;
|
||||
}
|
||||
|
||||
export interface Pronoun {
|
||||
pronouns: string;
|
||||
display_text: string | null;
|
||||
status: WordStatus;
|
||||
}
|
||||
|
||||
export enum WordStatus {
|
||||
Unknown = 0,
|
||||
Favourite = 1,
|
||||
Okay = 2,
|
||||
Jokingly = 3,
|
||||
FriendsOnly = 4,
|
||||
Avoid = 5,
|
||||
}
|
||||
|
||||
export interface PartialMember {
|
||||
id: string;
|
||||
name: string;
|
||||
display_name: string | null;
|
||||
avatar_urls: string[] | null;
|
||||
}
|
||||
|
||||
export interface APIError {
|
||||
code: ErrorCode;
|
||||
message?: string;
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import type { APIError } from "./entities";
|
||||
|
||||
export async function fetchAPI<T>(
|
||||
export async function apiFetch<T>(
|
||||
path: string,
|
||||
{ method, body, token }: { method?: string; body?: any; token?: string },
|
||||
) {
|
||||
const resp = await fetch(`${process.env.ORIGIN}/api/v1${path}`, {
|
||||
method,
|
||||
const apiBase = typeof process !== "undefined" ? process.env.ORIGIN : "";
|
||||
|
||||
const resp = await fetch(`${apiBase}/api/v1${path}`, {
|
||||
method: method || "GET",
|
||||
headers: {
|
||||
...(token ? { Authorization: token } : {}),
|
||||
"Content-Type": "application/json",
|
||||
|
@ -17,3 +19,6 @@ export async function fetchAPI<T>(
|
|||
if (resp.status < 200 || resp.status >= 300) throw data as APIError;
|
||||
return data as T;
|
||||
}
|
||||
|
||||
export const apiFetchClient = async <T>(path: string, method: string = "GET", body: any = null) =>
|
||||
apiFetch<T>(path, { method, body, token: localStorage.getItem("pronouns-token") || undefined });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue