-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to star pull requests
Closes #4
- Loading branch information
Showing
10 changed files
with
152 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { UseQueryResult, useQueries } from "@tanstack/react-query"; | ||
import { Config } from "./config"; | ||
import { getPulls, getViewer } from "./github"; | ||
import { Pull } from "./model"; | ||
|
||
export const usePullRequests = (config: Config): UseQueryResult<Pull[]>[] => { | ||
const viewers = useQueries({ | ||
queries: config.connections.map(connection => ({ | ||
queryKey: ['viewer', connection.host], | ||
queryFn: () => getViewer(connection), | ||
staleTime: Infinity, | ||
})), | ||
}) | ||
return useQueries({ | ||
queries: config.sections.flatMap(section => { | ||
return config.connections.map((connection, idx) => ({ | ||
queryKey: ['pulls', connection.host, connection.auth, section.search], | ||
queryFn: () => getPulls(connection, section.search, viewers[idx].data?.login || ""), | ||
refetchInterval: 300_000, | ||
refetchIntervalInBackground: true, | ||
// refetchOnWindowFocus: false, | ||
staleTime: 60_000, | ||
enabled: viewers[idx].data !== undefined, | ||
})) | ||
}), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useCallback, useContext } from "react"; | ||
import { Button, Card, H3, Spinner } from "@blueprintjs/core"; | ||
|
||
import { ConfigContext } from "../config"; | ||
import PullTable from "../components/PullTable"; | ||
import { usePullRequests } from "../queries"; | ||
|
||
|
||
export default function Stars() { | ||
const { config } = useContext(ConfigContext) | ||
const results = usePullRequests(config) | ||
|
||
const stars = new Set(config.stars) | ||
|
||
const isLoading = results.some(res => res.isLoading) | ||
const isFetching = results.some(res => res.isFetching) | ||
|
||
const data = config.connections.map((connection, idx) => ({ | ||
host: connection.host, | ||
pulls: config.sections.flatMap((_, idx2) => results[idx + config.connections.length * idx2].data || []).filter(v => stars.has(v.number)) | ||
})) | ||
const count = data.map(res => res.pulls.length).reduce((acc, v) => acc + v, 0) | ||
|
||
const refetchAll = useCallback(async () => { | ||
await Promise.all(results.map(res => res.refetch())); | ||
}, [results]); | ||
|
||
return ( | ||
<> | ||
<div className="flex mb-4"> | ||
<H3 className="grow">Starred pull requests</H3> | ||
<Button | ||
icon="refresh" | ||
disabled={isFetching} | ||
loading={isFetching} | ||
className="ml-4" | ||
onClick={refetchAll}/> | ||
</div> | ||
|
||
<Card className="mt-4"> | ||
{isLoading | ||
? <Spinner/> | ||
: count > 0 | ||
? <PullTable data={data}/> | ||
: <p className="no-results">No results</p>} | ||
</Card> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ | |
flex-grow: 1; | ||
} | ||
|
||
.cursor-pointer { | ||
cursor: pointer; | ||
} | ||
|
||
.text-sm { | ||
font-size: @pt-font-size-small; | ||
} | ||
|