App
App copied to clipboard
Group Chat custom avatar not saved when navigating back to invite members page
Coming from https://github.com/Expensify/App/pull/39757#issuecomment-2052659550
- Create a new group chat
- Choose a picture for custom avatar
- Go back to member invite page
- Proceed again
- Create chat
Expected:
Avatar image should be saved.
Actual
Picture is not taken into consideration.
I am guessing this is because the file ref needs to be cached outside the component lifecycle or some other strategy to achieve it. Feels like a minor issue that can be easily solved.
No progress yet. Focused on QBO
Gonna take this one External
so we can make some progress.
Triggered auto assignment to @adelekennedy (Bug
), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.
Job added to Upwork: https://www.upwork.com/jobs/~014f246ab8eb2607ee
Current assignee @s77rt is eligible for the External assigner, not assigning anyone new.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Group Chat custom avatar not saved when navigating back to invite members page
What is the root cause of that problem?
When creating the group, we use the outdated fileRef.current
which is undefined when coming back.
https://github.com/Expensify/App/blob/406139cf2120b25c28643f1e728d531fd8848a60/src/pages/NewChatConfirmPage.tsx#L96
What changes do you think we should make in order to solve the problem?
We should use stashedLocalAvatarImage
which takes the saved picture from the NEW_GROUP_CHAT_DRAFT
Onyx key when creating the groupChat
https://github.com/Expensify/App/blob/406139cf2120b25c28643f1e728d531fd8848a60/src/pages/NewChatConfirmPage.tsx#L107
@neonbhai Thanks for the proposal. Your RCA makes sense but the solution won't work. In onyx we only store the url and we want to pass the whole image.
Still looking for proposals
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
still waiting for proposals - @marcaaron @s77rt is this a more complex issue than originally thought?
@adelekennedy I didn't check in depth but it shouldn't be that hard, no need to adjust the bounty yet
Agree, I think we just haven't found the obvious solution yet - but let's see.
@s77rt @marcaaron @adelekennedy this issue is now 4 weeks old, please consider:
- Finding a contributor to fix the bug
- Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
- If you have any questions, don't hesitate to start a discussion in #expensify-open-source
Thanks!
still waiting
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
gonna just keep waiting on this as it's pretty edge-casey. Going to move this to weekly so we don't keep getting dinged
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
Still looking for proposals...
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
still pending proposals @neonbhai can you update your proposal with @s77rt feedback?
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
Proposal
Please re-state the problem that we are trying to solve in this issue.
Group Chat custom avatar not saved when navigating back to invite members page
What is the root cause of that problem?
The screen remounts every time we navigate, causing the fileRef to be re-initialized upon returning.
What changes do you think we should make in order to solve the problem?
We can follow receipt flow to keep the avatar image persist by re-reading stored uri.
In src/pages/NewChatConfirmPage.tsx
change fileRef to state, add avatarFile
as createGroup
dependency and add useEffect
to re-read the stored file when re-mounts.
const [avatarFile, setAvatarFile] = useState<File | CustomRNImageManipulatorResult | undefined>();
..............
useEffect(() => {
if (!stashedLocalAvatarImage) {
return;
}
const onSuccess = (file: File) => {
setAvatarFile(file)
};
const onFailure = () => {
setAvatarFile(undefined);
Report.setGroupDraft({avatarUri: null, avatarFileName: null, avatarFileType: null});
};
FileUtils.readFileAsync(stashedLocalAvatarImage.toString(), newGroupDraft?.avatarFileName ?? '', onSuccess, onFailure, newGroupDraft?.avatarFileType ?? '');
}, []);
What alternative solutions did you explore? (Optional)
We can move fileRef to a context to make it persist while navigate.
Create src/hooks/useFileRef.tsx
useFileRef.tsx
import React, { createContext, useContext, useRef, ReactNode } from 'react';
import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types';
// Define the type for the context
type FileRefContextType = React.MutableRefObject<File | CustomRNImageManipulatorResult | undefined> | null;
// Create the context
const FileRefContext = createContext<FileRefContextType>(null);
// Custom hook to access the context
const useFileRef = (): FileRefContextType => useContext(FileRefContext);
// Define the type for the provider props
type FileRefProviderProps = {
children: ReactNode;
};
// Provider component to manage the fileRef value
const FileRefProvider = ({ children }: FileRefProviderProps) => {
const fileRef = useRef<File | CustomRNImageManipulatorResult | undefined>(null);
return (
<FileRefContext.Provider value={fileRef}>
{children}
</FileRefContext.Provider>
);
};
export { FileRefProvider, useFileRef }
Wrap RHP stack navigator with FileRefProvider
<View style={styles.RHPNavigatorContainer(isSmallScreenWidth)}>
<FileRefProvider>
<Stack.Navigator
.....
fileRef
in NewChatConfirmPage
will use useFileRef
function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmPageProps) {
const optimisticReportID = useRef<string>(ReportUtils.generateReportID());
const fileRef = useFileRef();
Clean up
const createGroup = useCallback(() => {
if (!newGroupDraft) {
return;
}
const logins: string[] = (newGroupDraft.participants ?? []).map((participant) => participant.login);
Report.navigateToAndOpenReport(logins, true, newGroupDraft.reportName ?? '', newGroupDraft.avatarUri ?? '', fileRef &&fileRef.current, optimisticReportID.current, true);
if (fileRef) {
fileRef.current = undefined;
}
@wildan-m Thanks for the proposal. Your RCA makes sense but the solution is over-engineered. We already have this flow working well with receipts. Let's follow the same approach.
@s77rt receipt has different case, perform back navigation from image preview will force the user to re-upload the scanned receipt, but group chat will expect we re-visit the image preview page without re-uploading the image.
@wildan-m If you start the money request process from the FAB you can go back to the participants page
@s77rt thanks for the hints. I've updated my propsal.
Change log: Move prev solution to alternative, add new main solution that mimic receipt upload behavior.
@wildan-m Thanks for looking into this. The solution looks good to me 👍.
🎀 👀 🎀 C+ reviewed Link to proposal
Triggered auto assignment to @MonilBhavsar, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@MonilBhavsar, do we need to consider anything else before we proceed?