Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/superfly/flyctl-ac…
Browse files Browse the repository at this point in the history
…tions-1.4
  • Loading branch information
PatrickHeneise authored Sep 6, 2023
2 parents a8dfb11 + 8d1df8c commit ba37c43
Show file tree
Hide file tree
Showing 13 changed files with 3,550 additions and 3,596 deletions.
30 changes: 30 additions & 0 deletions app/features/components/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import { ErrorBoundary } from 'react-error-boundary'

type FallbackRenderProps = {
error: Error
resetErrorBoundary: () => void
}

const FallbackRender = ({ error }: FallbackRenderProps) => {
// eslint-disable-next-line no-console
console.error('Error description: ', error.message)

return (
<div role="alert">
<p className="text-center text-red-500">
We encountered an internal error. Please try again.
</p>
</div>
)
}

type CatchErrorBoundaryProps = {
children: React.ReactNode
}

export const CatchErrorBoundary = ({ children }: CatchErrorBoundaryProps) => {
return (
<ErrorBoundary fallbackRender={FallbackRender}>{children}</ErrorBoundary>
)
}
1 change: 1 addition & 0 deletions app/features/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './Breadcrumbs'
export * from './Page'
export * from './Show'
export * from './Spinner'
export * from './ErrorBoundary'
19 changes: 11 additions & 8 deletions app/features/providers/github/commands/getPastEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import {
} from '~/features/providers/misc/http'
import { mapIssuesToEvents } from './misc/mapIssueToEvent'
import type { Event } from './types'
import { fetchCached } from './misc/cache'

export const getPastEvents = async (
nextToken?: String
): Promise<ApiResponse<Event[]>> => {
try {
const client = newGraphQLClientFactory()

const res = await client<GetPastEventsQuery>(getPastEventsQuery, {
owner: 'cyprus-developer-community',
repo: 'events',
size: 20,
after: nextToken
})

const events = await mapIssuesToEvents(res.repository.issues.nodes)
const cacheKey = 'pastEvents'
const events = await fetchCached(cacheKey, async () => {
const res = await client<GetPastEventsQuery>(getPastEventsQuery, {
owner: 'cyprus-developer-community',
repo: 'events',
size: 20,
after: nextToken
})

return mapIssuesToEvents(res.repository.issues.nodes)
})
return newSuccessfulResponse(events)
} catch (e) {
return newErrorResponse(e)
Expand Down
18 changes: 11 additions & 7 deletions app/features/providers/github/commands/getUpcomingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ import {
} from '~/features/providers/misc/http'
import type { Event } from './types'
import { mapIssuesToEvents } from './misc/mapIssueToEvent'
import { fetchCached } from './misc/cache'

export const getUpcomingEvents = async (
nextToken?: String
): Promise<ApiResponse<Event[]>> => {
try {
const client = newGraphQLClientFactory()

const res = await client<GetUpcomingEventsQuery>(getUpcomingEventsQuery, {
owner: 'cyprus-developer-community',
repo: 'events',
size: 20,
after: nextToken
})
const cacheKey = 'upcomingEvents'
const events = await fetchCached(cacheKey, async () => {
const res = await client<GetUpcomingEventsQuery>(getUpcomingEventsQuery, {
owner: 'cyprus-developer-community',
repo: 'events',
size: 20,
after: nextToken
})

const events = await mapIssuesToEvents(res.repository.issues.nodes)
return mapIssuesToEvents(res.repository.issues.nodes)
})
return newSuccessfulResponse(events)
} catch (e) {
return newErrorResponse(e)
Expand Down
49 changes: 49 additions & 0 deletions app/features/providers/github/commands/misc/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import NodeCache from 'node-cache'

let cache: NodeCache
let expired = {}

declare global {
var __cache: NodeCache | undefined
var __expired: { [key: string]: boolean }
}

if (process.env.NODE_ENV === 'production') {
cache = new NodeCache({ deleteOnExpire: false })
} else {
if (!global.__cache) {
global.__cache = new NodeCache({ deleteOnExpire: false })
}
cache = global.__cache
if (!global.__expired) {
global.__expired = {}
}
expired = global.__expired
}

cache.on('expired', (key) => {
expired[key] = true
})

const fetchCached = async <T>(
cacheKey: string,
fetcher: () => Promise<T>,
ttl = 60 * 20
) => {
let response: T
if (cache.has(cacheKey)) {
response = cache.get(cacheKey)
if (expired[cacheKey]) {
;(async () => {
expired[cacheKey] = false
cache.set(cacheKey, await fetcher(), ttl)
})()
}
return response
}
response = await fetcher()
cache.set(cacheKey, response, ttl)
return response
}

export { cache, fetchCached }
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const getIssueStatus = (isUpcoming: boolean, issue: Issue): EventStatus => {
export const mapIssueToEvent = async (issue: Issue): Promise<Maybe<Event>> => {
try {
const { default: issueBodyParser } = await import(
'@zentered/issue-forms-body-parser/src/parse.js'
'@zentered/issue-forms-body-parser'
)

const parsedBody = await issueBodyParser(issue.body)
Expand Down
19 changes: 0 additions & 19 deletions app/pages/Events/components/PastEvents/index.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions app/pages/Events/components/UpcomingEvents/index.tsx

This file was deleted.

48 changes: 36 additions & 12 deletions app/pages/Events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import {
BreadcrumbLink,
H1,
Page,
Spinner
Spinner,
Section,
H2,
CatchErrorBoundary
} from '~/features/components'
import { PastEvents } from './components/PastEvents'
import { UpcomingEvents } from './components/UpcomingEvents'
import { Suspense } from 'react'
import { EventList } from './components/EventList'

const Events = () => {
const { pastEventsPromise, upcomingEventsPromise } =
const { upcomingEventsPromise, pastEventsPromise } =
useLoaderData() as LoaderData

return (
Expand All @@ -28,14 +30,36 @@ const Events = () => {
</Breadcrumbs>
<H1>Events</H1>
<div className="grid gap-12 lg:gap-24">
<Suspense fallback={<Spinner className="m-auto" />}>
<Await resolve={upcomingEventsPromise}>
<UpcomingEvents />
</Await>
<Await resolve={pastEventsPromise}>
<PastEvents />
</Await>
</Suspense>
<Section data-test-e2e="upcoming-events-section">
<H2>Upcoming events</H2>
<Suspense fallback={<Spinner className="mx-auto" />}>
<CatchErrorBoundary>
<Await resolve={upcomingEventsPromise}>
{(res) => {
if (res.success === false) {
throw new Error(res.message)
}
return <EventList events={res.data} />
}}
</Await>
</CatchErrorBoundary>
</Suspense>
</Section>
<Section data-test-e2e="past-events-section">
<H2>Past events</H2>
<Suspense fallback={<Spinner className="mx-auto" />}>
<CatchErrorBoundary>
<Await resolve={pastEventsPromise}>
{(res) => {
if (res.success === false) {
throw new Error(res.message)
}
return <EventList events={res.data} />
}}
</Await>
</CatchErrorBoundary>
</Suspense>
</Section>
</div>
</Page>
)
Expand Down
7 changes: 5 additions & 2 deletions app/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { LoaderArgs, LoaderFunction } from '@remix-run/node'
import type {
LoaderArgs,
LoaderFunction,
TypedDeferredData
} from '@remix-run/node'

import type { TypedDeferredData } from '@remix-run/node'
export type {
Event,
User,
Expand Down
89 changes: 47 additions & 42 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,61 +49,63 @@
"/public/build"
],
"dependencies": {
"@headlessui/react": "^1.7.12",
"@heroicons/react": "^2.0.16",
"@octokit/auth-app": "^4.0.9",
"@octokit/graphql": "^5.0.5",
"@remix-run/node": "^1.13.0",
"@remix-run/react": "^1.13.0",
"@remix-run/serve": "^1.13.0",
"@remix-run/server-runtime": "^1.13.0",
"@types/marked": "^4.0.8",
"@zentered/issue-forms-body-parser": "^2.1.1",
"date-fns": "^2.29.3",
"@headlessui/react": "^1.7.17",
"@heroicons/react": "^2.0.18",
"@octokit/auth-app": "^6.0.0",
"@octokit/graphql": "^7.0.1",
"@remix-run/node": "^1.19.3",
"@remix-run/react": "^1.19.3",
"@remix-run/serve": "^1.19.3",
"@remix-run/server-runtime": "^1.19.3",
"@types/marked": "^5.0.1",
"@zentered/issue-forms-body-parser": "^2.1.4",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.0",
"graphql": "^16.6.0",
"marked": "^4.2.12",
"graphql": "^16.8.0",
"marked": "^8.0.0",
"node-cache": "^5.1.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.11",
"react-schemaorg": "^2.0.0",
"remix-image": "^1.4.0",
"schema-dts": "^1.1.2"
},
"devDependencies": {
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.4",
"@graphql-codegen/cli": "3.2.2",
"@graphql-codegen/typed-document-node": "^3.0.1",
"@graphql-codegen/typescript": "^3.0.1",
"@graphql-codegen/typescript-operations": "^3.0.1",
"@playwright/test": "^1.31.1",
"@remix-run/dev": "^1.13.0",
"@remix-run/eslint-config": "^1.13.0",
"@testing-library/jest-dom": "^5.16.5",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@graphql-codegen/cli": "5.0.0",
"@graphql-codegen/typed-document-node": "^5.0.1",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-operations": "^4.0.1",
"@playwright/test": "^1.37.1",
"@remix-run/dev": "^1.19.3",
"@remix-run/eslint-config": "^1.19.3",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"@types/node": "^18.14.2",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/testing-library__jest-dom": "^5.14.5",
"@unocss/cli": "^0.50.1",
"@unocss/reset": "^0.50.1",
"@vitejs/plugin-react": "^3.1.0",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"@types/node": "^20.5.9",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@types/testing-library__jest-dom": "^5.14.9",
"@unocss/cli": "^0.55.7",
"@unocss/reset": "^0.55.7",
"@vitejs/plugin-react": "^4.0.4",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-markdown": "^3.0.1",
"husky": "8.0.3",
"is-ci": "^3.0.1",
"jsdom": "^21.1.0",
"lint-staged": "^13.1.2",
"msw": "^1.2.1",
"jsdom": "^22.1.0",
"lint-staged": "^14.0.1",
"msw": "^1.3.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"typescript": "^4.9.5",
"unocss": "^0.50.1",
"vite": "^4.1.4",
"vite-tsconfig-paths": "^4.0.5",
"vitest": "^0.29.1"
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"unocss": "^0.55.7",
"vite": "^4.4.9",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.34.3"
},
"engines": {
"node": ">=18"
Expand All @@ -112,5 +114,8 @@
"branches": [
"main"
]
},
"volta": {
"node": "18.17.1"
}
}
Loading

0 comments on commit ba37c43

Please sign in to comment.