Add memes & meme-editing views
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import { Appbar, Button, useTheme } from 'react-native-paper';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
||||
import { BSON } from 'realm';
|
||||
import { useRealm } from '@realm/react';
|
||||
import { useObject, useRealm } from '@realm/react';
|
||||
import { TagEditor } from '../components';
|
||||
import styles from '../styles';
|
||||
import { ORIENTATION, useDimensions } from '../contexts';
|
||||
@@ -15,14 +15,14 @@ import { validateColor, validateTagName } from '../utilities';
|
||||
const EditTag = ({
|
||||
route,
|
||||
}: NativeStackScreenProps<RootStackParamList, ROUTE.EDIT_TAG>) => {
|
||||
const navigation = useNavigation();
|
||||
const { goBack } = useNavigation();
|
||||
const { colors } = useTheme();
|
||||
const { orientation } = useDimensions();
|
||||
const realm = useRealm();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const tag = realm.objectForPrimaryKey(
|
||||
Tag,
|
||||
const tag = useObject<Tag>(
|
||||
Tag.schema.name,
|
||||
BSON.UUID.createFromHexString(route.params.id),
|
||||
)!;
|
||||
|
||||
@@ -36,14 +36,14 @@ const EditTag = ({
|
||||
tag.dateModified = new Date();
|
||||
});
|
||||
|
||||
navigation.goBack();
|
||||
goBack();
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
realm.write(() => {
|
||||
for (const meme of tag.memes) {
|
||||
meme.dateModified = new Date();
|
||||
const tags = meme.tags as Set<Tag>;
|
||||
const tags = meme.tags as Realm.Set<Tag>;
|
||||
tags.delete(tag);
|
||||
meme.tagsLength = tags.size;
|
||||
}
|
||||
@@ -51,13 +51,13 @@ const EditTag = ({
|
||||
realm.delete(tag);
|
||||
});
|
||||
|
||||
navigation.goBack();
|
||||
goBack();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Appbar.Header>
|
||||
<Appbar.BackAction onPress={() => navigation.goBack()} />
|
||||
<Appbar.BackAction onPress={() => goBack()} />
|
||||
<Appbar.Content title={'Edit Tag'} />
|
||||
<Appbar.Action icon="delete" onPress={handleDelete} />
|
||||
</Appbar.Header>
|
||||
|
Reference in New Issue
Block a user