feat: read/write improved fields for users, read improved names/pronouns for users

This commit is contained in:
Sam 2023-01-14 17:33:18 +01:00
parent 7669595586
commit c6537c920d
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
8 changed files with 87 additions and 127 deletions

View file

@ -51,11 +51,12 @@ export interface Pronoun {
export interface Field {
name: string;
favourite: Arr<string>;
okay: Arr<string>;
jokingly: Arr<string>;
friends_only: Arr<string>;
avoid: Arr<string>;
entries: Arr<FieldEntry>;
}
export interface FieldEntry {
value: string;
status: WordStatus;
}
export interface APIError {

View file

@ -199,31 +199,11 @@ export class Pronouns extends Label {
export class Field {
name: string;
labels: Label[];
constructor({
name,
favourite,
okay,
jokingly,
friends_only,
avoid,
}: API.Field) {
constructor({ name, entries }: API.Field) {
this.name = name;
function transpose(arr: API.Arr<string>, status: LabelStatus): Label[] {
return (arr ?? []).map(
(text) =>
new Label({
displayText: null,
text,
status,
})
);
}
this.labels = [
...transpose(favourite, LabelStatus.Favourite),
...transpose(okay, LabelStatus.Okay),
...transpose(jokingly, LabelStatus.Jokingly),
...transpose(friends_only, LabelStatus.FriendsOnly),
...transpose(avoid, LabelStatus.Avoid),
];
this.labels =
entries?.map(
(e) => new Label({ displayText: null, text: e.value, status: e.status })
) ?? [];
}
}