Skip to content

Commit

Permalink
Ensure that all arrays are de-duped
Browse files Browse the repository at this point in the history
  • Loading branch information
micahlt committed Mar 14, 2024
1 parent e4d43fd commit be4e14b
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ android {
applicationId "com.micahlindley.offsides"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 11
versionName "0.4.0"
versionCode 12
versionName "0.4.1"
}
signingConfigs {
debug {
Expand Down
Binary file modified android/app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions android/app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 11,
"versionName": "0.4.0",
"versionCode": 12,
"versionName": "0.4.1",
"outputFile": "app-release.apk"
}
],
Expand Down
2 changes: 1 addition & 1 deletion docs/latest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"latestVersion": "0.4.0"
"latestVersion": "0.4.1"
}
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "offsides",
"version": "0.4.0",
"version": "0.4.1",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down
5 changes: 4 additions & 1 deletion src/components/CommentModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Appbar, useTheme, Text, Divider } from 'react-native-paper';
import { AppContext } from '../App';
import Comment from './Comment';
import Post from './Post';
import useUniqueList from '../hooks/useUniqueList';

function CommentModal({ navigation, route }) {
/** @type {{postID: String, postObj: SidechatPostOrComment}} */
Expand Down Expand Up @@ -39,6 +40,8 @@ function CommentModal({ navigation, route }) {
});
};

const uniqueComments = useUniqueList(comments);

return (
<View style={{ backgroundColor: colors.background, flex: 1 }}>
<StatusBar animated={true} backgroundColor={colors.elevation.level2} />
Expand All @@ -49,7 +52,7 @@ function CommentModal({ navigation, route }) {
<View style={{ ...style.container, backgroundColor: colors.background }}>
<FlatList
contentContainerStyle={{ gap: 10, padding: 10 }}
data={comments}
data={uniqueComments}
keyExtractor={item => item.id}
renderItem={renderItem}
estimatedItemSize={200}
Expand Down
9 changes: 9 additions & 0 deletions src/hooks/useUniqueList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

export default function useUniqueList(list) {
return React.useMemo(() => {
return list.filter(
({ id }, i, _arr) => _arr.findIndex(elem => elem.id === id) === i,
);
}, [list]);
}
1 change: 1 addition & 0 deletions src/screens/ExploreGroupsScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { View, StatusBar, FlatList } from 'react-native';
import { Appbar, useTheme, Card, ProgressBar } from 'react-native-paper';
import { AppContext } from '../App';
import Group from '../components/Group';
import useUniqueList from '../hooks/useUniqueList';

const BORDER_RADIUS = 15;

Expand Down
12 changes: 3 additions & 9 deletions src/screens/HomeScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { AppContext } from '../App';
import { useFocusEffect } from '@react-navigation/native';
import Post from '../components/Post';
import GroupPicker from '../components/GroupPicker';
import useUniqueList from '../hooks/useUniqueList';

const BORDER_RADIUS = 12;

Expand Down Expand Up @@ -62,16 +63,9 @@ function HomeScreen({ navigation }) {
});
}
}, [postCategory, currentGroupId]);
React.useEffect(() => {
const newRenderedPostIds = new Set(renderedPostIds);
posts.forEach(post => newRenderedPostIds.add(post.id));
setRenderedPostIds(newRenderedPostIds);
}, [posts]);
const uniquePosts = useUniqueList(posts);
const renderItem = React.useCallback(each => {
// Check if the post has already been rendered
if (renderedPostIds.has(each.id)) {
return null; // Skip rendering if the post is a duplicate
}
return <Post post={each.item} nav={navigation} key={each.id} />;
});
const fetchPosts = refresh => {
Expand Down Expand Up @@ -210,7 +204,7 @@ function HomeScreen({ navigation }) {
<ProgressBar indeterminate={true} visible={loadingPosts} />
<FlatList
contentContainerStyle={{ gap: 10, padding: 10 }}
data={posts}
data={uniquePosts}
renderItem={renderItem}
estimatedItemSize={350}
windowSize={10}
Expand Down
5 changes: 1 addition & 4 deletions src/screens/SettingsScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ function SettingsScreen({ navigation }) {
mode="contained-tonal"
onPress={() => {
Linking.openURL(
`https://github.com/micahlt/offsides/releases/download/${updateAvailable}/offsides-${updateAvailable.replaceAll(
'.',
'-',
)}.apk`,
`https://github.com/micahlt/offsides/releases/${updateAvailable}/`,
);
}}
style={{
Expand Down

0 comments on commit be4e14b

Please sign in to comment.