hensei-web/components/character/CharacterConflictModal/index.tsx
Justin Edmund 4c949d9206
July 2023 Feature Release: Rich text editor and support for tagging objects (#340) (#341)
* Preliminary work around making an Element type

* Disabled Youtube code for now

* Clean description with DOMPurify

* Update GranblueElement with slug

* Add new api endpoint for searching all resources

* Add new variables and themes

* Remove fixed height on html tag for now

* Update README.md

We renamed the folders for character images from `chara-` to `character-`

* Add no results string

* Add tiptap and associated packages

* Update .gitignore

* Update components that use character images

* Add Editor component

This commit adds the bulk of the code for our new rich-text editor. The Editor component will be used to edit and display rich text via Tiptap.

* Add mention components

This adds the code required for us to mention objects in rich text fields like team descriptions.

The mentionSuggestion util fetches data from the server and serves it to MentionList for the user to select, then inserts it into the Editor as a token.

* Implements Editor in edit team and team footer

This implements the Editor component in EditPartyModal and PartyFooter. In PartyFooter, it is read-only.

* Remove min-width on tokens

* Add rudimentary conversion for old descriptions

Old descriptions just translate as a blob of text, so we try to insert some paragraphs and newlines to keep things presentable and lessen the load if users decide to update

* Add support for displaying jobs in MentionList

* Handle numbers and value=0 better

* Keep description reactive

This shouldn't work? The snapshot should be the reactive one? I don't fucking know

* Send locale to api with search query

* Delete getLocale.tsx

We didn't actually use this

* Fix build errors
2023-07-05 21:51:30 -07:00

134 lines
3.9 KiB
TypeScript

import React, { useEffect, useState } from 'react'
import { useRouter } from 'next/router'
import { Trans, useTranslation } from 'next-i18next'
import { Dialog } from '~components/common/Dialog'
import DialogContent from '~components/common/DialogContent'
import DialogFooter from '~components/common/DialogFooter'
import Button from '~components/common/Button'
import Overlay from '~components/common/Overlay'
import { appState } from '~utils/appState'
import styles from './index.module.scss'
interface Props {
open: boolean
incomingCharacter?: Character
conflictingCharacters?: GridCharacter[]
desiredPosition: number
resolveConflict: () => void
resetConflict: () => void
}
const CharacterConflictModal = (props: Props) => {
// Localization
const router = useRouter()
const { t } = useTranslation('common')
const locale =
router.locale && ['en', 'ja'].includes(router.locale) ? router.locale : 'en'
// States
const [open, setOpen] = useState(false)
// Refs
const footerRef = React.createRef<HTMLDivElement>()
useEffect(() => {
setOpen(props.open)
}, [setOpen, props.open])
function imageUrl(character?: Character, uncap: number = 0) {
// Change the image based on the uncap level
let suffix = '01'
if (uncap == 6) suffix = '04'
else if (uncap == 5) suffix = '03'
else if (uncap > 2) suffix = '02'
// Special casing for Lyria (and Young Cat eventually)
if (character?.granblue_id === '3030182000') {
let element = 1
if (
appState.grid.weapons.mainWeapon &&
appState.grid.weapons.mainWeapon.element
) {
element = appState.grid.weapons.mainWeapon.element
} else if (appState.party.element != 0) {
element = appState.party.element
}
suffix = `${suffix}_0${element}`
}
return `${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/character-square/${character?.granblue_id}_${suffix}.jpg`
}
function openChange(open: boolean) {
setOpen(open)
props.resetConflict()
}
function close() {
setOpen(false)
props.resetConflict()
}
return (
<Dialog open={open} onOpenChange={openChange}>
<DialogContent
className="conflict"
footerref={footerRef}
onOpenAutoFocus={(event) => event.preventDefault()}
onEscapeKeyDown={close}
>
<div className={styles.content}>
<p>
<Trans i18nKey="modals.conflict.character"></Trans>
</p>
<div className={styles.diagram}>
<ul>
{props.conflictingCharacters?.map((character, i) => (
<li className={styles.character} key={`conflict-${i}`}>
<img
alt={character.object.name[locale]}
src={imageUrl(character.object, character.uncap_level)}
/>
<span>{character.object.name[locale]}</span>
</li>
))}
</ul>
<span className={styles.arrow}>&rarr;</span>
<div className={styles.wrapper}>
<div className={styles.character}>
<img
alt={props.incomingCharacter?.name[locale]}
src={imageUrl(props.incomingCharacter)}
/>
<span>{props.incomingCharacter?.name[locale]}</span>
</div>
</div>
</div>
</div>
<DialogFooter
rightElements={[
<Button
bound={true}
onClick={close}
key="cancel"
text={t('buttons.cancel')}
/>,
<Button
bound={true}
onClick={props.resolveConflict}
key="confirm"
text={t('modals.conflict.buttons.confirm')}
/>,
]}
/>
</DialogContent>
<Overlay open={open} visible={true} />
</Dialog>
)
}
export default CharacterConflictModal