Skip to content
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

bug fix: pfp not working on mobile #2443

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions apps/mobile/src/components/ProfilePicture/ProfilePicture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { useFragment } from 'react-relay';
import { graphql } from 'relay-runtime';

import { ProfilePictureFragment$key } from '~/generated/ProfilePictureFragment.graphql';
import { ProfilePictureValidFragment$key } from '~/generated/ProfilePictureValidFragment.graphql';
import { ReportingErrorBoundary } from '~/shared/errors/ReportingErrorBoundary';
import { useGetSinglePreviewImage } from '~/shared/relay/useGetPreviewImages';

import { RawProfilePicture, RawProfilePictureProps } from './RawProfilePicture';

Expand All @@ -21,6 +23,7 @@ export function ProfilePicture({ userRef, style, ...rest }: ProfilePictureProps)
profileImage {
... on TokenProfileImage {
token {
...ProfilePictureValidFragment
definition {
media {
... on Media {
Expand Down Expand Up @@ -48,7 +51,7 @@ export function ProfilePicture({ userRef, style, ...rest }: ProfilePictureProps)
);

const { token, profileImage: ensImage } = user?.profileImage ?? {};
const imageUrl = token?.definition?.media?.previewURLs?.small ?? ensImage?.previewURLs?.small;
const ensImageUrl = ensImage?.previewURLs?.small;

const letter = user?.username?.[0]?.toUpperCase();

Expand All @@ -64,15 +67,29 @@ export function ProfilePicture({ userRef, style, ...rest }: ProfilePictureProps)
/>
);

if (imageUrl) {
if (ensImageUrl) {
return (
<ReportingErrorBoundary fallback={fallbackProfilePicture}>
<RawProfilePicture
eventElementId="ProfilePicture"
eventName="ProfilePicture pressed"
// TODO analytics prop drill
eventContext={null}
imageUrl={imageUrl}
imageUrl={ensImageUrl}
style={style}
{...rest}
/>
</ReportingErrorBoundary>
);
} else if (token) {
return (
<ReportingErrorBoundary fallback={fallbackProfilePicture}>
<ValidProfilePicture
eventElementId="ProfilePicture"
eventName="ProfilePicture pressed"
// TODO analytics prop drill
eventContext={null}
tokenRef={token}
style={style}
{...rest}
/>
Expand All @@ -82,3 +99,23 @@ export function ProfilePicture({ userRef, style, ...rest }: ProfilePictureProps)
return fallbackProfilePicture;
}
}

type ValidProfilePictureProps = {
style?: ViewProps['style'];
tokenRef: ProfilePictureValidFragment$key;
} & Omit<RawProfilePictureProps, 'imageUrl'>;

function ValidProfilePicture({ tokenRef, style, ...rest }: ValidProfilePictureProps) {
const token = useFragment(
graphql`
fragment ProfilePictureValidFragment on Token {
...useGetPreviewImagesSingleFragment
}
`,
tokenRef
);

const imageUrl = useGetSinglePreviewImage({ tokenRef: token, size: 'small' }) ?? '';

return <RawProfilePicture imageUrl={imageUrl} style={style} {...rest} />;
}
Loading