Skip to content

Commit

Permalink
fix: Chat - Download option in three-dot menu is still available in o…
Browse files Browse the repository at this point in the history
…ffline mode.

Signed-off-by: Krishna Gupta <[email protected]>
  • Loading branch information
Krishna2323 committed Feb 20, 2024
1 parent a21cfbc commit 8144890
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/components/VideoPlayerContexts/VideoPopoverMenuContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {useCallback, useContext, useMemo, useState} from 'react';
import _ from 'underscore';
import * as Expensicons from '@components/Icon/Expensicons';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import fileDownload from '@libs/fileDownload';
import * as Url from '@libs/Url';
import CONST from '@src/CONST';
Expand All @@ -14,6 +15,7 @@ function VideoPopoverMenuContextProvider({children}) {
const {currentVideoPlayerRef} = usePlaybackContext();
const {translate} = useLocalize();
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[2]);
const {isOffline} = useNetwork();

const updatePlaybackSpeed = useCallback(
(speed) => {
Expand All @@ -30,15 +32,8 @@ function VideoPopoverMenuContextProvider({children}) {
});
}, [currentVideoPlayerRef]);

const menuItems = useMemo(
() => [
{
icon: Expensicons.Download,
text: translate('common.download'),
onSelected: () => {
downloadAttachment();
},
},
const menuItems = useMemo(() => {
const items = [
{
icon: Expensicons.Meter,
text: translate('videoPlayer.playbackSpeed'),
Expand All @@ -53,9 +48,20 @@ function VideoPopoverMenuContextProvider({children}) {
})),
],
},
],
[currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed],
);
];

if (!isOffline) {
items.push({
icon: Expensicons.Download,
text: translate('common.download'),
onSelected: () => {
downloadAttachment();
},
});
}

return items;
}, [currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed, isOffline]);

const contextValue = useMemo(() => ({menuItems, updatePlaybackSpeed}), [menuItems, updatePlaybackSpeed]);
return <VideoPopoverMenuContext.Provider value={contextValue}>{children}</VideoPopoverMenuContext.Provider>;
Expand Down

0 comments on commit 8144890

Please sign in to comment.