Skip to content

Commit

Permalink
add - added EmptyScreen when array is empty for all tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gehrkej committed Aug 21, 2024
1 parent 7d0f31c commit d1464df
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 156 deletions.
88 changes: 48 additions & 40 deletions app/segments/(team)/blacklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button, List } from "react-native-paper";
import { themeColors } from "~/Constants";
import { getErrorString } from "~/Utility";
import DialogComponent from "~/components/dialog";
import EmptyScreen from "~/components/emptyScreen";
import ErrorComponent from "~/components/errorComponent";
import Loading from "~/components/loading";
import RefreshInvalidate from "~/components/refreshInvalidate";
Expand Down Expand Up @@ -57,48 +58,55 @@ function Blacklist() {
borderRadius: 5,
}}
>
{Object.keys(blacklist).map((userId) => {
return (
<List.Item
title={blacklist[userId].email}
key={userId}
right={() => (
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingLeft: 10,
}}
>
<Button
onPress={async () => {
try {
if (unbanLoading[userId]) return;
setUnbanLoading({ ...unbanLoading, [userId]: true });
await removeBlacklist(currentTeamId, userId);
await invalidateMultipleKeys(
queryClient,
invalidateKeys,
);
setUnbanCounter((prev) => prev + 1);
setSnackbarVisible(true);
setUnbanLoading({ ...unbanLoading, [userId]: false });
} catch (e) {
console.log(e);
setUnbanLoading({ ...unbanLoading, [userId]: false });
showDialog("Error", getErrorString(e));
}
{Object.keys(blacklist).length === 0 ? (
<EmptyScreen
invalidateKeys={invalidateKeys}
text={"No users found on blacklist"}
/>
) : (
Object.keys(blacklist).map((userId) => {
return (
<List.Item
title={blacklist[userId].email}
key={userId}
right={() => (
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingLeft: 10,
}}
textColor={themeColors.accent}
loading={unbanLoading[userId]}
>
Unban
</Button>
</View>
)}
/>
);
})}
<Button
onPress={async () => {
try {
if (unbanLoading[userId]) return;
setUnbanLoading({ ...unbanLoading, [userId]: true });
await removeBlacklist(currentTeamId, userId);
await invalidateMultipleKeys(
queryClient,
invalidateKeys,
);
setUnbanCounter((prev) => prev + 1);
setSnackbarVisible(true);
setUnbanLoading({ ...unbanLoading, [userId]: false });
} catch (e) {
console.log(e);
setUnbanLoading({ ...unbanLoading, [userId]: false });
showDialog("Error", getErrorString(e));
}
}}
textColor={themeColors.accent}
loading={unbanLoading[userId]}
>
Unban
</Button>
</View>
)}
/>
);
})
)}
</List.Section>
</ScrollView>
);
Expand Down
88 changes: 48 additions & 40 deletions app/segments/(team)/invitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Button, List } from "react-native-paper";
import { themeColors } from "~/Constants";
import { getErrorString } from "~/Utility";
import DialogComponent from "~/components/dialog";
import EmptyScreen from "~/components/emptyScreen";
import ErrorComponent from "~/components/errorComponent";
import Loading from "~/components/loading";
import RefreshInvalidate from "~/components/refreshInvalidate";
Expand Down Expand Up @@ -99,48 +100,55 @@ export function Invitelist() {
borderRadius: 5,
}}
>
{Object.keys(invitelist).map((inviteId) => {
return (
<List.Item
title={invitelist[inviteId].email}
key={inviteId}
right={() => (
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingLeft: 10,
}}
>
<Button
onPress={async () => {
setRemoveLoading({
...removeLoading,
[inviteId]: true,
});
await removeInvitelist(currentTeamId, inviteId);
await invalidateMultipleKeys(
queryClient,
invalidateKeys,
);
setRemoveCounter((prev) => prev + 1);
setSnackbarVisible(true);
setRemoveLoading({
...removeLoading,
[inviteId]: false,
});
{Object.keys(invitelist).length === 0 ? (
<EmptyScreen
invalidateKeys={invalidateKeys}
text={"No invites found"}
/>
) : (
Object.keys(invitelist).map((inviteId) => {
return (
<List.Item
title={invitelist[inviteId].email}
key={inviteId}
right={() => (
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingLeft: 10,
}}
height={38} //so the button doesn't change size because of the spinner
textColor={themeColors.accent}
loading={removeLoading[inviteId]}
>
Remove
</Button>
</View>
)}
/>
);
})}
<Button
onPress={async () => {
setRemoveLoading({
...removeLoading,
[inviteId]: true,
});
await removeInvitelist(currentTeamId, inviteId);
await invalidateMultipleKeys(
queryClient,
invalidateKeys,
);
setRemoveCounter((prev) => prev + 1);
setSnackbarVisible(true);
setRemoveLoading({
...removeLoading,
[inviteId]: false,
});
}}
height={38} //so the button doesn't change size because of the spinner
textColor={themeColors.accent}
loading={removeLoading[inviteId]}
>
Remove
</Button>
</View>
)}
/>
);
})
)}
</List.Section>
</ScrollView>
<Text>{statusText}</Text>
Expand Down
160 changes: 84 additions & 76 deletions app/segments/(team)/waitlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ActivityIndicator, Button, List } from "react-native-paper";
import { themeColors } from "~/Constants";
import { getErrorString } from "~/Utility";
import DialogComponent from "~/components/dialog";
import EmptyScreen from "~/components/emptyScreen";
import ErrorComponent from "~/components/errorComponent";
import Loading from "~/components/loading";
import RefreshInvalidate from "~/components/refreshInvalidate";
Expand Down Expand Up @@ -61,84 +62,91 @@ function Waitlist() {
borderRadius: 5,
}}
>
{Object.keys(waitlist).map((userId) => {
console.log("waitlist", waitlist[userId]);
return (
<List.Item
title={waitlist[userId].email}
key={userId}
right={() => (
<View
style={{
alignItems: "center",
justifyContent: "center",
}}
height={38} //so the button doesn't change size because of the spinner
width={100}
>
{loading[userId] ? (
<ActivityIndicator color={themeColors.accent} />
) : (
<View
style={{
flexDirection: "row",
paddingLeft: 10,
}}
>
<Button
onPress={async () => {
setLoading({ ...loading, [userId]: true });
await addToTeam(
currentTeamId,
userId,
waitlist[userId],
);
await removeWaitlist(currentTeamId, userId);
await invalidateMultipleKeys(
queryClient,
invalidateKeys,
);
if (lastDecision !== "Accepted") {
setLastDecision("Accepted");
setSnackbarCounter(1);
} else {
setSnackbarCounter((prev) => prev + 1);
}
setSnackbarVisible(true);
setLoading({ ...loading, [userId]: false });
{Object.keys(waitlist).length === 0 ? (
<EmptyScreen
invalidateKeys={invalidateKeys}
text={"No users found on waitlist"}
/>
) : (
Object.keys(waitlist).map((userId) => {
console.log("waitlist", waitlist[userId]);
return (
<List.Item
title={waitlist[userId].email}
key={userId}
right={() => (
<View
style={{
alignItems: "center",
justifyContent: "center",
}}
height={38} //so the button doesn't change size because of the spinner
width={100}
>
{loading[userId] ? (
<ActivityIndicator color={themeColors.accent} />
) : (
<View
style={{
flexDirection: "row",
paddingLeft: 10,
}}
textColor={"green"}
>
Accept
</Button>
<Button
onPress={async () => {
setLoading({ ...loading, [userId]: true });
await removeWaitlist(currentTeamId, userId);
await invalidateMultipleKeys(
queryClient,
invalidateKeys,
);
if (lastDecision !== "Rejected") {
setLastDecision("Rejected");
setSnackbarCounter(1);
} else {
setSnackbarCounter((prev) => prev + 1);
}
setSnackbarVisible(true);
setLoading({ ...loading, [userId]: false });
}}
textColor={"red"}
>
Reject
</Button>
</View>
)}
</View>
)}
/>
);
})}
<Button
onPress={async () => {
setLoading({ ...loading, [userId]: true });
await addToTeam(
currentTeamId,
userId,
waitlist[userId],
);
await removeWaitlist(currentTeamId, userId);
await invalidateMultipleKeys(
queryClient,
invalidateKeys,
);
if (lastDecision !== "Accepted") {
setLastDecision("Accepted");
setSnackbarCounter(1);
} else {
setSnackbarCounter((prev) => prev + 1);
}
setSnackbarVisible(true);
setLoading({ ...loading, [userId]: false });
}}
textColor={"green"}
>
Accept
</Button>
<Button
onPress={async () => {
setLoading({ ...loading, [userId]: true });
await removeWaitlist(currentTeamId, userId);
await invalidateMultipleKeys(
queryClient,
invalidateKeys,
);
if (lastDecision !== "Rejected") {
setLastDecision("Rejected");
setSnackbarCounter(1);
} else {
setSnackbarCounter((prev) => prev + 1);
}
setSnackbarVisible(true);
setLoading({ ...loading, [userId]: false });
}}
textColor={"red"}
>
Reject
</Button>
</View>
)}
</View>
)}
/>
);
})
)}
</List.Section>
</ScrollView>
);
Expand Down

0 comments on commit d1464df

Please sign in to comment.