Skip to content

Commit

Permalink
Merge pull request #787 from hackclub/add-cursed-blessed-status
Browse files Browse the repository at this point in the history
Display the blessed/cursed status for users
  • Loading branch information
maxwofford authored Nov 15, 2024
2 parents 8f32656 + 632ea74 commit 6112bf4
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/app/harbor/battles/battles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import Image from 'next/image'
import ReactMarkdown, { Components } from 'react-markdown'

import { LoadingSpinner } from '../../../components/ui/loading_spinner.js'
import { getVotesRemainingForNextPendingShip } from '@/app/utils/airtable'
import {
getVotesRemainingForNextPendingShip,
safePerson,
} from '@/app/utils/airtable'
import useLocalStorageState from '../../../../lib/useLocalStorageState'
import { useToast } from '@/hooks/use-toast'
import { HsSession } from '@/app/utils/auth'

import SpeechToText from '@/components/speech-to-text'
import Blessed from './blessed'
import Cursed from './cursed'

interface Matchup {
project1: Ships
Expand Down Expand Up @@ -217,6 +222,8 @@ export default function Matchups({ session }: { session: HsSession }) {
const [readmeContent, setReadmeContent] = useState('')
const [isReadmeView, setIsReadmeView] = useState(false)
const [isSubmitting, setIsSubmitting] = useState(false)
const [cursed, setCursed] = useState(false)
const [blessed, setBlessed] = useState(false)

// const turnstileRef = useRef(null);
// const [turnstileToken, setTurnstileToken] = useState<string | null>(null);
Expand All @@ -228,6 +235,13 @@ export default function Matchups({ session }: { session: HsSession }) {

const { toast } = useToast()

useEffect(() => {
safePerson().then((sp) => {
setCursed(sp.cursed)
setBlessed(sp.blessed)
})
})

useEffect(() => {
setFewerThanTenWords(reason.trim().split(' ').length < 10)
}, [reason])
Expand Down Expand Up @@ -434,6 +448,9 @@ export default function Matchups({ session }: { session: HsSession }) {
to skip!)
</p>

{blessed && <Blessed />}
{cursed && <Cursed />}

{voteBalance > 0 && (
<div className="flex justify-center items-center space-x-4">
{voteBalance} more vote{voteBalance == 1 ? '' : 's'} until your
Expand Down
65 changes: 65 additions & 0 deletions src/app/harbor/battles/blessed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use client'

import { useState } from 'react'

import Pill from '@/components/ui/pill'
import {
Popover,
PopoverTrigger,
PopoverContent,
} from '@/components/ui/popover'
import Icon from '@hackclub/icons'

export default function Blessed() {
const [open, setOpen] = useState(false)

return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger
asChild
onMouseEnter={() => setOpen(true)}
onMouseLeave={() => setOpen(false)}
>
<div className="text-center mb-5">
<Pill msg="🏴‍☠️ You have the pirate's blessing" color="yellow" />
</div>
</PopoverTrigger>
<PopoverContent className="text-sm">
<div>
<p className="inline-flex text-base">What's a blessing?</p>
<ul className="flex flex-col gap-1 mt-2">
<li className="flex gap-1">
<Icon
glyph="thumbsup"
size={20}
className="inline flex-shrink-0"
/>{' '}
Be thoughtful with your voting.
</li>
<li className="flex gap-1">
<Icon
glyph="message-new"
size={20}
className="inline flex-shrink-0"
/>{' '}
Write good descriptions.
</li>
<li className="flex gap-1">
<Icon glyph="friend" size={20} className="inline flex-shrink-0" />{' '}
Keep voting regularly.
</li>
<li className="flex gap-1">
<img
sizes="20px"
src="doubloon.svg"
alt="doubloons"
className="w-4 sm:w-5 h-4 sm:h-5"
/>{' '}
While you keep your voting streak, you'll earn 20% more doubloons!
</li>
</ul>
</div>
</PopoverContent>
</Popover>
)
}
57 changes: 57 additions & 0 deletions src/app/harbor/battles/cursed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use client'

import { useState } from 'react'

import Pill from '@/components/ui/pill'
import {
Popover,
PopoverTrigger,
PopoverContent,
} from '@/components/ui/popover'
import Icon from '@hackclub/icons'

export default function Cursed() {
const [open, setOpen] = useState(false)

return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger
asChild
onMouseEnter={() => setOpen(true)}
onMouseLeave={() => setOpen(false)}
>
<div className="text-center mb-5">
<Pill msg="️☠️ You have the pirate's curse" color="red" />
</div>
</PopoverTrigger>
<PopoverContent className="text-sm">
<div>
<p className="inline-flex text-base">Your votes have been flagged</p>
<ul className="flex flex-col gap-1 mt-2">
<li className="flex gap-1">
<Icon
glyph="thumbsdown"
size={20}
className="inline flex-shrink-0"
/>{' '}
Be more thoughtful with your voting.
</li>
<li className="flex gap-1">
<Icon glyph="meh" size={20} className="inline flex-shrink-0" />{' '}
Write better descriptions for your choices.
</li>
<li className="flex gap-1">
<img
sizes="20px"
src="doubloon.svg"
alt="doubloons"
className="w-4 sm:w-5 h-4 sm:h-5"
/>{' '}
Until you lift the curse, your payouts are halved.
</li>
</ul>
</div>
</PopoverContent>
</Popover>
)
}
6 changes: 6 additions & 0 deletions src/app/utils/airtable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export interface SafePerson {
votesRemainingForNextPendingShip: number
emailSubmittedOnMobile: boolean
preexistingUser: boolean
cursed: boolean
blessed: boolean
}

// Good method
Expand All @@ -140,6 +142,8 @@ export async function safePerson(): Promise<SafePerson> {
)
const emailSubmittedOnMobile = !!record.fields.email_submitted_on_mobile
const preexistingUser = !!record.fields.preexisting_user
const cursed = record.fields.curse_blessing_status === 'cursed'
const blessed = record.fields.curse_blessing_status === 'blessed'

return {
id,
Expand All @@ -149,5 +153,7 @@ export async function safePerson(): Promise<SafePerson> {
votesRemainingForNextPendingShip,
emailSubmittedOnMobile,
preexistingUser,
cursed,
blessed,
}
}

0 comments on commit 6112bf4

Please sign in to comment.