Add meme view & sharing
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { ScrollView, View } from 'react-native';
|
||||
import { Appbar, Button, useTheme } from 'react-native-paper';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
@@ -10,7 +10,7 @@ import styles from '../styles';
|
||||
import { ORIENTATION, useDimensions } from '../contexts';
|
||||
import { ROUTE, RootStackParamList } from '../types';
|
||||
import { Tag } from '../database';
|
||||
import { validateColor, validateTagName } from '../utilities';
|
||||
import { deleteTag, validateColor, validateTagName } from '../utilities';
|
||||
|
||||
const EditTag = ({
|
||||
route,
|
||||
@@ -29,36 +29,26 @@ const EditTag = ({
|
||||
const [tagName, setTagName] = useState(validateTagName(tag.name));
|
||||
const [tagColor, setTagColor] = useState(validateColor(tag.color));
|
||||
|
||||
const handleSave = () => {
|
||||
const handleSave = useCallback(() => {
|
||||
realm.write(() => {
|
||||
tag.name = tagName.parsed;
|
||||
tag.color = tagColor.parsed;
|
||||
tag.dateModified = new Date();
|
||||
});
|
||||
|
||||
goBack();
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
realm.write(() => {
|
||||
for (const meme of tag.memes) {
|
||||
meme.dateModified = new Date();
|
||||
meme.tags.slice(meme.tags.indexOf(tag), 1);
|
||||
meme.tagsLength -= 1;
|
||||
}
|
||||
|
||||
realm.delete(tag);
|
||||
});
|
||||
|
||||
goBack();
|
||||
};
|
||||
}, [realm, tag, tagColor.parsed, tagName.parsed]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Appbar.Header>
|
||||
<Appbar.BackAction onPress={() => goBack()} />
|
||||
<Appbar.Content title={'Edit Tag'} />
|
||||
<Appbar.Action icon="delete" onPress={handleDelete} />
|
||||
<Appbar.Action
|
||||
icon="delete"
|
||||
onPress={() => {
|
||||
deleteTag(realm, tag);
|
||||
goBack();
|
||||
}}
|
||||
/>
|
||||
</Appbar.Header>
|
||||
<ScrollView
|
||||
contentContainerStyle={[
|
||||
@@ -83,7 +73,10 @@ const EditTag = ({
|
||||
<Button
|
||||
mode="contained"
|
||||
icon="floppy"
|
||||
onPress={handleSave}
|
||||
onPress={() => {
|
||||
handleSave();
|
||||
goBack();
|
||||
}}
|
||||
disabled={!tagName.valid || !tagColor.valid}>
|
||||
Save
|
||||
</Button>
|
||||
|
Reference in New Issue
Block a user