Skip to content

Commit

Permalink
Add a "Notify me of new commits" checkbox (on by default) (#775)
Browse files Browse the repository at this point in the history
Fixes #772.
  • Loading branch information
fwouts authored Jun 4, 2020
1 parent a56ac89 commit 71cac39
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
18 changes: 14 additions & 4 deletions src/components/Popup.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import styled from "@emotion/styled";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { observer } from "mobx-react-lite";
import React, { useState } from "react";
import { Badge, Tab, Tabs } from "react-bootstrap";
import { Filter } from "../filtering/filters";
import { isRunningAsPopup } from "../popup-environment";
import { Core } from "../state/core";
import { PullRequest, ref } from "../storage/loaded-state";
import { MuteType } from "../storage/mute-configuration";
import { Link } from "./design/Link";
import { Row } from "./design/Row";
import { IgnoredRepositories } from "./IgnoredRepositories";
import { Loader } from "./Loader";
import { PullRequestList } from "./PullRequestList";
import { Settings } from "./Settings";
import { Status } from "./Status";
import { Row } from "./design/Row";
import { Link } from "./design/Link";
import styled from "@emotion/styled";
import { isRunningAsPopup } from "../popup-environment";

export interface PopupProps {
core: Core;
Expand Down Expand Up @@ -50,6 +50,10 @@ export const Popup = observer((props: PopupProps) => {
props.core.unmutePullRequest(ref(pullRequest));
};

const onToggleNewCommitsNotification = () => {
props.core.toggleNewCommitsNotificationSetting();
};

if (props.core.overallStatus !== "loaded") {
return <Loader />;
}
Expand Down Expand Up @@ -160,6 +164,12 @@ export const Popup = observer((props: PopupProps) => {
? "allow-unmuting"
: "none"
}
newCommitsNotificationToggled={
state.currentFilter === Filter.INCOMING
? !props.core.muteConfiguration.ignoreNewCommits
: null
}
onToggleNewCommitsNotification={onToggleNewCommitsNotification}
onOpenAll={onOpenAll}
onOpen={onOpen}
onMute={onMute}
Expand Down
24 changes: 24 additions & 0 deletions src/components/PullRequestList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ const List = styled.div`
margin-bottom: 16px;
`;

const NewCommitsToggle = styled.label`
padding: 8px;
margin: 0;
display: flex;
flex-direction: row;
align-items: center;
`;

const NewCommitsCheckbox = styled.input`
margin-right: 8px;
`;

const OpenAllParagraph = styled(Paragraph)`
text-align: center;
color: #777;
Expand All @@ -25,6 +37,8 @@ export interface PullRequestListProps {
pullRequests: EnrichedPullRequest[] | null;
emptyMessage: string;
mutingConfiguration: "allow-muting" | "allow-unmuting" | "none";
newCommitsNotificationToggled: boolean | null;
onToggleNewCommitsNotification?(): void;
onOpenAll(): void;
onOpen(pullRequestUrl: string): void;
onMute(pullRequest: PullRequest, muteType: MuteType): void;
Expand All @@ -33,6 +47,16 @@ export interface PullRequestListProps {

export const PullRequestList = observer((props: PullRequestListProps) => (
<List>
{props.newCommitsNotificationToggled !== null && (
<NewCommitsToggle>
<NewCommitsCheckbox
type="checkbox"
checked={props.newCommitsNotificationToggled}
onChange={props.onToggleNewCommitsNotification}
/>
Notify me of new commits
</NewCommitsToggle>
)}
{props.pullRequests === null ? (
<Loader />
) : props.pullRequests.length === 0 ? (
Expand Down
5 changes: 3 additions & 2 deletions src/filtering/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ export function filterPullRequests(
state: pullRequestState(pr, userLogin),
...pr,
}));
const ignoreNewCommits = !!muteConfiguration.ignoreNewCommits;
return {
incoming: enrichedPullRequests.filter(
(pr) =>
isReviewRequired(pr.state) &&
isReviewRequired(pr.state, ignoreNewCommits) &&
isMuted(env, pr, muteConfiguration) === MutedResult.VISIBLE
),
muted: enrichedPullRequests.filter(
(pr) =>
isReviewRequired(pr.state) &&
isReviewRequired(pr.state, ignoreNewCommits) &&
isMuted(env, pr, muteConfiguration) === MutedResult.MUTED
),
reviewed: enrichedPullRequests.filter(
Expand Down
9 changes: 7 additions & 2 deletions src/filtering/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,14 @@ export interface OutgoingState {
approvedByEveryone: boolean;
}

export function isReviewRequired(state: PullRequestState) {
export function isReviewRequired(
state: PullRequestState,
ignoreNewCommits: boolean
) {
return (
state.kind === "incoming" &&
(state.newReviewRequested || state.authorResponded || state.newCommit)
(state.newReviewRequested ||
state.authorResponded ||
(!ignoreNewCommits && state.newCommit))
);
}
8 changes: 8 additions & 0 deletions src/state/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ export class Core {
this.updateBadge();
}

async toggleNewCommitsNotificationSetting() {
await this.saveMuteConfiguration({
...this.muteConfiguration,
ignoreNewCommits: !this.muteConfiguration.ignoreNewCommits,
});
this.updateBadge();
}

@computed
get filteredPullRequests(): FilteredPullRequests | null {
const lastCheck = this.loadedState;
Expand Down
3 changes: 3 additions & 0 deletions src/storage/mute-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PullRequestReference, RepoReference } from "../github-api/api";
export const NOTHING_MUTED: MuteConfiguration = {
mutedPullRequests: [],
ignored: {},
ignoreNewCommits: false,
};

export interface MuteConfiguration {
Expand All @@ -21,6 +22,8 @@ export interface MuteConfiguration {
ignored?: {
[owner: string]: IgnoreConfiguration;
};

ignoreNewCommits?: boolean;
}

export function addMute(
Expand Down

0 comments on commit 71cac39

Please sign in to comment.