Shun Miyazawa 4 лет назад
Родитель
Сommit
0edef5c5f1
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      packages/app/src/stores/middlewares/user.ts

+ 6 - 2
packages/app/src/stores/middlewares/user.ts

@@ -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 });