|
@@ -2,34 +2,31 @@ import type { SWRResponse } from 'swr';
|
|
|
import useSWRImmutable from 'swr/immutable';
|
|
import useSWRImmutable from 'swr/immutable';
|
|
|
|
|
|
|
|
import { apiv3Get } from '~/client/util/apiv3-client';
|
|
import { apiv3Get } from '~/client/util/apiv3-client';
|
|
|
-import type { UserActivitiesResult, IActivityHasId } from '~/interfaces/activity';
|
|
|
|
|
|
|
+import type {
|
|
|
|
|
+ IActivityHasId,
|
|
|
|
|
+ UserActivitiesResult,
|
|
|
|
|
+} from '~/interfaces/activity';
|
|
|
import type { PaginateResult } from '~/interfaces/mongoose-utils';
|
|
import type { PaginateResult } from '~/interfaces/mongoose-utils';
|
|
|
|
|
|
|
|
export const useSWRxRecentActivity = (
|
|
export const useSWRxRecentActivity = (
|
|
|
- limit?: number,
|
|
|
|
|
- offset?: number,
|
|
|
|
|
- targetUserId?: string,
|
|
|
|
|
|
|
+ limit?: number,
|
|
|
|
|
+ offset?: number,
|
|
|
|
|
+ targetUserId?: string,
|
|
|
): SWRResponse<PaginateResult<IActivityHasId>, Error> => {
|
|
): SWRResponse<PaginateResult<IActivityHasId>, Error> => {
|
|
|
-
|
|
|
|
|
const shouldFetch = targetUserId && targetUserId.length > 0;
|
|
const shouldFetch = targetUserId && targetUserId.length > 0;
|
|
|
- const key = shouldFetch ? ['/user-activities', limit, offset, targetUserId] : null;
|
|
|
|
|
-
|
|
|
|
|
- const fetcher = ([
|
|
|
|
|
- endpoint,
|
|
|
|
|
- limitParam,
|
|
|
|
|
- offsetParam,
|
|
|
|
|
- targetUserIdParam,
|
|
|
|
|
- ]) => {
|
|
|
|
|
|
|
+ const key = shouldFetch
|
|
|
|
|
+ ? ['/user-activities', limit, offset, targetUserId]
|
|
|
|
|
+ : null;
|
|
|
|
|
|
|
|
|
|
+ const fetcher = ([endpoint, limitParam, offsetParam, targetUserIdParam]) => {
|
|
|
const promise = apiv3Get<UserActivitiesResult>(endpoint, {
|
|
const promise = apiv3Get<UserActivitiesResult>(endpoint, {
|
|
|
limit: limitParam,
|
|
limit: limitParam,
|
|
|
offset: offsetParam,
|
|
offset: offsetParam,
|
|
|
targetUserId: targetUserIdParam,
|
|
targetUserId: targetUserIdParam,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- return promise.then(result => result.data.serializedPaginationResult);
|
|
|
|
|
|
|
+ return promise.then((result) => result.data.serializedPaginationResult);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-
|
|
|
|
|
return useSWRImmutable(key, fetcher);
|
|
return useSWRImmutable(key, fetcher);
|
|
|
};
|
|
};
|