Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort blocked list #760

Merged
merged 7 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/features/settings/blocks/BlockedCommunities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import { ListHeader } from "../shared/formatting";
export default function BlockedCommunities() {
const dispatch = useAppDispatch();
const [loading, setLoading] = useState(false);

const communities = useAppSelector(
(state) => state.auth.site?.my_user?.community_blocks,
);

const sortedCommunities = communities
?.slice()
.sort((a, b) => a.community.name.localeCompare(b.community.name));

async function remove(community: CommunityBlockView) {
setLoading(true);

Expand All @@ -37,8 +42,8 @@ export default function BlockedCommunities() {
<IonLabel>Blocked Communities</IonLabel>
</ListHeader>
<IonList inset>
{communities?.length ? (
communities.map((community) => (
{sortedCommunities?.length ? (
sortedCommunities.map((community) => (
<IonItemSliding key={community.community.id}>
<IonItemOptions side="end" onIonSwipe={() => remove(community)}>
<IonItemOption
Expand All @@ -60,6 +65,7 @@ export default function BlockedCommunities() {
</InsetIonItem>
)}
</IonList>

<IonLoading isOpen={loading} />
</>
);
Expand Down
11 changes: 9 additions & 2 deletions src/features/settings/blocks/BlockedUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import { ListHeader } from "../shared/formatting";
export default function BlockedUsers() {
const dispatch = useAppDispatch();
const [loading, setLoading] = useState(false);

const users = useAppSelector(
(state) => state.auth.site?.my_user?.person_blocks,
);

const sortedUsers = users
?.slice()
.sort((a, b) => a.target.name.localeCompare(b.target.name));

async function remove(user: PersonBlockView) {
setLoading(true);

Expand All @@ -36,9 +41,10 @@ export default function BlockedUsers() {
<ListHeader>
<IonLabel>Blocked Users</IonLabel>
</ListHeader>

<IonList inset>
{users?.length ? (
users.map((user) => (
{sortedUsers?.length ? (
sortedUsers.map((user) => (
<IonItemSliding key={user.target.id}>
<IonItemOptions side="end" onIonSwipe={() => remove(user)}>
<IonItemOption
Expand All @@ -60,6 +66,7 @@ export default function BlockedUsers() {
</InsetIonItem>
)}
</IonList>

<IonLoading isOpen={loading} />
</>
);
Expand Down