ui: loading badges for spot videos
This commit is contained in:
parent
b3cb8df65b
commit
95d4df7a1b
2 changed files with 11 additions and 2 deletions
|
|
@ -32,6 +32,7 @@ import { Avatar, Icon } from 'UI';
|
||||||
import { TABS, Tab } from '../consts';
|
import { TABS, Tab } from '../consts';
|
||||||
import AccessModal from './AccessModal';
|
import AccessModal from './AccessModal';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { toast } from 'react-toastify'
|
||||||
|
|
||||||
const spotLink = spotsList();
|
const spotLink = spotsList();
|
||||||
|
|
||||||
|
|
@ -89,8 +90,12 @@ function SpotPlayerHeader({
|
||||||
|
|
||||||
const onMenuClick = async ({ key }: { key: string }) => {
|
const onMenuClick = async ({ key }: { key: string }) => {
|
||||||
if (key === '1') {
|
if (key === '1') {
|
||||||
|
const loader = toast.loading('Retrieving Spot video...')
|
||||||
const { url } = await spotStore.getVideo(spotStore.currentSpot!.spotId);
|
const { url } = await spotStore.getVideo(spotStore.currentSpot!.spotId);
|
||||||
await downloadFile(url, `${spotStore.currentSpot!.title}.mp4`);
|
await downloadFile(url, `${spotStore.currentSpot!.title}.mp4`);
|
||||||
|
setTimeout(() => {
|
||||||
|
toast.dismiss(loader)
|
||||||
|
}, 0)
|
||||||
} else if (key === '2') {
|
} else if (key === '2') {
|
||||||
spotStore.deleteSpot([spotStore.currentSpot!.spotId]).then(() => {
|
spotStore.deleteSpot([spotStore.currentSpot!.spotId]).then(() => {
|
||||||
history.push(spotsList());
|
history.push(spotsList());
|
||||||
|
|
@ -245,12 +250,11 @@ function SpotPlayerHeader({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadFile(url: string, fileName: string) {
|
async function downloadFile(url: string, fileName: string) {
|
||||||
const { t } = useTranslation();
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(t('Network response was not ok'));
|
throw new Error('Network response was not ok');
|
||||||
}
|
}
|
||||||
|
|
||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
|
|
@ -263,6 +267,7 @@ async function downloadFile(url: string, fileName: string) {
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
URL.revokeObjectURL(blobUrl);
|
URL.revokeObjectURL(blobUrl);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
toast.error('Error downloading file.')
|
||||||
console.error('Error downloading file:', error);
|
console.error('Error downloading file:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,12 @@ function SpotListItem({
|
||||||
case 'rename':
|
case 'rename':
|
||||||
return setIsEdit(true);
|
return setIsEdit(true);
|
||||||
case 'download':
|
case 'download':
|
||||||
|
const loader = toast.loading('Retrieving Spot video...')
|
||||||
const { url } = await onVideo(spot.spotId);
|
const { url } = await onVideo(spot.spotId);
|
||||||
await downloadFile(url, `${spot.title}.mp4`);
|
await downloadFile(url, `${spot.title}.mp4`);
|
||||||
|
setTimeout(() => {
|
||||||
|
toast.dismiss(loader)
|
||||||
|
}, 0)
|
||||||
return;
|
return;
|
||||||
case 'copy':
|
case 'copy':
|
||||||
copy(
|
copy(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue