adrianhajdin / social_media_app

Build a modern social app with a stunning UI with a native mobile feel, a special tech stack, an infinite scroll feature, and amazing performance using React JS, Appwrite, TypeScript, and more.
https://jsmastery.pro
1.26k stars 381 forks source link

type error in PostStats.tsx (solution) #59

Closed SteaceP closed 6 months ago

SteaceP commented 6 months ago

If you're like me and NEED to use the latest version of everything and you got a type error on save in currentUser?.save in savedPostRecord const in the PostStats.tsx file.

add this code to /src/types/index.ts IUser type:

save?: Array<{
 $id: string;
  post: {
    $id: string;
  };
 }>;
};

then, in PostStats.tsx, make the savedPostrecord const like this:

  const savedPostRecord = (currentUser as IUser)?.save?.find(
    (record: { $id: string; post: { $id: string } }) => record.post.$id === post.$id,
  );

enjoy! Sorry for not making a pull request, I'm not sure it will break something later and don't have time to check. If it does I'' be updating this. Edit: I just had a new(probably with my previous update) a new type error. Again the same. The IUser type is all fucked up, i'll be updati Edit: I just had a new(probably with my previous update) a new type error. Again the same. The IUser type is all fucked up, i'll be updating this

then, in PostStats.tsx, make the savedPostrecord const like this:

  const savedPostRecord = (currentUser as IUser)?.save?.find(
    (record: { $id: string; post: { $id: string } }) => record.post.$id === post.$id,
  );

enjoy! Sorry for not making a pull request, I'm not sure it will break something later and don't have time to check. If it does I'' be updating this. Edit: I just had a new(probably with my previous update) type error. Again, it's the same. The IUser type is all fucked up, i'll be updating this code from now on since the person who made it seems to be dead or something like that, well, I'll fork this and try to keep it updated, i'll give the link once it's done (on next weekend). To the guy with the unpronounceable name that speak english better than all of us (british are excluded from this debate) I can just make a pull request if you somehow raise from the dead(ressurectMe).pls