Skip to content

Commit

Permalink
feat: [torrust#658] new function wrapper for getting all user profile…
Browse files Browse the repository at this point in the history
…s from the API
  • Loading branch information
mario-nt committed Jan 16, 2025
1 parent 6e008e9 commit d585218
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion composables/states.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PublicSettings, Category, TokenResponse, TorrentTag } from "torrust-index-types-lib";
import type { PublicSettings, Category, TokenResponse, TorrentTag, UserProfile } from "torrust-index-types-lib";
import { Rest } from "torrust-index-api-lib";
import { notify } from "notiwind-ts";
import { useRuntimeConfig, useState } from "#imports";
Expand All @@ -8,6 +8,7 @@ export const useCategories = () => useState<Array<Category>>("categories", () =>
export const useTags = () => useState<Array<TorrentTag>>("tags", () => new Array<TorrentTag>());
export const useSettings = () => useState<PublicSettings>("public-settings", () => null);
export const useUser = () => useState<TokenResponse>("user", () => null);
export const useUserProfiles = () => useState<Array<UserProfile>>("user-profiles", () => new Array<UserProfile>());

export function getSettings () {
useRestApi().value.settings.getPublicSettings()
Expand Down Expand Up @@ -94,3 +95,17 @@ export async function getUser () {
}, 10000);
});
}

export function getUserProfiles () {
useRestApi().value.user.getUserProfiles()
.then((res) => {
useUserProfiles().value = res;
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to get user profiles. ${err.message}.`
}, 10000);
});
}

0 comments on commit d585218

Please sign in to comment.