Skip to content

Commit

Permalink
Merge pull request #89 from sqrl-planner/develop
Browse files Browse the repository at this point in the history
Add latest tag and last updated to about modal
  • Loading branch information
eamonma authored Jul 5, 2022
2 parents b46319c + 32a4f9a commit 03137fa
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 31 deletions.
107 changes: 81 additions & 26 deletions components/AboutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,90 @@ const Contributor = ({
src={contributor.avatar_url}
/>
{contributor.login}
<ExternalLinkIcon mx={1} />
{/* <ExternalLinkIcon mx={1} /> */}
</Link>
)
}

const AboutModal = ({ isOpen, onClose }: props) => {
const [contributors, setContributors] = useState<{
gator: Array<any>
sqrlClient: Array<any>
sqrlServer: Array<any>
client: Array<any>
server: Array<any>
}>({
gator: [],
sqrlClient: [],
sqrlServer: [],
client: [],
server: [],
})

const [lastUpdated, setLastUpdated] = useState<{
gator: Date
server: Date
client: Date
}>({
gator: new Date(),
client: new Date(),
server: new Date()
})

const [latestVersion, setLatestVersion] = useState<{
gator: string
server: string
client: string
}>({
gator: "",
client: "",
server: "",
})

useEffect(() => {
;(async () => {
const client = (await (
await fetch("/api/github?repositoryName=sqrl-client")
const clientContributors = (await (
await fetch("/api/github/contributors?repositoryName=sqrl-client")
).json()) as unknown as Array<any>
const server = (await (
await fetch("/api/github?repositoryName=sqrl-server")
const serverContributors = (await (
await fetch("/api/github/contributors?repositoryName=sqrl-server")
).json()) as unknown as Array<any>
const gator = (await (
await fetch("/api/github?repositoryName=gator")
const gatorContributors = (await (
await fetch("/api/github/contributors?repositoryName=gator")
).json()) as unknown as Array<any>

const clientLastUpdated = await ((await fetch(
"/api/github/lastUpdated?repositoryName=sqrl-client"
))).json() as string
const serverLastUpdated = await (await fetch((
"/api/github/lastUpdated?repositoryName=sqrl-server"
))).json() as string
const gatorLastUpdated = await (await fetch((
"/api/github/lastUpdated?repositoryName=gator"
))).json() as string

const clientLatestVersion = await (await fetch((
"/api/github/latestVersion?repositoryName=sqrl-client"
))).text() as string
const serverLatestVersion = await (await fetch((
"/api/github/latestVersion?repositoryName=sqrl-server"
))).text() as string
const gatorLatestVersion = await (await fetch((
"/api/github/latestVersion?repositoryName=gator"
))).text() as string

setContributors({
gator,
sqrlServer: server,
sqrlClient: client,
gator: gatorContributors,
server: serverContributors,
client: clientContributors,
})

setLastUpdated({
gator: new Date(gatorLastUpdated),
server: new Date(serverLastUpdated),
client: new Date(clientLastUpdated),
})

setLatestVersion({
gator: JSON.parse(gatorLatestVersion),
server: JSON.parse(serverLatestVersion),
client: JSON.parse(clientLatestVersion),
})
})()
}, [])
Expand Down Expand Up @@ -120,8 +172,9 @@ const AboutModal = ({ isOpen, onClose }: props) => {
bg={useColorModeValue("blue.50", "blue.800")}
href="https://github.com/sqrl-planner/sqrl-client"
>
<Icon as={FaGithub} /> sqrl-client <ExternalLinkIcon />
<Icon as={FaGithub} /> sqrl-client: {latestVersion.client} <ExternalLinkIcon />
</Link>
<Box opacity={0.6} fontSize="sm" mb={2}>{t("last-updated")} {lastUpdated.client.toLocaleDateString()}.</Box>
<Box opacity={0.8}>{t("sqrl-client-description")}</Box>

<Heading
Expand All @@ -142,8 +195,8 @@ const AboutModal = ({ isOpen, onClose }: props) => {
flexWrap="wrap"
justifyContent="stretch"
>
{contributors?.sqrlClient &&
contributors?.sqrlClient.map((contributor) => (
{contributors?.client &&
contributors?.client.map((contributor) => (
<Contributor
contributor={contributor}
key={contributor.id}
Expand All @@ -168,9 +221,10 @@ const AboutModal = ({ isOpen, onClose }: props) => {
bg={useColorModeValue("blue.50", "blue.800")}
href="https://github.com/sqrl-planner/sqrl-server"
>
<Icon as={FaGithub} /> sqrl-server <ExternalLinkIcon />
<Icon as={FaGithub} /> sqrl-server: {latestVersion.server} <ExternalLinkIcon />
</Link>

<Box opacity={0.6} fontSize="sm" mb={2}>{t("last-updated")} {lastUpdated.server.toLocaleDateString()}.</Box>
<Box opacity={0.8}>{t("sqrl-server-description")}</Box>

<Heading
Expand All @@ -191,8 +245,8 @@ const AboutModal = ({ isOpen, onClose }: props) => {
flexWrap="wrap"
justifyContent="stretch"
>
{contributors?.sqrlServer &&
contributors?.sqrlServer.map((contributor) => (
{contributors?.server &&
contributors?.server.map((contributor) => (
<Contributor
contributor={contributor}
key={contributor.id}
Expand All @@ -203,7 +257,7 @@ const AboutModal = ({ isOpen, onClose }: props) => {

<Divider />

<Flex flexDir="column" alignItems="start">
<Flex flexDir="column" alignItems="start" width="100%">
<Link
color={useColorModeValue("blue.800", "blue.300")}
isExternal
Expand All @@ -217,8 +271,9 @@ const AboutModal = ({ isOpen, onClose }: props) => {
bg={useColorModeValue("blue.50", "blue.800")}
href="https://github.com/sqrl-planner/gator"
>
<Icon as={FaGithub} /> gator <ExternalLinkIcon />
<Icon as={FaGithub} /> gator: {latestVersion.gator} <ExternalLinkIcon />
</Link>
<Box opacity={0.6} fontSize="sm" mb={2}>{t("last-updated")} {lastUpdated.gator.toLocaleDateString()}.</Box>
<Box opacity={0.8}>{t("gator-description")}</Box>
<Heading
mb={2}
Expand All @@ -240,10 +295,10 @@ const AboutModal = ({ isOpen, onClose }: props) => {
>
{contributors?.gator &&
contributors?.gator.map((contributor) => (
<Contributor
contributor={contributor}
key={contributor.id}
/>
<Contributor
contributor={contributor}
key={contributor.id}
/>
))}
</Grid>
</Flex>
Expand Down
6 changes: 4 additions & 2 deletions pages/api/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ export default async function handler(
if (!repositoryName) repositoryName = "sqrl-client"

const result = await fetch(
`https://api.github.com/repos/sqrl-planner/${repositoryName}/contributors`,
`https://api.github.com/repos/sqrl-planner/fart/${repositoryName}/contributors`,
{
method: "get",
headers: new Headers({
Authorization: `token ${process.env.GITHUB_API_KEY as string}`,
}),
}
)
// const result =
if(result.ok) return res.status(200).json(await result.json())

res.status(200).json(await result.json())
return res.status(500)
}
25 changes: 25 additions & 0 deletions pages/api/github/contributors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next"
import fetch from "cross-fetch"

export default async function handler(
req: NextApiRequest,
res: NextApiResponse<any>
) {
let { repositoryName } = req.query
if (!repositoryName) repositoryName = "sqrl-client"

const result = await fetch(
`https://api.github.com/repos/sqrl-planner/${repositoryName}/contributors`,
{
method: "get",
headers: new Headers({
Authorization: `token ${process.env.GITHUB_API_KEY as string}`,
}),
}
)

if(result.ok) return res.status(200).json(await result.json())

return res.status(500)
}
25 changes: 25 additions & 0 deletions pages/api/github/lastUpdated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next"
import fetch from "cross-fetch"

export default async function handler(
req: NextApiRequest,
res: NextApiResponse<any>
) {
let { repositoryName } = req.query
if (!repositoryName) repositoryName = "sqrl-client"

const result = await fetch(
`https://api.github.com/repos/sqrl-planner/${repositoryName}`,
{
method: "get",
headers: new Headers({
Authorization: `token ${process.env.GITHUB_API_KEY as string}`,
}),
}
)

if(result.ok) return res.status(200).json((await result.json()).pushed_at)

return res.status(500)
}
34 changes: 34 additions & 0 deletions pages/api/github/latestVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next"
import fetch from "cross-fetch"

export default async function handler(
req: NextApiRequest,
res: NextApiResponse<any>
) {
let { repositoryName } = req.query
if (!repositoryName) repositoryName = "sqrl-client"

const result = await fetch(
`https://api.github.com/repos/sqrl-planner/${repositoryName}/tags`,
{
method: "get",
headers: new Headers({
Authorization: `token ${process.env.GITHUB_API_KEY as string}`,
}),
}
)

let resultingName

try {
resultingName = (await result.json())[0].name
} catch(e) {
resultingName = "Not yet stable"
}

if(result.ok) return res.status(200).json(resultingName)

return res.status(500)
}

3 changes: 2 additions & 1 deletion public/locales/en/modal.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"checklist-two": "Sqrl is not affiliated with the University in any official capacity.",
"checklist-three": "Sqrl cannot enrol in courses for you.",
"timetable": "Timetable",
"calendar": "Calendar"
"calendar": "Calendar",
"last-updated": "Last updated"
}
3 changes: 2 additions & 1 deletion public/locales/fr/modal.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"checklist-two": "Sqrl is not affiliated with the University in any official capacity.",
"checklist-three": "Sqrl cannot enrol in courses for you.",
"timetable": "Timetable",
"calendar": "Calendar"
"calendar": "Calendar",
"last-updated": "Last updated"
}
3 changes: 2 additions & 1 deletion public/locales/zh/modal.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"checklist-two": "Sqrl is not affiliated with the University in any official capacity.",
"checklist-three": "Sqrl cannot enrol in courses for you.",
"timetable": "Timetable",
"calendar": "Calendar"
"calendar": "Calendar",
"last-updated": "Last updated"
}

0 comments on commit 03137fa

Please sign in to comment.