diff --git a/src/components/Popup.tsx b/src/components/Popup.tsx index c615d389..c2ee087d 100644 --- a/src/components/Popup.tsx +++ b/src/components/Popup.tsx @@ -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; @@ -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 ; } @@ -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} diff --git a/src/components/PullRequestList.tsx b/src/components/PullRequestList.tsx index 67952fb5..1f141894 100644 --- a/src/components/PullRequestList.tsx +++ b/src/components/PullRequestList.tsx @@ -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; @@ -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; @@ -33,6 +47,16 @@ export interface PullRequestListProps { export const PullRequestList = observer((props: PullRequestListProps) => ( + {props.newCommitsNotificationToggled !== null && ( + + + Notify me of new commits + + )} {props.pullRequests === null ? ( ) : props.pullRequests.length === 0 ? ( diff --git a/src/filtering/filters.ts b/src/filtering/filters.ts index 0180c179..01af98df 100644 --- a/src/filtering/filters.ts +++ b/src/filtering/filters.ts @@ -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( diff --git a/src/filtering/status.ts b/src/filtering/status.ts index b7e7ef2a..b7d62eb4 100644 --- a/src/filtering/status.ts +++ b/src/filtering/status.ts @@ -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)) ); } diff --git a/src/state/core.ts b/src/state/core.ts index fe287194..eb0ed0ad 100644 --- a/src/state/core.ts +++ b/src/state/core.ts @@ -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; diff --git a/src/storage/mute-configuration.ts b/src/storage/mute-configuration.ts index 9c7a3594..e540c772 100644 --- a/src/storage/mute-configuration.ts +++ b/src/storage/mute-configuration.ts @@ -6,6 +6,7 @@ import { PullRequestReference, RepoReference } from "../github-api/api"; export const NOTHING_MUTED: MuteConfiguration = { mutedPullRequests: [], ignored: {}, + ignoreNewCommits: false, }; export interface MuteConfiguration { @@ -21,6 +22,8 @@ export interface MuteConfiguration { ignored?: { [owner: string]: IgnoreConfiguration; }; + + ignoreNewCommits?: boolean; } export function addMute(