Skip to content

Commit

Permalink
WIP Export helpers and duplicated code from both projects #243
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jan 29, 2022
1 parent b758e76 commit 5ab172e
Show file tree
Hide file tree
Showing 36 changed files with 106 additions and 49 deletions.
2 changes: 1 addition & 1 deletion global-scoreboard/src/Components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { StatusCodes } from 'http-status-codes'
import { useEffect, useState } from 'react'
import { Route, Routes } from 'react-router-dom'

import { apiGet } from '../../../shared/api'
import Dashboard from './Dashboard/Dashboard'
import GameSearch from './GameSearch/GameSearch'
import ScoreboardNavBar from './NavBar/ScoreboardNavBar'
import { apiGet } from 'src/fetchers/api'
import type { ServerConfigs } from 'src/Models/Configs'
import Configs from 'src/Models/Configs'
import type Player from 'src/Models/Player'
Expand Down
4 changes: 2 additions & 2 deletions global-scoreboard/src/Components/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { useEffect, useRef, useState } from 'react'
import { Container } from 'react-bootstrap'
import type { Variant } from 'react-bootstrap/esm/types'

import { apiDelete, apiGet, apiPost, apiPut } from '../../../../shared/api'
import math from '../../../../shared/utils/math'
import type { ScoreboardRef } from './Scoreboard'
import { DesktopScoreTableLayout, MobileScoreTableLayout } from './TableElements/ScoreTableLayout'
import UpdateMessage, { renderScoreTable } from './UpdateMessage'
import { apiDelete, apiGet, apiPost, apiPut } from 'src/fetchers/api'
import Configs from 'src/Models/Configs'
import type Player from 'src/Models/Player'
import type UpdateRunnerResult from 'src/Models/UpdateRunnerResult'
import math from 'src/utils/math'

type DashboardProps = {
currentUser: Player | null | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { faArrowAltCircleRight } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { Button, Table } from 'react-bootstrap'

import { diffDays } from '../../../../../shared/utils/time'
import PlayerNameCell from 'src/Components/Dashboard/TableElements/PlayerNameCell'
import PlayerScoreCell from 'src/Components/Dashboard/TableElements/PlayerScoreCell'
import ScoreTitle from 'src/Components/Dashboard/TableElements/ScoreTitle'
import Configs from 'src/Models/Configs'
import type Player from 'src/Models/Player'
import { diffDays } from 'src/utils/time'

const currentTimeOnLoad = new Date()
const columnClass = (lastUpdate: Date) => {
Expand Down
2 changes: 1 addition & 1 deletion global-scoreboard/src/Components/Dashboard/Scoreboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import sortCaret from './TableElements/SortCarret'
import Configs from 'src/Models/Configs'
import type { PlayerField } from 'src/Models/Player'
import type Player from 'src/Models/Player'
import { diffDays } from 'src/utils/time'
import { diffDays } from '../../../../shared/utils/time'

type FormatExtraDataProps = {
currentUser: Player | null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import './PlayerScoreCell.css'
import { useState } from 'react'
import { Button } from 'react-bootstrap'

import { apiGet } from '../../../../../shared/api'
import { renderScoreTable } from 'src/Components/Dashboard/UpdateMessage'
import GenericModal from 'src/Components/GenericModal'
import { apiGet } from 'src/fetchers/api'
import type Player from 'src/Models/Player'
import type { RunResult } from 'src/Models/UpdateRunnerResult'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Alert, OverlayTrigger, ProgressBar, Tab, Tabs, Tooltip } from 'react-bo
import type { Variant } from 'react-bootstrap/esm/types'

import type { RunResult } from 'src/Models/UpdateRunnerResult'
import math from 'src/utils/math'
import math from '../../../../shared/utils/math'

type UpdateMessageProps = {
variant: Variant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { Dispatch, SetStateAction } from 'react'
import { Form } from 'react-bootstrap'
import type { SearchBarProps } from 'react-bootstrap-table2-toolkit'

import { apiGet, MAX_PAGINATION } from 'src/fetchers/api'
import { apiGet, MAX_PAGINATION } from '../../../../shared/api'
import math from '../../../../shared/utils/math'
import type { DataArray, SpeedruncomGame } from 'src/Models/SpeedruncomResponse'
import math from 'src/utils/math'

type IdToNameMap = Record<string, string>

Expand Down
6 changes: 3 additions & 3 deletions global-scoreboard/src/Components/GameSearch/GameSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import defaultPaginationOptions from 'src/Components/Dashboard/TableElements/Pag
import sortCaret from 'src/Components/Dashboard/TableElements/SortCarret'
import type { GameValueRow, IdToNameMap, PlatformSelectOption } from 'src/Models/GameSearch'
import { getAllGameValues, getAllPlatforms } from 'src/Models/GameSearch'
import { getLocalStorageItem } from 'src/utils/localStorage'
import math from 'src/utils/math'
import { secondsToTimeString, timeStringToSeconds } from 'src/utils/time'
import { getLocalStorageItem } from '../../../../shared/utils/localStorage'
import math from '../../../../shared/utils/math'
import { secondsToTimeString, timeStringToSeconds } from '../../../../shared/utils/time'

type FormatExtraDataProps = {
platforms: IdToNameMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { ChangeEventHandler, FormEvent } from 'react'
import { useState } from 'react'
import { Button, Form, InputGroup } from 'react-bootstrap'

import { apiGet } from 'src/fetchers/api'
import { apiGet } from '../../../../shared/api'
import math from '../../../../shared/utils/math'
import { secondsToTimeString } from '../../../../shared/utils/time'
import type { DataArray, SpeedruncomLeaderboard, SpeedruncomRun, SpeedruncomVariable } from 'src/Models/SpeedruncomResponse'
import math from 'src/utils/math'
import { secondsToTimeString } from 'src/utils/time'

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const TIME_BONUS_DIVISOR = math.SECONDS_IN_HOUR * 12 // 12h (1/2 day) for +100%
Expand Down
2 changes: 1 addition & 1 deletion global-scoreboard/src/Components/NavBar/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { ChangeEventHandler, FormEvent } from 'react'
import { useState } from 'react'
import { Button, Col, Form, InputGroup } from 'react-bootstrap'

import { apiPost } from '../../../../shared/api'
import SpeedruncomApiKeyLink from './SpeedruncomApiKeyLink'
import GenericModal from 'src/Components/GenericModal'
import { apiPost } from 'src/fetchers/api'
import type Player from 'src/Models/Player'
import type UpdateRunnerResult from 'src/Models/UpdateRunnerResult'

Expand Down
6 changes: 4 additions & 2 deletions global-scoreboard/src/Models/GameSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiGet, MAX_PAGINATION } from 'src/fetchers/api'
import { apiGet, MAX_PAGINATION } from '../../../shared/api'
import type { EmbeddedSpeedruncomRun } from 'src/Models/SpeedruncomResponse'

export type PlatformDto = {
Expand Down Expand Up @@ -59,5 +59,7 @@ export const fetchValueNamesForRun = async (runId: string) => {
{ [response.data.game.data.id]: response.data.game.data.names.international },
{ [response.data.category.data.id]: response.data.category.data.name },
])
.catch(() => requestsStartedForRun.delete(runId))
.catch(() => {
requestsStartedForRun.delete(runId)
})
}
7 changes: 6 additions & 1 deletion global-scoreboard/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
},
"include": [
"src"
]
],
"paths": {
"shared": [
"../shared"
],
},
}
File renamed without changes.
6 changes: 6 additions & 0 deletions shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as api from './api'
import * as localStorage from './utils/localStorage'
import * as math from './utils/math'
import * as time from './utils/time'

export {api, localStorage, math, time}
28 changes: 28 additions & 0 deletions shared/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions shared/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "shared",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"author": "Avasam (Samuel Therrien)",
"license": "AGPL-3.0",
"dependencies": {
"http-status-codes": "^2.2.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tournament-scheduler/src/Components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { StatusCodes } from 'http-status-codes'
import { useEffect, useState } from 'react'
import { Link as RouterLink, Route, Routes, useLocation } from 'react-router-dom'

import { apiGet } from '../../../shared/api'
import copyToClipboard from '../../../shared/utils/clipboard'
import LoginForm from './LoginForm/LoginForm'
import ScheduleManagement from './ScheduleManagement/ScheduleManagement'
import ScheduleRegistration from './ScheduleRegistration'
import ScheduleGroupViewer from './ScheduleViewer/ScheduleGroupViewer'
import ScheduleViewer from './ScheduleViewer/ScheduleViewer'
import { apiGet } from 'src/fetchers/api'
import type User from 'src/Models/User'
import darkTheme from 'src/styles/dark.theme'
import lightTheme from 'src/styles/light.theme'
import copyToClipboard from 'src/utils/clipboard'

type Themes = 'dark' | 'light'
type StylesOverrides = { body: { background: string } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import useMediaQuery from '@mui/material/useMediaQuery'
import { useState } from 'react'

import SpeedruncomApiKeyLink from './SpeedruncomApiKeyLink'
import { apiPost } from 'src/fetchers/api'
import { apiPost } from '../../../shared/api'
import type User from 'src/Models/User'

type loginFormProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { MoveToGroupMenuProps } from './MoveToGroupMenu'
import MoveToGroupMenu from './MoveToGroupMenu'
import type { IOrderableProps } from 'src/Models/IOrderable'
import type { Schedule } from 'src/Models/Schedule'
import copyToClipboard from 'src/utils/clipboard'
import copyToClipboard from '../../../../shared/utils/clipboard'

type ScheduleCardProps = IOrderableProps<Schedule> & MoveToGroupMenuProps & {
schedule: Schedule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { memo, useEffect, useState } from 'react'
import ScheduleCard from './ScheduleCard/ScheduleCard'
import ScheduleGroupCard from './ScheduleCard/ScheduleGroupCard'
import { ScheduleWizard } from './ScheduleWizard/ScheduleWizard'
import { apiDelete, apiGet, apiPost, apiPut } from 'src/fetchers/api'
import { apiDelete, apiGet, apiPost, apiPut } from '../../../shared/api'
import type { ScheduleDto, ScheduleGroupDto, ScheduleOrderDto } from 'src/Models/Schedule'
import { isGroup, Schedule, ScheduleGroup } from 'src/Models/Schedule'
import { TimeSlot } from 'src/Models/TimeSlot'
import type User from 'src/Models/User'
import { arrayMove } from 'src/utils/objectUtils'
import { arrayMove } from '../../../../shared/utils/objectUtils'

const getSchedules = () =>
apiGet<ScheduleDto[] | undefined>('schedules')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import TimeSlotRow from './TimeSlotRow'
import DisableDashlane from 'src/Components/DisableDashlane'
import type { Schedule, ScheduleDto } from 'src/Models/Schedule'
import { TimeSlot } from 'src/Models/TimeSlot'
import { DEADLINE_FORMAT, diffDays, startOfDay } from 'src/utils/date'
import type { NonFunctionProperties } from 'src/utils/objectUtils'
import { getDeadlineDueText } from 'src/utils/scheduleHelper'
import { DEADLINE_FORMAT, diffDays, startOfDay } from '../../../../shared/utils/date'
import type { NonFunctionProperties } from '../../../../shared/utils/objectUtils'
import { getDeadlineDueText } from '../../../../shared/utils/scheduleHelper'

const calendarIconStyle: SxProps<Theme> = {
'.MuiInput-root > .MuiSvgIcon-root': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import dayjs from 'dayjs'
import type { MouseEventHandler } from 'react'
import { useState } from 'react'

import { apiDelete, apiPut } from '../../../../../shared/api'
import NonZeroNumberInput from './NonZeroNumberInput'
import RegistrationList from './RegistrationList'
import { apiDelete, apiPut } from 'src/fetchers/api'
import type { RegistrationProxy } from 'src/Models/Registration'
import type Registration from 'src/Models/Registration'
import type { Schedule } from 'src/Models/Schedule'
import type { TimeSlot } from 'src/Models/TimeSlot'
import { minutesStep } from 'src/Models/TimeSlot'
import { TIMESLOT_FORMAT } from 'src/utils/date'
import type { NonFunctionProperties } from 'src/utils/objectUtils'
import { createProxy } from 'src/utils/objectUtils'
import { TIMESLOT_FORMAT } from '../../../../shared/utils/date'
import type { NonFunctionProperties } from '../../../../shared/utils/objectUtils'
import { createProxy } from '../../../../shared/utils/objectUtils'

const MIN_YEAR = 2000

Expand Down
6 changes: 3 additions & 3 deletions tournament-scheduler/src/Components/ScheduleRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { useEffect, useState } from 'react'
import { Helmet } from 'react-helmet'
import { Link as RouterLink, useNavigate, useParams } from 'react-router-dom'

import { apiGet, apiPost } from '../../../shared/api'
import { addTime, diffDays, fancyFormat } from '../../../shared/utils/date'
import { getDeadlineDueText } from '../../../shared/utils/scheduleHelper'
import DisableDashlane from 'src/Components/DisableDashlane'
import { apiGet, apiPost } from 'src/fetchers/api'
import type { ScheduleDto } from 'src/Models/Schedule'
import { Schedule } from 'src/Models/Schedule'
import { TimeSlot } from 'src/Models/TimeSlot'
import { addTime, diffDays, fancyFormat } from 'src/utils/date'
import { getDeadlineDueText } from 'src/utils/scheduleHelper'

const timeSlotLabelPaddingRight = 40

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Button } from '@mui/material'

import type { Schedule } from 'src/Models/Schedule'
import type { TimeSlot } from 'src/Models/TimeSlot'
import { addTime } from 'src/utils/date'
import { buildCalendarEventDescription, buildCalendarEventTitle } from 'src/utils/scheduleHelper'
import { addTime } from '../../../../shared/utils/date'
import { buildCalendarEventDescription, buildCalendarEventTitle } from '../../../../shared/utils/scheduleHelper'

type AddScheduleToCalendarProps = {
schedule: Schedule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Helmet } from 'react-helmet'
import { useParams } from 'react-router-dom'

import ScheduleViewer, { TimeZoneMessage } from 'src/Components/ScheduleViewer/ScheduleViewer'
import { apiGet } from 'src/fetchers/api'
import { apiGet } from '../../../shared/api'
import type { ScheduleDto, ScheduleGroupDto } from 'src/Models/Schedule'
import { Schedule } from 'src/Models/Schedule'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { useEffect, useState } from 'react'
import { Helmet } from 'react-helmet'
import { useParams } from 'react-router-dom'

import { apiGet } from '../../../../shared/api'
import TimeSlotView from 'src/Components/ScheduleViewer/TimeSlotView'
import { apiGet } from 'src/fetchers/api'
import type { ScheduleDto } from 'src/Models/Schedule'
import { Schedule } from 'src/Models/Schedule'
import { TimeSlot } from 'src/Models/TimeSlot'
import { diffDays } from 'src/utils/date'
import { getDeadlineDueText } from 'src/utils/scheduleHelper'
import { diffDays } from '../../../../shared/utils/date'
import { getDeadlineDueText } from '../../../../shared/utils/scheduleHelper'

const embedded = typeof new URLSearchParams(window.location.search).get('embedded') == 'string'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Grid, List, ListItem, ListItemText, Paper } from '@mui/material'
import AddScheduleToCalendarButton from 'src/Components/ScheduleViewer/AddScheduleToCalendarButton'
import type { Schedule } from 'src/Models/Schedule'
import type { TimeSlot } from 'src/Models/TimeSlot'
import { fancyFormat } from 'src/utils/date'
import { fancyFormat } from '../../../../shared/utils/date'

type Props = {
timeSlot: TimeSlot
Expand Down
6 changes: 3 additions & 3 deletions tournament-scheduler/src/Models/Schedule.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type IOrderable from './IOrderable'
import type { TimeSlotDto } from './TimeSlot'
import { TimeSlot } from './TimeSlot'
import { nextDayFlat } from 'src/utils/date'
import type { NonFunctionProperties } from 'src/utils/objectUtils'
import { createProxy } from 'src/utils/objectUtils'
import { nextDayFlat } from '../../../../shared/utils/date'
import type { NonFunctionProperties } from '../../../../shared/utils/objectUtils'
import { createProxy } from '../../../../shared/utils/objectUtils'

export type ScheduleDto = IOrderable & {
id: number
Expand Down
2 changes: 1 addition & 1 deletion tournament-scheduler/src/Models/TimeSlot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Registration from './Registration'
import { floorToMinutesStep, nextDay } from 'src/utils/date'
import { floorToMinutesStep, nextDay } from '../../../../shared/utils/date'

export const minutesStep = 5

Expand Down
2 changes: 1 addition & 1 deletion tournament-scheduler/src/styles/base.theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { ThemeOptions } from '@mui/material/styles'
import { createTheme } from '@mui/material/styles'

import math from 'src/utils/math'
import math from '../../../../shared/utils/math'

// Uses default `{spacing: 8}`
const themeSpacing = createTheme().spacing
Expand Down
2 changes: 1 addition & 1 deletion tournament-scheduler/src/styles/dark.theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createTheme } from '@mui/material'
import { lightBlue as secondary, red as error, teal as primary, yellow as warn } from '@mui/material/colors'

import baseThemeOptions from './base.theme'
import { mergeDeep } from 'src/utils/objectUtils'
import { mergeDeep } from '../../../../shared/utils/objectUtils'

// Actual theme declaration
const theme = createTheme(mergeDeep(
Expand Down
2 changes: 1 addition & 1 deletion tournament-scheduler/src/styles/light.theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createTheme } from '@mui/material'
import { amber as warn, indigo as primary, orange as secondary, red as error } from '@mui/material/colors'

import baseThemeOptions from './base.theme'
import { mergeDeep } from 'src/utils/objectUtils'
import { mergeDeep } from '../../../../shared/utils/objectUtils'

// Actual theme declaration
const theme = createTheme(mergeDeep(
Expand Down
Loading

0 comments on commit 5ab172e

Please sign in to comment.