Skip to content

Commit

Permalink
Remove media query from <Message>
Browse files Browse the repository at this point in the history
Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>
  • Loading branch information
automated-signal and EvanHahn-Signal committed Oct 19, 2021
1 parent 9728053 commit 01028bb
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions ts/components/conversation/Message.tsx
Expand Up @@ -279,8 +279,6 @@ type State = {
reactionViewerRoot: HTMLDivElement | null;
reactionPickerRoot: HTMLDivElement | null;

isWide: boolean;

canDeleteForEveryone: boolean;
};

Expand All @@ -298,8 +296,6 @@ export class Message extends React.PureComponent<Props, State> {

public reactionsContainerRefMerger = createRefMerger();

public wideMl: MediaQueryList;

public expirationCheckInterval: NodeJS.Timeout | undefined;

public expiredTimeout: NodeJS.Timeout | undefined;
Expand All @@ -311,9 +307,6 @@ export class Message extends React.PureComponent<Props, State> {
public constructor(props: Props) {
super(props);

this.wideMl = window.matchMedia('(min-width: 926px)');
this.wideMl.addEventListener('change', this.handleWideMlChange);

this.state = {
expiring: false,
expired: false,
Expand All @@ -325,8 +318,6 @@ export class Message extends React.PureComponent<Props, State> {
reactionViewerRoot: null,
reactionPickerRoot: null,

isWide: this.wideMl.matches,

canDeleteForEveryone: props.canDeleteForEveryone,
};
}
Expand Down Expand Up @@ -365,10 +356,6 @@ export class Message extends React.PureComponent<Props, State> {
return Boolean(reactions && reactions.length);
}

public handleWideMlChange = (event: MediaQueryListEvent): void => {
this.setState({ isWide: event.matches });
};

public captureMenuTrigger = (triggerRef: Trigger): void => {
this.menuTriggerRef = triggerRef;
};
Expand Down Expand Up @@ -466,8 +453,6 @@ export class Message extends React.PureComponent<Props, State> {
}
this.toggleReactionViewer(true);
this.toggleReactionPicker(true);

this.wideMl.removeEventListener('change', this.handleWideMlChange);
}

public componentDidUpdate(prevProps: Props): void {
Expand Down Expand Up @@ -1333,7 +1318,7 @@ export class Message extends React.PureComponent<Props, State> {
return null;
}

const { reactionPickerRoot, isWide } = this.state;
const { reactionPickerRoot } = this.state;

const multipleAttachments = attachments && attachments.length > 1;
const firstAttachment = attachments && attachments[0];
Expand Down Expand Up @@ -1362,8 +1347,10 @@ export class Message extends React.PureComponent<Props, State> {
<Reference>
{({ ref: popperRef }) => {
// Only attach the popper reference to the reaction button if it is
// visible in the page (it is hidden when the page is narrow)
const maybePopperRef = isWide ? popperRef : undefined;
// visible (it is hidden when the timeline is narrow)
const maybePopperRef = this.shouldShowAdditionalMenuButtons()
? popperRef
: undefined;

return (
// This a menu meant for mouse use only
Expand Down Expand Up @@ -1413,10 +1400,11 @@ export class Message extends React.PureComponent<Props, State> {
const menuButton = (
<Reference>
{({ ref: popperRef }) => {
// Only attach the popper reference to the collapsed menu button if
// the reaction button is not visible in the page (it is hidden when
// the page is narrow)
const maybePopperRef = !isWide ? popperRef : undefined;
// Only attach the popper reference to the collapsed menu button if the reaction
// button is not visible (it is hidden when the timeline is narrow)
const maybePopperRef = !this.shouldShowAdditionalMenuButtons()
? popperRef
: undefined;

return (
<StopPropagation className="module-message__buttons__menu--container">
Expand Down

0 comments on commit 01028bb

Please sign in to comment.