Skip to content

Commit

Permalink
Merge branch 'main' into malted/img
Browse files Browse the repository at this point in the history
  • Loading branch information
malted authored Dec 22, 2024
2 parents 21f79de + 9ea765c commit 5d64935
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 17 deletions.
19 changes: 12 additions & 7 deletions lib/battles/airtable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,21 @@ export const submitVote = async (
throw new Error('User not found')
}

const [winner, loser] = await Promise.all([
base('ships').find(voteData.winner),
base('ships').find(voteData.loser),
])

const K = 30
const expectedScoreWinner =
1 / (1 + Math.pow(10, (voteData.loserRating - voteData.winnerRating) / 400))
1 / (1 + Math.pow(10, (loser.fields.rating - winner.fields.rating) / 400))
const expectedScoreLoser = 1 - expectedScoreWinner

const newWinnerRating = Math.round(
voteData.winnerRating + K * (1 - expectedScoreWinner),
winner.fields.rating + K * (1 - expectedScoreWinner),
)
const newLoserRating = Math.round(
voteData.loserRating + K * (0 - expectedScoreLoser),
loser.fields.rating + K * (0 - expectedScoreLoser),
)

const record = await base('battles').create({
Expand All @@ -126,10 +131,10 @@ export const submitVote = async (
ships: [voteData.winner, voteData.loser],
winner: [voteData.winner],
loser: [voteData.loser],
winner_rating: voteData.winnerRating,
winner_adjustment: newWinnerRating - voteData.winnerRating,
loser_rating: voteData.loserRating,
loser_adjustment: newLoserRating - voteData.loserRating,
winner_rating: winner.fields.rating,
winner_adjustment: newWinnerRating - winner.fields.rating,
loser_rating: loser.fields.rating,
loser_adjustment: newLoserRating - loser.fields.rating,
is_tutorial_vote: !person.user_has_graduated,
generated_at: voteData.ts,
winner_readme_opened: voteData.winner_readme_opened,
Expand Down
Binary file added public/sticky-holidays/d1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added public/sticky-holidays/d2b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/app/api/battles/matchups/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function GET(request: NextRequest) {
readme_url: matchup.project1.readme_url,
repo_url: matchup.project1.repo_url,
deploy_url: matchup.project1.deploy_url,
// rating: matchup.project1.rating,
rating: matchup.project1.rating,
ship_type: matchup.project1.ship_type,
update_description: matchup.project1.update_description,
entrant__slack_id: matchup.project1.entrant__slack_id[0],
Expand All @@ -59,7 +59,7 @@ export async function GET(request: NextRequest) {
readme_url: matchup.project2.readme_url,
repo_url: matchup.project2.repo_url,
deploy_url: matchup.project2.deploy_url,
// rating: matchup.project2.rating,
rating: matchup.project2.rating,
ship_type: matchup.project2.ship_type,
update_description: matchup.project2.update_description,
entrant__slack_id: matchup.project2.entrant__slack_id[0],
Expand Down
31 changes: 30 additions & 1 deletion src/app/harbor/battles/battles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Ship } from '@/app/utils/data'
import Modal from '@/components/ui/modal'
import { sendFraudReport } from './fraud-utils'
import { Button } from '@/components/ui/button'

import { Howl } from 'howler'
interface Matchup {
project1: Ships
project2: Ships
Expand Down Expand Up @@ -102,7 +102,32 @@ export default function Matchups({ session }: { session: HsSession }) {
console.log(project)
}

const shuffleNoise = new Howl({
src: 'https://cloud-dq0583nuu-hack-club-bot.vercel.app/0roll_audio.mp4',
})
const shuffledNoises = [
'https://cloud-6ibeo2nhb-hack-club-bot.vercel.app/0orchestra_hit_audio.mp4',
'https://cloud-nunjao1ax-hack-club-bot.vercel.app/0cash_register_audio.mp4',
'https://cloud-1qghl8m1m-hack-club-bot.vercel.app/0chimes_audio.mp4',
'https://cloud-qzzqwgtk5-hack-club-bot.vercel.app/0musica_default_audio.mp4',
'https://cloud-a42iebcfd-hack-club-bot.vercel.app/0musica_exclamation_audio.mp4',
'https://cloud-o6nhwcf3y-hack-club-bot.vercel.app/0musica_open_audio.mp4',
'https://cloud-1t05cbn0l-hack-club-bot.vercel.app/0robotz_error_audio.mp4',
'https://cloud-7pcpircvf-hack-club-bot.vercel.app/0tada_audio.mp4',
'https://cloud-b578wplwe-hack-club-bot.vercel.app/0boing.mp3',
'https://cloud-qft2iibp4-hack-club-bot.vercel.app/0indigo.mp3',
'https://cloud-4kk5a8dir-hack-club-bot.vercel.app/0quack.mp3',
'https://cloud-d2457l6yk-hack-club-bot.vercel.app/0funk.mp3',
'https://cloud-k7djoy844-hack-club-bot.vercel.app/0basso.mp3',
'https://cloud-kdii29uqp-hack-club-bot.vercel.app/0se_bell_audio.mp4',
'https://cloud-2531xbnu4-hack-club-bot.vercel.app/0yr_stoy_03_how_2d_audio.mp4',
'https://cloud-1v9k8a4x7-hack-club-bot.vercel.app/0yr_sweep_up_01_audio.mp4',
].map((path) => new Howl({ src: path }))

let shuffling = false
function shuffle() {
shuffling = true
shuffleNoise.play()
fetchMatchup()

document.body.style.willChange = 'transform'
Expand Down Expand Up @@ -232,6 +257,10 @@ export default function Matchups({ session }: { session: HsSession }) {
} catch (error) {
console.error('Error fetching matchup:', error)
} finally {
if (shuffling) {
shuffleNoise.stop()
shuffledNoises[Math.floor(Math.random() * shuffledNoises.length)].play()
}
setLoading(false)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/harbor/battles/project-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ export default function ProjectCard({
)}
<a
target="_blank"
href={`https://slack.com/app_redirect?channel=${project.entrant__slack_id}`}
href={`https://hackclub.slack.com/app_redirect?channel=${project.entrant__slack_id}`}
rel="noreferrer"
>
<Pill glyph="slack" color="purple" msg="Chat on Slack" />
</a>
Expand Down
1 change: 1 addition & 0 deletions src/app/harbor/shipyard/new-ship-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default function NewShipForm({
{ label: 'Riceathon', value: 'riceathon' },
{ label: 'Counterspell', value: 'counterspell' },
{ label: 'Anchor', value: 'anchor' },
{ label: 'Dessert', value: 'dessert' },
]

// Initialize confetti on mount
Expand Down
15 changes: 12 additions & 3 deletions src/app/harbor/signpost/best-ships.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@ export default function BestShips() {
}
/>
<div className="flex gap-3">
<a target="_blank" href={partialShip.repoUrl}>
<a
target="_blank"
href={partialShip.repoUrl}
rel="noreferrer"
>
<Pill
classes="bg-white/15 text-white"
glyph="github"
msg="Repository"
color="gray"
/>
</a>
<a target="_blank" href={partialShip.deployUrl}>
<a
target="_blank"
href={partialShip.deployUrl}
rel="noreferrer"
>
<Pill
classes="bg-white/15 text-white"
glyph="view-forward"
Expand All @@ -56,7 +64,8 @@ export default function BestShips() {
{partialShip.entrantSlackId ? (
<a
target="_blank"
href={`https://slack.com/app_redirect?channel=${partialShip.entrantSlackId}`}
href={`https://hackclub.slack.com/app_redirect?channel=${partialShip.entrantSlackId}`}
rel="noreferrer"
>
<Pill
glyph="slack"
Expand Down
16 changes: 14 additions & 2 deletions src/app/harbor/signpost/signpost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,28 @@ export default function Signpost() {
</p>
</a>

<div className="flex items-center justify-center gap-4 overflow-x-scroll">
<div className="flex items-center justify-center gap-4 overflow-x-auto">
<div className="w-fit h-fit">
<JaggedCard
shadow={false}
className="w-96 pb-16 h-full flex flex-col gap-2 justify-between items-center"
>
<p className="text-lg">Day 1</p>
<p>Unlocked!</p>
<div className="h-40 mx-auto rounded">
<img src="/sticky-holidays/d1.png" alt="" className="w-64" />
</div>
</JaggedCard>
</div>
<div className="w-fit h-fit">
<JaggedCard
shadow={false}
className="w-96 pb-16 h-full flex flex-col gap-2 justify-between items-center"
>
<p className="text-lg">Day 2</p>
<p>Unlocks in {unlockString}</p>
<div className="h-40 mx-auto rounded">
<img src="/sticky-holidays/day1.png" alt="" className="w-64" />
<img src="/sticky-holidays/d2b.png" alt="" className="w-40" />
</div>
</JaggedCard>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/app/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type YswsType =
| 'riceathon'
| 'counterspell'
| 'anchor'
| 'dessert'

export interface Ship extends EditableShipFields {
id: string // The Airtable row's ID.
Expand Down
14 changes: 13 additions & 1 deletion src/components/ui/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type React from 'react'
import React, { useEffect } from 'react'
import { AnimatePresence, motion } from 'framer-motion'
import Icon from '@hackclub/icons'
import JaggedCard from '../jagged-card'
Expand All @@ -17,6 +17,18 @@ export default function Modal({
children: React.ReactNode
props?: any
}) {
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && !hideCloseButton) {
close(event)
}
}
document.addEventListener('keydown', handleKeyDown)
return () => {
document.removeEventListener('keydown', handleKeyDown)
}
}, [hideCloseButton, close])

return (
<AnimatePresence>
{isOpen ? (
Expand Down

0 comments on commit 5d64935

Please sign in to comment.