Skip to content

Commit

Permalink
Merge pull request #36918 from Krishna2323/krishna2323/issue/36901
Browse files Browse the repository at this point in the history
fix: Chat - Download option in three-dot menu is still available in offline mode
  • Loading branch information
bondydaa authored Feb 23, 2024
2 parents eba50cb + 7c77703 commit 57ad70b
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 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,32 +32,36 @@ function VideoPopoverMenuContextProvider({children}) {
});
}, [currentVideoPlayerRef]);

const menuItems = useMemo(
() => [
{
const menuItems = useMemo(() => {
const items = [];

if (!isOffline) {
items.push({
icon: Expensicons.Download,
text: translate('common.download'),
onSelected: () => {
downloadAttachment();
},
},
{
icon: Expensicons.Meter,
text: translate('videoPlayer.playbackSpeed'),
subMenuItems: [
..._.map(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS, (speed) => ({
icon: currentPlaybackSpeed === speed ? Expensicons.Checkmark : null,
text: speed.toString(),
onSelected: () => {
updatePlaybackSpeed(speed);
},
shouldPutLeftPaddingWhenNoIcon: true,
})),
],
},
],
[currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed],
);
});
}

items.push({
icon: Expensicons.Meter,
text: translate('videoPlayer.playbackSpeed'),
subMenuItems: [
..._.map(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS, (speed) => ({
icon: currentPlaybackSpeed === speed ? Expensicons.Checkmark : null,
text: speed.toString(),
onSelected: () => {
updatePlaybackSpeed(speed);
},
shouldPutLeftPaddingWhenNoIcon: true,
})),
],
});

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 57ad70b

Please sign in to comment.