Add variable storage locations & batch adding
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { NavigationProp } from '@react-navigation/native';
|
||||
import { Dirs, FileSystem } from 'react-native-file-access';
|
||||
import { extension } from 'react-native-mime-types';
|
||||
import { AndroidScoped, Dirs, FileSystem } from 'react-native-file-access';
|
||||
import Share from 'react-native-share';
|
||||
import Clipboard from '@react-native-clipboard/clipboard';
|
||||
import { Meme } from '../database';
|
||||
@@ -13,10 +12,20 @@ const favoriteMeme = (realm: Realm, meme: Meme) => {
|
||||
});
|
||||
};
|
||||
|
||||
const shareMeme = async (meme: Meme) => {
|
||||
const fileExtension = extension(meme.mimeType) as string;
|
||||
const cacheUri = `${Dirs.CacheDir}/${meme.id.toHexString()}.${fileExtension}`;
|
||||
await FileSystem.cp(meme.uri, cacheUri);
|
||||
const shareMeme = async (realm: Realm, storageUri: string, meme: Meme) => {
|
||||
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
||||
const cacheUri = `${Dirs.CacheDir}/${meme.filename}`;
|
||||
|
||||
realm.write(() => {
|
||||
meme.dateUsed = new Date();
|
||||
meme.timesUsed += 1;
|
||||
meme.tags.forEach(tag => {
|
||||
tag.dateUsed = new Date();
|
||||
tag.timesUsed += 1;
|
||||
});
|
||||
});
|
||||
|
||||
await FileSystem.cp(uri, cacheUri);
|
||||
await Share.open({
|
||||
url: `file://${cacheUri}`,
|
||||
type: meme.mimeType,
|
||||
@@ -24,10 +33,22 @@ const shareMeme = async (meme: Meme) => {
|
||||
});
|
||||
};
|
||||
|
||||
const copyMeme = async (meme: Meme) => {
|
||||
const exists = await FileSystem.exists(meme.uri);
|
||||
const copyMeme = async (realm: Realm, storageUri: string, meme: Meme) => {
|
||||
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
||||
|
||||
const exists = await FileSystem.exists(uri);
|
||||
if (!exists) throw new Error('File does not exist');
|
||||
Clipboard.setURI(meme.uri);
|
||||
|
||||
realm.write(() => {
|
||||
meme.dateUsed = new Date();
|
||||
meme.timesUsed += 1;
|
||||
meme.tags.forEach(tag => {
|
||||
tag.dateUsed = new Date();
|
||||
tag.timesUsed += 1;
|
||||
});
|
||||
});
|
||||
|
||||
Clipboard.setURI(uri);
|
||||
};
|
||||
|
||||
const editMeme = (
|
||||
@@ -37,8 +58,10 @@ const editMeme = (
|
||||
navigation.navigate(ROUTE.EDIT_MEME, { id: meme.id.toHexString() });
|
||||
};
|
||||
|
||||
const deleteMeme = async (realm: Realm, meme: Meme) => {
|
||||
await FileSystem.unlink(meme.uri).catch(noOp);
|
||||
const deleteMeme = async (realm: Realm, storageUri: string, meme: Meme) => {
|
||||
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
||||
|
||||
await FileSystem.unlink(uri).catch(noOp);
|
||||
|
||||
realm.write(() => {
|
||||
for (const tag of meme.tags) {
|
||||
|
Reference in New Issue
Block a user