Skip to content

Commit

Permalink
fix: changed download to share api
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJustChew committed Apr 16, 2024
1 parent 8a7508b commit 7257658
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@capacitor/haptics": "5.0.7",
"@capacitor/ios": "5.6.0",
"@capacitor/keyboard": "5.0.8",
"@capacitor/share": "^6.0.0",
"@capacitor/status-bar": "5.0.7",
"@dnd-kit/core": "^6.1.0",
"@dnd-kit/modifiers": "^7.0.0",
Expand Down
36 changes: 7 additions & 29 deletions src/components/Timetable/DownloadTimetableDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ import Timetable from './Timetable';
import useUserTimetable from '@/hooks/contexts/useUserTimetable';
import { toPng } from 'html-to-image';
import { useCallback, useRef, useState } from 'react';
import {createTimetableFromCourses, colorMapFromCourses} from '@/helpers/timetable';
import { useSettings } from '@/hooks/contexts/settings';
import { createTimetableFromCourses } from '@/helpers/timetable';
import { MinimalCourse } from '@/types/courses';
import { Device } from '@capacitor/device';
import { Media } from '@capacitor-community/media';
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
import { toast } from '../ui/use-toast';
import { Capacitor } from '@capacitor/core';
import { Share } from '@capacitor/share';

const DownloadTimetableComponent = () => {
const dict = useDictionary();
Expand All @@ -36,14 +32,9 @@ const DownloadTimetableComponent = () => {
link.href = dataUrl;
link.click();
} else {
const albums = await Media.getAlbums();
if (albums.albums.every(album => album.name !== 'NTHUMods')) {
await Media.createAlbum({ name: 'NTHUMods' });
}
await Media.savePhoto({
path: dataUrl,
albumIdentifier: 'NTHUMods',
fileName: filename,
await Share.share({
title: 'Share Timetable',
url: dataUrl,
});
}
})
Expand Down Expand Up @@ -84,22 +75,9 @@ const DownloadTimetableDialog = ({ onClose, icsfileLink }: { onClose: () => void
link.href = icsfileLink;
link.click();
} else {
const res = await Filesystem.checkPermissions()
if (!res.publicStorage) {
const result = await Filesystem.requestPermissions();
if (result.publicStorage != 'granted') {
toast({
title: 'Permission Denied',
description: 'Please allow storage permission to download the file.',
});
return;
}
}
Filesystem.downloadFile({
path: `ics/${filename}`,
await Share.share({
url: icsfileLink,
directory: Directory.Documents,
recursive: true,
dialogTitle: 'Open in Calendar',
});
}

Expand Down

0 comments on commit 7257658

Please sign in to comment.