Add navigation to families screen

This commit is contained in:
2023-07-07 18:57:43 +02:00
parent 09f1584d18
commit 6aceda7fe7
2 changed files with 73 additions and 32 deletions

View File

@ -1,6 +1,6 @@
import { APIClient } from "./ApiClient";
export interface Family {
interface FamilyAPI {
user_id: number;
family_id: number;
name: string;
@ -11,6 +11,49 @@ export interface Family {
count_admins: number;
}
export class Family implements FamilyAPI {
user_id: number;
family_id: number;
name: string;
time_create: number;
is_admin: boolean;
invitation_code: string;
count_members: number;
count_admins: number;
constructor(f: FamilyAPI) {
this.user_id = f.user_id;
this.family_id = f.family_id;
this.name = f.name;
this.time_create = f.time_create;
this.is_admin = f.is_admin;
this.invitation_code = f.invitation_code;
this.count_members = f.count_members;
this.count_admins = f.count_admins;
}
/**
* Check if the current user user can leave a family
*/
get CanLeave(): boolean {
return !this.is_admin || this.count_admins > 1;
}
/**
* Get application URL for family
*/
URL(uri?: string): string {
return `/family/${this.family_id}/${uri ?? ""}`;
}
/**
* Get base family URL
*/
get BaseURL(): string {
return this.URL("");
}
}
export enum JoinFamilyResult {
TooManyRequests,
InvalidCode,
@ -65,14 +108,7 @@ export class FamilyApi {
method: "GET",
uri: "/family/list",
})
).data;
}
/**
* Check if the current user user can leave a family
*/
static CanLeaveFamily(f: Family): boolean {
return !f.is_admin || f.count_admins > 1;
).data.map((f: FamilyAPI) => new Family(f));
}
/**