aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-06-10 17:23:47 -0400
committerIvan Chen <ivan@tagg.id>2021-06-10 17:23:47 -0400
commit770dcf385fa99fbb93c4ae89a51b09fd96d23bf9 (patch)
treeb6463d6827582fa6081dfe89cf98826e1e9a00ea /src/utils
parentd4c65c0ba3de95adf3069500491b124df453660f (diff)
Add util function, Add logic for updating comment preview
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/users.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/utils/users.ts b/src/utils/users.ts
index 64ad10e9..c1c3b8bc 100644
--- a/src/utils/users.ts
+++ b/src/utils/users.ts
@@ -306,3 +306,21 @@ export const patchProfile = async (
return false;
});
};
+
+/**
+ * Returns the logged-in user's info in ProfilePreviewType from redux store.
+ * @param state the current state of the redux store
+ * @returns logged-in user in ProfilePreviewType
+ */
+export const getLoggedInUserAsProfilePreview: (
+ state: RootState,
+) => ProfilePreviewType = (state) => {
+ const nameSplit = state.user.profile.name.split(' ');
+ return {
+ id: state.user.user.userId,
+ username: state.user.user.username,
+ first_name: nameSplit[0],
+ last_name: nameSplit[1],
+ thumbnail_url: state.user.avatar ?? '', // in full res
+ };
+};