Skip to content

Commit c2cf0f3

Browse files
committed
complete pr
1 parent 2c9eca3 commit c2cf0f3

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@
117117
],
118118
"sourceLocale": "en"
119119
}
120-
}
120+
}

pages/index.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Trans } from '@lingui/macro'
1111
import FrontPage from '../src/components/templates/FrontPage'
1212
import fetcher from '../utils/fetcher'
1313
import toCamelCase from '../utils/camelCase'
14+
import { PrivacyTipTwoTone } from '@mui/icons-material'
1415

1516
interface Props {
1617
events: ServerData[]
@@ -53,33 +54,36 @@ export default function Index(props: Props): JSX.Element {
5354
}
5455

5556
export async function getStaticProps() {
56-
const date = new Date().toISOString()
57-
58-
const [event, eventErr] = await fetcher(
59-
'events',
60-
`&filter=[{"and":[{"name":"state","op":"eq","val":"published"},{"name":"privacy","op":"eq","val":"public"},{"name":"is-featured","op":"eq","val":true}]},{"or":[{"name":"ends-at","op":"ge","val":"${date}"}]}]
61-
&page[size]=6
57+
const [event, eventErr] = await fetcher({
58+
url: `events?filter=[{"and":[{"name":"state","op":"eq","val":"published"},{"name":"privacy","op":"eq","val":"public"},{"name":"is-featured","op":"eq","val":true}]},{"or":[{"name":"ends-at","op":"ge","val":"${new Date()}"}]}]
59+
&page[size]=6
6260
&public=true
63-
&sort=starts-at`
64-
)
61+
&sort=ends-at`,
62+
})
6563
if (eventErr) {
6664
console.error(eventErr)
6765
}
6866
const events = toCamelCase(event?.data)
6967

70-
const [upcomingEvent, upcomingEventErr] = await fetcher(
71-
'events/upcoming',
72-
'page[size]=3&public=true&upcoming=true'
73-
)
68+
const [upcomingEvent, upcomingEventErr] = await fetcher({
69+
url: 'events/upcoming?page[size]=3&public=true&upcoming=true',
70+
})
7471
if (upcomingEventErr) {
7572
console.error(upcomingEventErr)
7673
}
7774
const upcomingEvents = toCamelCase(upcomingEvent?.data)
7875

79-
const [group, groupErr] = await fetcher(
80-
'groups',
81-
'filter=[{"name":"is-promoted","op":"eq","val":true}]&include=user,follower&page[size]=3&public=true'
82-
)
76+
const grpFilter = JSON.stringify([
77+
{
78+
name: 'is-promoted',
79+
op: 'eq',
80+
val: 'true',
81+
},
82+
])
83+
84+
const [group, groupErr] = await fetcher({
85+
url: `groups?filter=${grpFilter}&include=user,follower&page[size]=3&public=true`,
86+
})
8387
if (groupErr) {
8488
console.error(groupErr)
8589
}

utils/fetcher.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { instance } from '../src/ky/instance'
22

3-
export default async function fetcher(
4-
url: string,
5-
searchParams: string
6-
): Promise<[data: ServerProp | null, err: any]> {
3+
interface Props {
4+
url: string
5+
method?: string
6+
}
7+
8+
export default async function fetcher({
9+
url,
10+
method = 'GET',
11+
}: Props): Promise<[data: ServerProp | null, err: any]> {
712
try {
813
const data: ServerProp = await instance(url, {
9-
searchParams: searchParams,
14+
method: method,
1015
}).json()
1116

1217
return [data, null]

0 commit comments

Comments
 (0)