Skip to content

Commit

Permalink
feat: most used apps hook (#747)
Browse files Browse the repository at this point in the history
* feat: most used apps hook

* fix: update hook

* fix: update hook key

* fix: update hook key

* feat: update hook

* fix: unused variables

* fix: update hooks

* fix: update hook

* fix: update hook

* fix: update hook

* fix: update field name

* fix: update key

* fix: formatting

---------

Co-authored-by: spaenleh <[email protected]>
  • Loading branch information
ztlee042 and spaenleh authored May 15, 2024
1 parent 4369ad2 commit 1b5fb17
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/api/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { App, UUID } from '@graasp/sdk';

import { PartialQueryConfigForApi } from '../types.js';
import { verifyAuthentication } from './axios.js';
import { buildAppListRoute, buildGetApiAccessTokenRoute } from './routes.js';
import {
buildAppListRoute,
buildGetApiAccessTokenRoute,
buildMostUsedAppListRoute,
} from './routes.js';

export const getApps = async ({ API_HOST, axios }: PartialQueryConfigForApi) =>
verifyAuthentication(() =>
Expand All @@ -11,6 +15,18 @@ export const getApps = async ({ API_HOST, axios }: PartialQueryConfigForApi) =>
.then(({ data }) => data),
);

export const getMostUsedApps = async ({
API_HOST,
axios,
}: PartialQueryConfigForApi) =>
verifyAuthentication(() =>
axios
.get<
{ url: string; name: string; count: number }[]
>(`${API_HOST}/${buildMostUsedAppListRoute}`)
.then(({ data }) => data),
);

export const requestApiAccessToken = async (
args: {
id: UUID;
Expand Down
1 change: 1 addition & 0 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const CATEGORIES_ROUTE = `${ITEMS_ROUTE}/categories`;
export const ETHERPAD_ROUTE = `${ITEMS_ROUTE}/etherpad`;
export const COLLECTIONS_ROUTE = `collections`;
export const buildAppListRoute = `${APPS_ROUTE}/list`;
export const buildMostUsedAppListRoute = `${APPS_ROUTE}/most-used`;
export const SHORT_LINKS_ROUTE = `${ITEMS_ROUTE}/short-links`;
export const SHORT_LINKS_LIST_ROUTE = `${SHORT_LINKS_ROUTE}/list`;
export const EMBEDDED_LINKS_ROUTE = `${ITEMS_ROUTE}/embedded-links/metadata`;
Expand Down
3 changes: 3 additions & 0 deletions src/config/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ export const memberKeys = {

// subscription plan for the current member
subscription: [...currentBaseKey, 'subscription'] as const,

// apps used mostly by the member
mostUsedApps: [...currentBaseKey, 'mostUsedApps'] as const,
};
},
};
Expand Down
8 changes: 7 additions & 1 deletion src/hooks/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query';

import * as Api from '../api/apps.js';
import { CONSTANT_KEY_STALE_TIME_MILLISECONDS } from '../config/constants.js';
import { APPS_KEY } from '../config/keys.js';
import { APPS_KEY, memberKeys } from '../config/keys.js';
import { QueryClientConfig } from '../types.js';

export default (queryConfig: QueryClientConfig) => {
Expand All @@ -16,5 +16,11 @@ export default (queryConfig: QueryClientConfig) => {
...defaultQueryOptions,
staleTime: CONSTANT_KEY_STALE_TIME_MILLISECONDS,
}),
useMostUsedApps: () =>
useQuery({
queryKey: memberKeys.current().mostUsedApps,
queryFn: () => Api.getMostUsedApps(queryConfig),
...defaultQueryOptions,
}),
};
};

0 comments on commit 1b5fb17

Please sign in to comment.