Skip to content

Commit

Permalink
chore(): update profile avatar in topbar (#1058)
Browse files Browse the repository at this point in the history
* chore(): update profile avatar in topbar

* chore(): add globalChannel
  • Loading branch information
SeverS authored Apr 8, 2021
1 parent 9e0e3e7 commit 207b116
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/akasha/src/components/app-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const AppRoutes: React.FC<RootComponentProps & AppRoutesProps> = props => {
ipfsService: sdkModules.commons.ipfsService,
onError: errorActions.createError,
rxjsOperators: props.rxjsOperators,
globalChannel: props.globalChannel,
});

React.useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions apps/akasha/src/components/post-page/post-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const PostPage: React.FC<IPostPage & RootComponentProps> = props => {
ipfsService: props.sdkModules.commons.ipfsService,
onError: errorActions.createError,
rxjsOperators: props.rxjsOperators,
globalChannel: props.globalChannel,
});

React.useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const ProfileCardWidget: React.FC<RootComponentProps> = props => {
ipfsService: props.sdkModules.commons.ipfsService,
profileService: props.sdkModules.profiles.profileService,
postsService: props.sdkModules.posts,
globalChannel: props.globalChannel,
});

const [loginState] = useLoginState({
Expand Down
4 changes: 4 additions & 0 deletions apps/moderation/src/components/content-card/content-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const ContentCard: React.FC<Omit<IContentProps, 'entryData'>> = props => {
},
ipfsService: props.sdkModules.commons.ipfsService,
profileService: props.sdkModules.profiles.profileService,
globalChannel: props.globalChannel,
});

const [reporterProfile, reporterProfileActions] = useProfile({
Expand All @@ -55,6 +56,7 @@ const ContentCard: React.FC<Omit<IContentProps, 'entryData'>> = props => {
},
ipfsService: props.sdkModules.commons.ipfsService,
profileService: props.sdkModules.profiles.profileService,
globalChannel: props.globalChannel,
});

const [moderatorProfile, moderatorProfileActions] = useProfile({
Expand All @@ -63,6 +65,7 @@ const ContentCard: React.FC<Omit<IContentProps, 'entryData'>> = props => {
},
ipfsService: props.sdkModules.commons.ipfsService,
profileService: props.sdkModules.profiles.profileService,
globalChannel: props.globalChannel,
});

React.useEffect(() => {
Expand Down Expand Up @@ -135,6 +138,7 @@ const ContentCard: React.FC<Omit<IContentProps, 'entryData'>> = props => {
singleSpa={props.singleSpa}
sdkModules={props.sdkModules}
handleButtonClick={props.handleButtonClick}
globalChannel={props.globalChannel}
/>
</MainAreaCardBox>
</Box>
Expand Down
1 change: 1 addition & 0 deletions apps/moderation/src/components/content-card/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const Content: React.FC<IContentProps> = props => {
forLabel={props.forLabel}
logger={props.logger}
sdkModules={props.sdkModules}
globalChannel={props.globalChannel}
/>
)}
<Box
Expand Down
3 changes: 3 additions & 0 deletions apps/moderation/src/components/content-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IContentListProps {
logger: any;
singleSpa: any;
sdkModules: any;
globalChannel: any;
}

interface IBaseItem {
Expand Down Expand Up @@ -266,6 +267,7 @@ const ContentList: React.FC<IContentListProps> = props => {
reportedDateTime={pendingItem.entryDate}
makeADecisionLabel={t('Make a Decision')}
handleButtonClick={handleButtonClick}
globalChannel={props.globalChannel}
/>
))
: renderNotFound('pending'))}
Expand Down Expand Up @@ -309,6 +311,7 @@ const ContentList: React.FC<IContentListProps> = props => {
evaluationDateTime={moderatedItem.evaluationDate}
reviewDecisionLabel={t('Review decision')}
handleButtonClick={handleButtonClick}
globalChannel={props.globalChannel}
/>
))
: renderNotFound('moderated'))}
Expand Down
2 changes: 2 additions & 0 deletions apps/moderation/src/components/explanations-box-entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface IExplanationsBoxEntryProps {
forLabel: string;
logger: any;
sdkModules: any;
globalChannel: any;
}

const ExplanationsCardEntry: React.FC<IExplanationsBoxEntryProps> = props => {
Expand All @@ -21,6 +22,7 @@ const ExplanationsCardEntry: React.FC<IExplanationsBoxEntryProps> = props => {
},
ipfsService: props.sdkModules.commons.ipfsService,
profileService: props.sdkModules.profiles.profileService,
globalChannel: props.globalChannel,
});

React.useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions apps/moderation/src/components/explanations-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const ExplanationsCard: React.FC<IExplanationsBoxProps> = props => {
forLabel={forLabel}
logger={logger}
sdkModules={sdkModules}
globalChannel={props.globalChannel}
/>
))}
</Box>
Expand Down
1 change: 1 addition & 0 deletions apps/moderation/src/interfaces/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ export interface IContentProps {
logger: any;
singleSpa: any;
sdkModules: any;
globalChannel: any;
handleButtonClick: (param1: string, param2: string) => void;
}
33 changes: 29 additions & 4 deletions ui/hooks/src/use-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import { getMediaUrl } from './utils/media-utils';
type voidFunc<T = object> = (arg: T) => void;

export interface UseProfileActions {
getProfileData: voidFunc<{ pubKey?: string | null; ethAddress?: string | null }>;
getProfileData: (
payload: { pubKey?: string | null; ethAddress?: string | null },
disableLoadingIndicator?: boolean,
) => void;
getEntryAuthor: voidFunc<{ entryId: string }>;
resetProfileData: () => void;
optimisticUpdate: (data: any) => void;
Expand Down Expand Up @@ -42,6 +45,7 @@ export interface UseProfileProps {
postsService?: any;
ensService?: any;
rxjsOperators?: any;
globalChannel: any;
}

export interface ProfileUpdateStatus {
Expand All @@ -60,7 +64,7 @@ export interface ProfileUpdateStatus {
export const useProfile = (
props: UseProfileProps,
): [Partial<IProfileData & { isLoading: boolean }>, UseProfileActions, ProfileUpdateStatus] => {
const { onError, ipfsService, profileService, postsService } = props;
const { onError, ipfsService, profileService, postsService, globalChannel } = props;
const [profile, setProfile] = React.useState<Partial<IProfileData & { isLoading: boolean }>>({
isLoading: true,
});
Expand All @@ -74,10 +78,31 @@ export const useProfile = (
notAllowed: false,
});

React.useEffect(() => {
if (globalChannel && props.rxjsOperators) {
globalChannel
.pipe(
props.rxjsOperators.filter((payload: any) => {
return (
payload.channelInfo.method === 'makeDefaultProvider' &&
payload.channelInfo.servicePath.includes('PROFILE_STORE')
);
}),
)
.subscribe(() => {
if (profile.pubKey) {
actions.getProfileData({ pubKey: profile.pubKey }, true);
}
});
}
}, [profile]);

const actions: UseProfileActions = {
getProfileData(payload) {
getProfileData(payload, disableLoadingIndicator) {
try {
setProfile({ isLoading: true });
if (!disableLoadingIndicator) {
setProfile({ isLoading: true });
}
const ipfsGatewayCall = ipfsService.getSettings({});
const getProfileCall = profileService.getProfile(payload);
const obs = forkJoin([ipfsGatewayCall, getProfileCall]);
Expand Down
1 change: 1 addition & 0 deletions ui/plugins/profile/src/components/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Routes: React.FC<RootComponentProps> = props => {
ipfsService: props.sdkModules.commons.ipfsService,
onError: errorActions.createError,
rxjsOperators: props.rxjsOperators,
globalChannel: props.globalChannel,
});

const [reportModalOpen, setReportModalOpen] = React.useState(false);
Expand Down
1 change: 1 addition & 0 deletions ui/plugins/profile/src/components/routes/profile-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const ProfilePage = (props: ProfilePageProps) => {
profileService: props.sdkModules.profiles.profileService,
ensService: props.sdkModules.registry.ens,
rxjsOperators: props.rxjsOperators,
globalChannel: props.globalChannel,
});

const [postsState, postsActions] = usePosts({
Expand Down
1 change: 1 addition & 0 deletions ui/plugins/search/src/components/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Routes: React.FC<RootComponentProps> = props => {
const [loginProfile] = useProfile({
profileService: props.sdkModules.profiles.profileService,
ipfsService: props.sdkModules.commons.ipfsService,
globalChannel: props.globalChannel,
});

const [modalState, modalStateActions] = useModalState({
Expand Down
2 changes: 2 additions & 0 deletions ui/widgets/top-bar/src/components/topbar-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const TopbarComponent = (props: TopBarProps) => {
onError: err => logger.error(err),
profileService: props.sdkModules.profiles.profileService,
ipfsService: props.sdkModules.commons.ipfsService,
globalChannel: props.globalChannel,
rxjsOperators: props.rxjsOperators,
});

const [notificationsState, notificationActions] = useNotifications({
Expand Down

0 comments on commit 207b116

Please sign in to comment.