Skip to content

Commit

Permalink
Add ugly hack for dashboard auto refresh (#42)
Browse files Browse the repository at this point in the history
* Update application form

* Add ugly hack for dashboard auto refresh

The MarkDownRenderer is a server component as it needs direct access
to the database for render context. A nice auto refresh would need to
be implemented client side as only part of the page needs to be re-rendered.

Switching MarkDownRenderer to be a client component is simply too much
work that I'm not willing to commit to so I've resorted back to this
ugly hack of server rendering a `<script>` tag that just refreshes
the entire page every minute.

Thank Sneh for all the work he did on this!
  • Loading branch information
JaneIRL authored Aug 26, 2023
1 parent 73fb8ff commit f28022f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
17 changes: 1 addition & 16 deletions src/app/ApplicationForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import Link from 'next/link'
import { useEffect, useState } from 'react'
import { useState } from 'react'

import { Box } from '@/components/Box'
import { Button } from '@/components/Button'
Expand Down Expand Up @@ -88,16 +88,6 @@ export function ApplicationForm() {
}
}

useEffect(() => {
window.addEventListener(
'beforeunload',
(e) => {
e.preventDefault()
},
{ capture: true },
)
}, [])

return (
<Box
id="applicationForm"
Expand Down Expand Up @@ -256,11 +246,6 @@ export function ApplicationForm() {
/>

<Heading level={3}>MLH Checkboxes</Heading>
<p>
We are currently in the process of partnering with MLH. The following 3
checkboxes are for this partnership. If we do not end up partnering with
MLH, your information will not be shared.
</p>
<Dropdown
id="agreedMlhCoC"
text={
Expand Down
11 changes: 8 additions & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Image from 'next/image'

import { Box } from '@/components/Box'
import { LinkButton } from '@/components/Button'
import { Header } from '@/components/Header'
import { Heading } from '@/components/Heading'
import { Organizer, OrganizerProps } from '@/components/Organizer'
import clientPromise from '@/lib/db'
Expand Down Expand Up @@ -151,7 +150,7 @@ async function Dashboard({ user }: { user: JsonUser }) {

// Generate check-in PIN
if (user.checkInPin === undefined) {
const pin = randomInt(100_000, 999_999)
const pin = randomInt(1000, 9999)
await client
.db()
.collection<User>('users')
Expand Down Expand Up @@ -185,7 +184,8 @@ async function Dashboard({ user }: { user: JsonUser }) {
children = [
<p key="kid">
We&apos;ve received your application. Check back later to see if you get
accepted, and feel free to contact the organizers if you need any
accepted, and feel free to contact the organizers at{' '}
<a href="mailto:[email protected]">[email protected]</a> if you need any
assistance!
</p>,
]
Expand All @@ -209,6 +209,11 @@ async function Dashboard({ user }: { user: JsonUser }) {
>
{...children}
</Box>
<div
dangerouslySetInnerHTML={{
__html: `<!-- hey you found my ugly hack! --><script>setInterval(() => window.location.reload(), 60_000)</script>`,
}}
></div>
</Box>
)
}

0 comments on commit f28022f

Please sign in to comment.