|
|
@@ -1,10 +1,14 @@
|
|
|
+import { Middleware, SWRHook } from 'swr';
|
|
|
+
|
|
|
+import { IUserHasId } from '~/interfaces/user';
|
|
|
+
|
|
|
import { apiv3Put } from '~/client/util/apiv3-client';
|
|
|
|
|
|
-export const checkAndUpdateImageUrlCached = (useSWRNext) => {
|
|
|
+export const checkAndUpdateImageUrlCached: Middleware = (useSWRNext: SWRHook) => {
|
|
|
return (key, fetcher, config) => {
|
|
|
const swrNext = useSWRNext(key, fetcher, config);
|
|
|
if (swrNext.data != null) {
|
|
|
- const userIds = swrNext.data?.map(user => user._id);
|
|
|
+ const userIds = Object(swrNext.data).map((user: IUserHasId) => user._id);
|
|
|
if (userIds.length > 0) {
|
|
|
const distinctUserIds = Array.from(new Set(userIds));
|
|
|
apiv3Put('/users/update.imageUrlCache', { userIds: distinctUserIds });
|