-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for viewing group avatar photo #48757
Changes from all commits
1c93560
755a304
e2e2093
8e37922
631b494
58249b7
bcfb52a
e0ad3ff
f27a9d4
0638ed5
f9137e9
d6020af
6bc1eb1
1dce9ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
import React from 'react'; | ||
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import React, {useMemo} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import AttachmentModal from '@components/AttachmentModal'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {AuthScreensParamList} from '@libs/Navigation/types'; | ||
|
@@ -10,50 +9,51 @@ import * as UserUtils from '@libs/UserUtils'; | |
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import type {Policy, Report} from '@src/types/onyx'; | ||
|
||
type ReportAvatarOnyxProps = { | ||
report: OnyxEntry<Report>; | ||
isLoadingApp: OnyxEntry<boolean>; | ||
policies: OnyxCollection<Policy>; | ||
}; | ||
type ReportAvatarProps = StackScreenProps<AuthScreensParamList, typeof SCREENS.REPORT_AVATAR>; | ||
|
||
type ReportAvatarProps = ReportAvatarOnyxProps & StackScreenProps<AuthScreensParamList, typeof SCREENS.REPORT_AVATAR>; | ||
function ReportAvatar({route}: ReportAvatarProps) { | ||
const reportIDFromRoute = route.params?.reportID ?? '-1'; | ||
const policyIDFromRoute = route.params?.policyID ?? '-1'; | ||
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`); | ||
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyIDFromRoute}`); | ||
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true}); | ||
|
||
function ReportAvatar({report = {} as Report, route, policies, isLoadingApp = true}: ReportAvatarProps) { | ||
const policyID = route.params.policyID ?? '-1'; | ||
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; | ||
const policyName = ReportUtils.getPolicyName(report, false, policy); | ||
const avatarURL = ReportUtils.getWorkspaceIcon(report).source; | ||
const attachment = useMemo(() => { | ||
if (ReportUtils.isGroupChat(report) && !ReportUtils.isThread(report)) { | ||
return { | ||
source: report?.avatarUrl ? UserUtils.getFullSizeAvatar(report.avatarUrl, 0) : ReportUtils.getDefaultGroupAvatar(report?.reportID ?? ''), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can still access it using a URL, for example: |
||
headerTitle: ReportUtils.getReportName(report), | ||
originalFileName: report?.avatarFileName ?? '', | ||
isWorkspaceAvatar: false, | ||
}; | ||
} | ||
|
||
return { | ||
source: UserUtils.getFullSizeAvatar(ReportUtils.getWorkspaceIcon(report).source, 0), | ||
headerTitle: ReportUtils.getPolicyName(report, false, policy), | ||
// In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar | ||
originalFileName: policy?.originalFileName ?? policy?.id ?? report?.policyID ?? '', | ||
isWorkspaceAvatar: true, | ||
}; | ||
}, [report, policy]); | ||
|
||
return ( | ||
<AttachmentModal | ||
headerTitle={policyName} | ||
headerTitle={attachment.headerTitle} | ||
defaultOpen | ||
source={UserUtils.getFullSizeAvatar(avatarURL, 0)} | ||
source={attachment.source} | ||
onModalClose={() => { | ||
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '-1')); | ||
}} | ||
isWorkspaceAvatar | ||
isWorkspaceAvatar={attachment.isWorkspaceAvatar} | ||
maybeIcon | ||
// In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar | ||
originalFileName={policy?.originalFileName ?? policy?.id ?? report?.policyID} | ||
originalFileName={attachment.originalFileName} | ||
shouldShowNotFoundPage={!report?.reportID && !isLoadingApp} | ||
isLoading={(!report?.reportID || !policy?.id) && !!isLoadingApp} | ||
/> | ||
); | ||
} | ||
|
||
ReportAvatar.displayName = 'ReportAvatar'; | ||
|
||
export default withOnyx<ReportAvatarProps, ReportAvatarOnyxProps>({ | ||
report: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID ?? '-1'}`, | ||
}, | ||
isLoadingApp: { | ||
key: ONYXKEYS.IS_LOADING_APP, | ||
}, | ||
policies: { | ||
key: ONYXKEYS.COLLECTION.POLICY, | ||
}, | ||
})(ReportAvatar); | ||
export default ReportAvatar; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we set
avatarFileName
to an empty string whenfile
is undefined, theavatarFileName
will remain an empty string. For example, when removing the avatar, theavatarFileName
will stay as an empty string, but it should be set tonull
to effectively remove theavatarFileName
.To test this, go to the avatar picker’s popover menu and select "Remove Avatar." Then, check the Onyx value of
avatarFileName
. While theavatarUrl
will be removed, theavatarFileName
will remain an empty string.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that the url is being removed but the filename is not? given that both fallback to an empty string, or is it because the former is cleared from BE onyx response?
Either way, let's set both to
null