From 2f5b1582cd7d9450316cfb7289de7c079cd8df54 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 5 Jun 2023 20:14:30 -0700 Subject: [PATCH] Update types Added RaidGroup and updated Raid, then updated dependent types and objects --- components/RaidSelect/index.scss | 22 ++++ components/RaidSelect/index.tsx | 170 +++++++++++++++++++++++++++++++ types/Raid.d.ts | 2 +- types/RaidGroup.d.ts | 14 +++ types/index.d.ts | 3 +- utils/appState.tsx | 4 +- 6 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 components/RaidSelect/index.scss create mode 100644 components/RaidSelect/index.tsx create mode 100644 types/RaidGroup.d.ts diff --git a/components/RaidSelect/index.scss b/components/RaidSelect/index.scss new file mode 100644 index 00000000..e6eaa60f --- /dev/null +++ b/components/RaidSelect/index.scss @@ -0,0 +1,22 @@ +.Raid.Select { + min-width: 420px; + + .Top { + display: flex; + flex-direction: column; + gap: $unit; + padding: $unit 0; + + .SegmentedControl { + width: 100%; + } + + .Input.Bound { + background-color: var(--select-contained-bg); + + &:hover { + background-color: var(--select-contained-bg-hover); + } + } + } +} diff --git a/components/RaidSelect/index.tsx b/components/RaidSelect/index.tsx new file mode 100644 index 00000000..8d114b59 --- /dev/null +++ b/components/RaidSelect/index.tsx @@ -0,0 +1,170 @@ +import React, { useEffect, useState } from 'react' +import { useTranslation } from 'react-i18next' +import * as RadixSelect from '@radix-ui/react-select' +import classNames from 'classnames' + +import Overlay from '~components/common/Overlay' + +import ChevronIcon from '~public/icons/Chevron.svg' + +import './index.scss' +import SegmentedControl from '~components/common/SegmentedControl' +import Segment from '~components/common/Segment' +import Input from '~components/common/Input' + +// Props +interface Props + extends React.DetailedHTMLProps< + React.SelectHTMLAttributes, + HTMLSelectElement + > { + altText?: string + currentSegment: number + iconSrc?: string + open: boolean + trigger?: React.ReactNode + children?: React.ReactNode + onOpenChange?: () => void + onValueChange?: (value: string) => void + onSegmentClick: (segment: number) => void + onClose?: () => void + triggerClass?: string + overlayVisible?: boolean +} + +const RaidSelect = React.forwardRef(function Select( + props: Props, + forwardedRef +) { + // Import translations + const { t } = useTranslation('common') + + const searchInput = React.createRef() + + const [open, setOpen] = useState(false) + const [value, setValue] = useState('') + const [query, setQuery] = useState('') + + const triggerClasses = classNames( + { + SelectTrigger: true, + Disabled: props.disabled, + }, + props.triggerClass + ) + + useEffect(() => { + setOpen(props.open) + }, [props.open]) + + useEffect(() => { + if (props.value && props.value !== '') setValue(`${props.value}`) + else setValue('') + }, [props.value]) + + function onValueChange(newValue: string) { + setValue(`${newValue}`) + if (props.onValueChange) props.onValueChange(newValue) + } + + function onCloseAutoFocus() { + setOpen(false) + if (props.onClose) props.onClose() + } + + function onEscapeKeyDown() { + setOpen(false) + if (props.onClose) props.onClose() + } + + function onPointerDownOutside() { + setOpen(false) + if (props.onClose) props.onClose() + } + + return ( + + + {props.iconSrc ? {props.altText} : ''} + + {!props.disabled ? ( + + + + ) : ( + '' + )} + + + + <> + + + +
+ {}} + /> + + props.onSegmentClick(1)} + > + {t('raids.sections.events')} + + props.onSegmentClick(0)} + > + {t('raids.sections.raids')} + + props.onSegmentClick(2)} + > + {t('raids.sections.solo')} + + +
+ {props.children} +
+ +
+
+ ) +}) + +RaidSelect.defaultProps = { + overlayVisible: true, +} + +export default RaidSelect diff --git a/types/Raid.d.ts b/types/Raid.d.ts index 5b6cf588..89e599d5 100644 --- a/types/Raid.d.ts +++ b/types/Raid.d.ts @@ -1,5 +1,6 @@ interface Raid { id: string + group: RaidGroup name: { [key: string]: string en: string @@ -7,6 +8,5 @@ interface Raid { } slug: string level: number - group: number element: number } diff --git a/types/RaidGroup.d.ts b/types/RaidGroup.d.ts new file mode 100644 index 00000000..d6290a3f --- /dev/null +++ b/types/RaidGroup.d.ts @@ -0,0 +1,14 @@ +interface RaidGroup { + id: string + name: { + [key: string]: string + en: string + ja: string + } + raids: Raid[] + difficulty: number + section: number + order: number + extra: boolean + hl: boolean +} diff --git a/types/index.d.ts b/types/index.d.ts index 307c3026..77a721b2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -83,8 +83,7 @@ interface PageContextObj { party?: Party jobs?: Job[] jobSkills?: JobSkill[] - raids: Raid[] - sortedRaids: Raid[][] + raidGroups: RaidGroup[] weaponKeys?: GroupedWeaponKeys pagination?: PaginationObject meta?: { [key: string]: string } diff --git a/utils/appState.tsx b/utils/appState.tsx index de2b94b7..214763ce 100644 --- a/utils/appState.tsx +++ b/utils/appState.tsx @@ -83,7 +83,7 @@ interface AppState { summons: Summon[] } } - raids: Raid[] + raidGroups: RaidGroup[] jobs: Job[] jobSkills: JobSkill[] weaponKeys: GroupedWeaponKeys @@ -149,7 +149,7 @@ export const initialAppState: AppState = { summons: [], }, }, - raids: [], + raidGroups: [], jobs: [], jobSkills: [], weaponKeys: {