Fix a couple of bugs
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -148,7 +148,7 @@ const MemeTagSearchModal = ({
|
|||||||
active={memeTags.has(tag.id.toHexString())}
|
active={memeTags.has(tag.id.toHexString())}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
ListEmptyComponent={() => (
|
ListFooterComponent={() => (
|
||||||
<Chip
|
<Chip
|
||||||
icon="plus"
|
icon="plus"
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
|
@@ -71,7 +71,7 @@ const MemeView = ({
|
|||||||
|
|
||||||
const flashListRef = useRef<FlashList<Meme>>(null);
|
const flashListRef = useRef<FlashList<Meme>>(null);
|
||||||
|
|
||||||
const index = useRef(route.params.index);
|
const [index, setIndex] = useState(route.params.index);
|
||||||
const memes = useQuery<Meme>(Meme.schema.name, collectionIn => {
|
const memes = useQuery<Meme>(Meme.schema.name, collectionIn => {
|
||||||
return collectionIn
|
return collectionIn
|
||||||
.filtered(multipleIdQuery(route.params.ids))
|
.filtered(multipleIdQuery(route.params.ids))
|
||||||
@@ -83,8 +83,8 @@ const MemeView = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (memes.length === 0) navigation.goBack();
|
if (memes.length === 0) navigation.goBack();
|
||||||
if (index.current >= memes.length) {
|
if (index >= memes.length) {
|
||||||
index.current = memes.length - 1;
|
setIndex(memes.length - 1);
|
||||||
flashListRef.current?.scrollToIndex({ index: memes.length - 1 });
|
flashListRef.current?.scrollToIndex({ index: memes.length - 1 });
|
||||||
}
|
}
|
||||||
}, [index, memes.length, navigation]);
|
}, [index, memes.length, navigation]);
|
||||||
@@ -94,19 +94,19 @@ const MemeView = ({
|
|||||||
<Appbar.Header style={memeViewStyles.header}>
|
<Appbar.Header style={memeViewStyles.header}>
|
||||||
<Appbar.BackAction onPress={() => navigation.goBack()} />
|
<Appbar.BackAction onPress={() => navigation.goBack()} />
|
||||||
{/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */}
|
{/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */}
|
||||||
<Appbar.Content title={memes[index.current]?.title} />
|
<Appbar.Content title={memes[index]?.title} />
|
||||||
</Appbar.Header>
|
</Appbar.Header>
|
||||||
<FlashList
|
<FlashList
|
||||||
ref={flashListRef}
|
ref={flashListRef}
|
||||||
key={height}
|
key={height}
|
||||||
data={memes}
|
data={memes}
|
||||||
initialScrollIndex={index.current}
|
initialScrollIndex={index}
|
||||||
onScroll={event => {
|
onScroll={event => {
|
||||||
const newIndex = Math.round(
|
const newIndex = Math.round(
|
||||||
event.nativeEvent.contentOffset.x /
|
event.nativeEvent.contentOffset.x /
|
||||||
event.nativeEvent.layoutMeasurement.width,
|
event.nativeEvent.layoutMeasurement.width,
|
||||||
);
|
);
|
||||||
if (newIndex !== index.current) index.current = newIndex;
|
if (newIndex !== index) setIndex(newIndex);
|
||||||
}}
|
}}
|
||||||
estimatedItemSize={width}
|
estimatedItemSize={width}
|
||||||
estimatedListSize={{ height, width }}
|
estimatedListSize={{ height, width }}
|
||||||
@@ -126,14 +126,14 @@ const MemeView = ({
|
|||||||
<Appbar style={memeViewStyles.footer}>
|
<Appbar style={memeViewStyles.footer}>
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
icon={memes[index.current]?.isFavorite ? 'heart' : 'heart-outline'}
|
icon={memes[index]?.isFavorite ? 'heart' : 'heart-outline'}
|
||||||
onPress={() => favoriteMeme(realm, memes[index.current])}
|
onPress={() => favoriteMeme(realm, memes[index])}
|
||||||
disabled={isBlocked}
|
disabled={isBlocked}
|
||||||
/>
|
/>
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon="share"
|
icon="share"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
shareMeme(realm, storageUri, memes[index.current]).catch(() =>
|
shareMeme(realm, storageUri, memes[index]).catch(() =>
|
||||||
setSnackbarMessage('Failed to share meme!'),
|
setSnackbarMessage('Failed to share meme!'),
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
@@ -142,7 +142,7 @@ const MemeView = ({
|
|||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon="content-copy"
|
icon="content-copy"
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
await copyMeme(realm, storageUri, memes[index.current])
|
await copyMeme(realm, storageUri, memes[index])
|
||||||
.then(() => setSnackbarMessage('Meme copied!'))
|
.then(() => setSnackbarMessage('Meme copied!'))
|
||||||
.catch(() => setSnackbarMessage('Failed to copy meme!'));
|
.catch(() => setSnackbarMessage('Failed to copy meme!'));
|
||||||
}}
|
}}
|
||||||
@@ -151,7 +151,7 @@ const MemeView = ({
|
|||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon="pencil"
|
icon="pencil"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
editMeme(navigation, memes[index.current]);
|
editMeme(navigation, memes[index]);
|
||||||
}}
|
}}
|
||||||
disabled={isBlocked}
|
disabled={isBlocked}
|
||||||
/>
|
/>
|
||||||
@@ -159,7 +159,7 @@ const MemeView = ({
|
|||||||
icon="delete"
|
icon="delete"
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
setIsBlocked(true);
|
setIsBlocked(true);
|
||||||
await deleteMeme(realm, storageUri, memes[index.current]);
|
await deleteMeme(realm, storageUri, memes[index]);
|
||||||
setIsBlocked(false);
|
setIsBlocked(false);
|
||||||
}}
|
}}
|
||||||
disabled={isBlocked}
|
disabled={isBlocked}
|
||||||
|
Reference in New Issue
Block a user