Skip to content

Commit

Permalink
Merge pull request #71 from FlemingVincent/feature/fix-two-bugs
Browse files Browse the repository at this point in the history
Fix two bugs related to displaying cirles.
  • Loading branch information
flemingvincent authored Nov 28, 2023
2 parents 4558134 + 961683c commit a1e6741
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/routes/protected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Join from "@/screens/protected/Join";
import Settings from "@/screens/protected/Settings";

export type ProtectedStackParamList = {
Home: undefined;
Home: { newCircleAdded: string | null };
Settings: undefined;
Join: undefined;
Create: undefined;
Expand All @@ -21,7 +21,11 @@ export function ProtectedStack() {
headerShown: false,
}}
>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen
name="Home"
component={Home}
initialParams={{ newCircleAdded: null }}
/>
<Stack.Screen name="Settings" component={Settings} />
<Stack.Screen name="Join" component={Join} />
<Stack.Screen name="Create" component={Create} />
Expand Down
2 changes: 1 addition & 1 deletion src/screens/protected/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default function Create({ navigation }: JoinProps) {
});

setTimeout(() => {
navigation.navigate("Home");
navigation.navigate("Home", { newCircleAdded: name });
}, 1000);
} catch (error) {
console.log(error);
Expand Down
26 changes: 24 additions & 2 deletions src/screens/protected/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export default function Home({ navigation }: HomeProps) {
// TODO: Get a user's information, given their id, from the db
const user = dummyProfiles.find((profile) => profile.id === profileId);

if (user) {
if (user && user.id !== profile?.id) {
// TODO: Get a user's location from the db
usersInCircle.push(
<View style={tw`mt-4`}>
Expand All @@ -494,7 +494,13 @@ export default function Home({ navigation }: HomeProps) {
);
}
});

if (usersInCircle.length === 0) {
return (
<View style={tw`mt-4`}>
<Text variant="caption2">You are the only one in this circle!</Text>
</View>
);
}
return usersInCircle;
};

Expand Down Expand Up @@ -553,6 +559,21 @@ export default function Home({ navigation }: HomeProps) {
updateProfileIdsInCurrentCircle();
}, [selectedCircle]);

// Fetch all the user's circles from db if a new circle has been created.
const newCirclePossiblyAdded = useRef(false);
const newCircleAdded = navigation.getState().routes[0].params?.newCircleAdded;
const updateStateIfNewlyCreatedCircle = async () => {
if (
newCircleAdded !== null &&
newCircleAdded !== undefined &&
newCirclePossiblyAdded.current === true
) {
newCirclePossiblyAdded.current = false;
await getUsersCircles();
}
};
updateStateIfNewlyCreatedCircle();

useEffect(() => {
(async () => {
checkPermissionsAndUpdateScreen();
Expand Down Expand Up @@ -591,6 +612,7 @@ export default function Home({ navigation }: HomeProps) {
variant="primary"
label="Create a Circle"
onPress={() => {
newCirclePossiblyAdded.current = true;
navigation.navigate("Create");
}}
/>
Expand Down

0 comments on commit a1e6741

Please sign in to comment.