Skip to content

Commit

Permalink
created getTimeFromParts and consolidated to one new page
Browse files Browse the repository at this point in the history
  • Loading branch information
varCepheid committed Nov 24, 2023
1 parent a14535d commit ac2de16
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 103 deletions.
4 changes: 0 additions & 4 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ const routes = [
path: '/events/:eventKey/matches/:matchKey/scout',
component: () => import('./routes/scout'),
},
{
path: '/events/:eventKey/match-creator',
component: () => import('./routes/match-creator'),
},
{
path: '/events/:eventKey/match-editor',
component: () => import('./routes/match-editor'),
Expand Down
88 changes: 0 additions & 88 deletions src/routes/match-creator.tsx

This file was deleted.

15 changes: 9 additions & 6 deletions src/routes/match-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Form } from '@/components/form'
import Page from '@/components/page'
import TextInput from '@/components/text-input'
import { route } from '@/router'
import { getTimeFromParts } from '@/utils/use-time-from-parts'
import { getTimeFromParts } from '@/utils/get-time-from-parts'
import { css } from 'linaria'
import { useState } from 'preact/hooks'

Expand Down Expand Up @@ -36,7 +36,7 @@ const EditorForm = ({ eventKey }: { eventKey: string }) => {
createEventMatch(eventKey, {
redAlliance: teamList.slice(0, 3),
blueAlliance: teamList.slice(3, 6),
time: getTimeFromParts(day, time, eventKey),
time: getTimeFromParts(day, time),
key: `qm${matchNumber}`,
})
.then(() => route(`/events/${eventKey}`))
Expand Down Expand Up @@ -67,16 +67,19 @@ const EditorForm = ({ eventKey }: { eventKey: string }) => {
}}
/>
<Button disabled={isLoading || !isValid}>
{isLoading ? 'Creating Match' : 'Create Match'}
{isLoading ? 'Saving Match Information' : 'Save Match'}
</Button>
</>
)}
</Form>
)
}

const MatchCreator = ({ eventKey }: { eventKey: string }) => (
<Page name="Create Match" back={`/events/${eventKey}`}>
const MatchEditor = ({ eventKey }: { eventKey: string }) => (
<Page
name={need ? 'Create Match' : 'Edit Match'}
back={`/events/${eventKey}`}
>
<Card class={cardStyle}>
<ErrorBoundary>
<EditorForm eventKey={eventKey} />
Expand All @@ -85,4 +88,4 @@ const MatchCreator = ({ eventKey }: { eventKey: string }) => (
</Page>
)

export default MatchCreator
export default MatchEditor
11 changes: 11 additions & 0 deletions src/utils/get-time-from-parts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const getTimeFromParts = (date: string, time: string) => {
const now = new Date(Date.now())
if (date.length !== 5 || time.length !== 5) return now.toISOString()

const month = Number.parseInt(date.slice(0, 2))
const day = Number.parseInt(date.slice(3, 5))
const hour = Number.parseInt(time.slice(0, 2))
const minute = Number.parseInt(time.slice(3, 5))
const inputDate = new Date(now.getFullYear(), month, day, hour, minute)
return inputDate.toISOString()
}
5 changes: 0 additions & 5 deletions src/utils/use-time-from-parts.ts

This file was deleted.

0 comments on commit ac2de16

Please sign in to comment.