Skip to content

Commit

Permalink
fix download option is shown for local file
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Feb 4, 2025
1 parent 92eb817 commit 0e25300
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function BaseVideoPlayer({
const isUploading = CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => url.startsWith(prefix));
const videoStateRef = useRef<AVPlaybackStatus | null>(null);
const {updateVolume, lastNonZeroVolume} = useVolumeContext();
const {videoPopoverMenuPlayerRef, currentPlaybackSpeed, setCurrentPlaybackSpeed} = useVideoPopoverMenuContext();
const {videoPopoverMenuPlayerRef, currentPlaybackSpeed, setCurrentPlaybackSpeed, setSource: setPopoverMenuSource} = useVideoPopoverMenuContext();
const {source} = videoPopoverMenuPlayerRef.current?.props ?? {};
const shouldUseNewRate = typeof source === 'number' || !source || source.uri !== sourceURL;

Expand Down Expand Up @@ -163,6 +163,7 @@ function BaseVideoPlayer({
}
setIsPopoverVisible(true);
});
setPopoverMenuSource(url);
if (!event || !('nativeEvent' in event)) {
return;
}
Expand Down
18 changes: 7 additions & 11 deletions src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import type {PopoverMenuItem} from '@components/PopoverMenu';
import type {VideoWithOnFullScreenUpdate} from '@components/VideoPlayer/types';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
import fileDownload from '@libs/fileDownload';
import CONST from '@src/CONST';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {usePlaybackContext} from './PlaybackContext';
import type {PlaybackSpeed, VideoPopoverMenuContext} from './types';

const Context = React.createContext<VideoPopoverMenuContext | null>(null);

function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
const {currentlyPlayingURL} = usePlaybackContext();
const {translate} = useLocalize();
const [source, setSource] = useState('');
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState<PlaybackSpeed>(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[3]);
const {isOffline} = useNetwork();
const isLocalFile = currentlyPlayingURL && CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => currentlyPlayingURL.startsWith(prefix));
const isLocalFile = source && CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => source.startsWith(prefix));
const videoPopoverMenuPlayerRef = useRef<VideoWithOnFullScreenUpdate | null>(null);

const updatePlaybackSpeed = useCallback(
Expand All @@ -29,15 +29,11 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
);

const downloadAttachment = useCallback(() => {
if (videoPopoverMenuPlayerRef.current === null) {
return;
}
const {source} = videoPopoverMenuPlayerRef.current?.props ?? {};
if (typeof source === 'number' || !source) {
return;
}
fileDownload(source.uri);
}, [videoPopoverMenuPlayerRef]);
fileDownload(addEncryptedAuthTokenToURL(source));
}, [source]);

const menuItems = useMemo(() => {
const items: PopoverMenuItem[] = [];
Expand Down Expand Up @@ -70,8 +66,8 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
}, [currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed, isOffline, isLocalFile]);

const contextValue = useMemo(
() => ({menuItems, videoPopoverMenuPlayerRef, currentPlaybackSpeed, updatePlaybackSpeed, setCurrentPlaybackSpeed}),
[menuItems, videoPopoverMenuPlayerRef, currentPlaybackSpeed, updatePlaybackSpeed, setCurrentPlaybackSpeed],
() => ({menuItems, videoPopoverMenuPlayerRef, currentPlaybackSpeed, updatePlaybackSpeed, setCurrentPlaybackSpeed, setSource}),
[menuItems, videoPopoverMenuPlayerRef, currentPlaybackSpeed, updatePlaybackSpeed, setCurrentPlaybackSpeed, setSource],
);
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/VideoPlayerContexts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type VideoPopoverMenuContext = {
currentPlaybackSpeed: PlaybackSpeed;
updatePlaybackSpeed: (speed: PlaybackSpeed) => void;
setCurrentPlaybackSpeed: (speed: PlaybackSpeed) => void;
setSource: (source: string) => void;
};

type FullScreenContext = {
Expand Down

0 comments on commit 0e25300

Please sign in to comment.