From 346923d42731869e651c89c131573e44be14515c Mon Sep 17 00:00:00 2001 From: Dwayne Harris Date: Thu, 31 Oct 2019 01:47:51 -0400 Subject: [PATCH] WIP --- src/components/pages/view-user.tsx | 35 +++++++++++++++++++++--------- src/types/entities.ts | 10 +++++++-- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/components/pages/view-user.tsx b/src/components/pages/view-user.tsx index e795499..dc97ec6 100644 --- a/src/components/pages/view-user.tsx +++ b/src/components/pages/view-user.tsx @@ -2,13 +2,13 @@ import React, { FC, useEffect } from 'react' import { useSelector, useDispatch } from 'react-redux' import { Link, useParams, useHistory } from 'react-router-dom' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { faUserPlus, faUserMinus, faBan } from '@fortawesome/free-solid-svg-icons' +import { faUserPlus, faUserMinus, faUserClock, faBan } from '@fortawesome/free-solid-svg-icons' import { handleApiError } from 'src/api/errors' -import { fetchUser } from 'src/actions/users' +import { fetchUser, subscribe, unsubscribe } from 'src/actions/users' import { fetchUserPosts } from 'src/actions/posts' import { getEntity } from 'src/selectors/entities' -import { getAuthenticatedUser } from 'src/selectors/authentication' +import { getAuthenticatedUser, getChecked } from 'src/selectors/authentication' import { getUserPosts } from 'src/selectors/posts' import { useDeepCompareEffect, useConfig } from 'src/hooks' @@ -26,6 +26,7 @@ interface Params { const ViewUser: FC = () => { const { id } = useParams() + const checked = useSelector(getChecked) const self = useSelector(getAuthenticatedUser) const user = useSelector(state => getEntity(state, EntityType.User, id)) const posts = useSelector(state => getUserPosts(state, id)) @@ -43,8 +44,8 @@ const ViewUser: FC = () => { } } - init() - }, []) + if (checked) init() + }, [checked]) useDeepCompareEffect(() => { if (user) setTitle(user.name) @@ -52,9 +53,14 @@ const ViewUser: FC = () => { if (!user) return + console.log('user', user) + const isSelf = self && self.id === user.id const isGroup = self && self.group && user.group && self.group.id === user.group.id const imageUrl = user.imageUrl ? urlForBlob(config, user.imageUrl) : undefined + const subscription = self && user.subscriptions ? user.subscriptions.find(subscription => subscription.from === self.id && subscription.to === user.id) : undefined + const subscribed = subscription && !subscription.pending + const subscriptionPending = subscription && subscription.pending return (
@@ -87,8 +93,8 @@ const ViewUser: FC = () => {
- {user.subscribed && - } - {user.subscribed && - + } + + {self && !isSelf && !subscribed && !subscriptionPending && + } diff --git a/src/types/entities.ts b/src/types/entities.ts index 585ca6b..0baacfc 100644 --- a/src/types/entities.ts +++ b/src/types/entities.ts @@ -14,6 +14,13 @@ export enum GroupMembershipType { Member = 'member', } +export interface UserSubscription { + from: string + to: string + pending: boolean + created: number +} + export interface Entity { [key: string]: any id: string @@ -50,8 +57,7 @@ type BaseUser = Entity & { coverImageUrl?: string requiresApproval: boolean privacy: string - subscribed: boolean - subscribedToYou: boolean + subscriptions: UserSubscription[] } export type User = BaseUser & {