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

Improved how muted streams are displayed on Streams screen #5522

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions src/streams/StreamIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import type { Node } from 'react';
import type { TextStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';

import { IconMute, IconStream, IconPrivate, IconWebPublic } from '../common/Icons';
import { IconStream, IconPrivate, IconWebPublic } from '../common/Icons';

type Props = $ReadOnly<{|
color?: string,
Expand All @@ -15,12 +15,11 @@ type Props = $ReadOnly<{|
|}>;

Syed-Ansar marked this conversation as resolved.
Show resolved Hide resolved
export default function StreamIcon(props: Props): Node {
const { color, style, isPrivate, isMuted, isWebPublic, size } = props;
const { color, style, isPrivate, isWebPublic, size } = props;

let Component = undefined;
if (isMuted) {
Component = IconMute;
} else if (isPrivate) {

if (isPrivate) {
Comment on lines -21 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component StreamIcon is used in several other places besides the Streams screen. So this change affects them too.

It should therefore go in its own commit, with a commit message that describes the changes it's making and why.

That commit can come before the commit that changes the sorting.

Component = IconPrivate;
} else if (isWebPublic ?? false) {
Component = IconWebPublic;
Expand Down
3 changes: 2 additions & 1 deletion src/streams/SubscriptionsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export default function SubscriptionsScreen(props: Props): Node {
.sort((a, b) => caseInsensitiveCompareFunc(a.name, b.name));
return [
{ key: 'Pinned', data: sortedSubscriptions.filter(x => x.pin_to_top) },
{ key: 'Unpinned', data: sortedSubscriptions.filter(x => !x.pin_to_top) },
{ key: 'Unpinned', data: sortedSubscriptions.filter(x => !x.pin_to_top && x.in_home_view) },
{ key: 'Muted', data: sortedSubscriptions.filter(x => !x.pin_to_top && !x.in_home_view) },
Comment on lines 61 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid going through the list of subscriptions three times here. We can do it with just one pass, by using a plain old loop instead of .filter.

That will also let us deduplicate the conditionals on .pin_to_top and .in_home_view.

With the old code it's a bit of a closer call between those advantages of a loop, and the declarative neatness of this .filter version. But when there's three filters instead of two, and the conditions get further duplicated between them like this, it's time to make it a loop.

Let's have one commit that's NFC (https://github.com/zulip/zulip-mobile/blob/main/docs/glossary.md#nfc ) and just changes the existing code to use a loop and make a single pass. Then a subsequent commit can make the substantive change here.

];
}, [subscriptions]);

Expand Down