Deploy transcendence fixes (#351)

* Rich text editor and support for tagging objects (#340)

* 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

* Override peer dependencies for tiptap mentions

They haven't fixed the suggestion plugin, so we have to use a beta version

* Fix background-color on CharacterRep

* Tiptap updates (#343)

* Reinstantiate editor on changes

We can't dynamically update the content, so we have to recreate the Editor whenever something changes (page loads and updates)

* Fix import

@tiptap/core is different than @tiptap/react, who knew

* Added several Tiptap components

* Added a Remix icon that isn't in remixicon-react

* Add colors for highlights

* Add ToolbarButton component

This is to standardize adding Toolbar icons so it wasn't a miserable mess in the Editor file

* Add extensions and implement ToolbarButton

* Remove unused code

* Use party prop and add keys

We always want to use the party in props until the transformer work is done and our source of truth is more reliable.

Also, we are using keys to ensure that the component reloads on new page.

* Component cleanup

* Always use props.party

* Ensure content gets reset when edits are committed

Here, we do some tactical bandaid fixes to ensure that when the user saves data to the server, the editor will show the freshest data in both editable and read-only mode.

In the Editor, its as easy as calling the setContent command in a useEffect hook when the content changes.

In the party, we are saving party in a state and passing it down to the components via props. This is because the party prop we get from pages is only from the first time the server loaded data, so any edits are not reflected. The app state should have the latest updates, but due to reasons I don't completely understand, it is showing the old state first and then the one we want, causing the Editor to get stuck on old data.

By storing the party in a state, we can populate the state from the server when the component mounts, then update it whenever the user saves data since all party data is saved in that component.

* Fix build errors

* Fix icon path

* Remove duplicate binding

* Fix styles

* Update transcendence components to work with CSS modules (#350)

* Update transcendence components to use CSS modules

* Fix summon transcendence

Summon transcendence was doing something wonky. This adapts the updateUncap endpoint method to make it a little bit clearer whats going on.

* Add toolbar localizations

* Allow translation of Heading icons

* Show localized placeholder for team name

* Add placeholder extension

* Add placeholder to party description

* Ensure name modification works right

Needed a null check? for some reason?
This commit is contained in:
Justin Edmund 2023-07-06 17:09:21 -07:00 committed by GitHub
parent a19e2055b9
commit 65bc7100c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 177 additions and 49 deletions

View file

@ -36,6 +36,14 @@
outline: none;
}
p.empty:first-child::before {
color: var(--text-tertiary);
content: attr(data-placeholder);
float: left;
height: 0;
pointer-events: none;
}
&.bound {
background-color: var(--input-bound-bg);

View file

@ -1,9 +1,12 @@
import { ComponentProps, useCallback, useEffect } from 'react'
import { useRouter } from 'next/router'
import { useEditor, EditorContent } from '@tiptap/react'
import { useRouter } from 'next/router'
import { useTranslation } from 'next-i18next'
import StarterKit from '@tiptap/starter-kit'
import Link from '@tiptap/extension-link'
import Highlight from '@tiptap/extension-highlight'
import Placeholder from '@tiptap/extension-placeholder'
import Typography from '@tiptap/extension-typography'
import Youtube from '@tiptap/extension-youtube'
import CustomMention from '~extensions/CustomMention'
@ -45,6 +48,8 @@ const Editor = ({
const router = useRouter()
const locale = router.locale || 'en'
const { t } = useTranslation('common')
useEffect(() => {
editor?.commands.setContent(formatContent(content))
}, [content])
@ -72,6 +77,10 @@ const Editor = ({
}),
Link,
Highlight,
Placeholder.configure({
emptyEditorClass: styles.empty,
placeholder: t('modals.edit_team.placeholders.description'),
}),
Typography,
CustomMention.configure({
renderLabel({ options, node }) {

View file

@ -21,12 +21,6 @@
&.flush {
padding: 0;
}
.Arrow {
fill: var(--dialog-bg);
filter: drop-shadow(0px 1px 1px rgb(0 0 0 / 0.18));
margin-top: -1px;
}
}
.trigger {

View file

@ -0,0 +1,5 @@
.arrow {
fill: var(--dialog-bg);
filter: drop-shadow(0px 1px 1px rgb(0 0 0 / 0.18));
margin-top: -1px;
}

View file

@ -24,7 +24,13 @@ const ToolbarIcon = ({ editor, action, level, icon, onClick }: Props) => {
})
return (
<Tooltip content={t(`toolbar.tooltips.${action}`)}>
<Tooltip
content={
level
? t(`toolbar.tooltips.${action}`, { level: level })
: t(`toolbar.tooltips.${action}`)
}
>
<button onClick={onClick} className={classes}>
{icon}
</button>

View file

@ -297,7 +297,8 @@ const EditPartyModal = ({
// Methods: Modification checking
function hasBeenModified() {
const nameChanged =
name !== party.name && !(name === '' && party.name === undefined)
name !== party.name &&
!(name === '' && (party.name === undefined || party.name === null))
const descriptionChanged =
description !== party.description &&
!(description === '' && party.description === undefined)
@ -433,7 +434,7 @@ const EditPartyModal = ({
const nameField = (
<Input
name="name"
placeholder="Name your team"
placeholder={t('modals.edit_team.placeholders.name')}
autoFocus={true}
value={name}
maxLength={50}

View file

@ -261,9 +261,7 @@ const SummonGrid = (props: Props) => {
try {
if (stage != previousTranscendenceStages[position])
await api.endpoints.grid_summons
.update(id, payload)
.then((response) => {
await api.updateTranscendence('summon', id, stage).then((response) => {
storeGridSummon(response.data.grid_summon)
})
} catch (error) {

View file

@ -1,4 +1,4 @@
.Fragment {
.fragment {
$degrees: 72deg;
$origWidth: 29px;
@ -28,11 +28,11 @@
cursor: pointer;
}
&.Visible {
&.visible {
opacity: 1;
}
&.Stage1 {
&.stage1 {
top: 3px;
left: 18px;
@ -41,7 +41,7 @@
// }
}
&.Stage2 {
&.stage2 {
top: 10px;
left: 27px;
transform: rotate($degrees);
@ -51,7 +51,7 @@
// }
}
&.Stage3 {
&.stage3 {
top: 21px;
left: 24px;
transform: rotate($degrees * 2);
@ -61,7 +61,7 @@
// }
}
&.Stage4 {
&.stage4 {
top: 21px;
left: 12px;
transform: rotate($degrees * 3);
@ -71,7 +71,7 @@
// }
}
&.Stage5 {
&.stage5 {
top: 10px;
left: 8px;
transform: rotate($degrees * 4);

View file

@ -1,5 +1,5 @@
import React from 'react'
import classnames from 'classnames'
import classNames from 'classnames'
import styles from './index.module.scss'
@ -18,14 +18,14 @@ const TranscendenceFragment = ({
onClick,
onHover,
}: Props) => {
const classes = classnames({
Fragment: true,
Visible: visible,
Stage1: stage === 1,
Stage2: stage === 2,
Stage3: stage === 3,
Stage4: stage === 4,
Stage5: stage === 5,
const classes = classNames({
[styles.fragment]: true,
[styles.visible]: visible,
[styles.stage1]: stage === 1,
[styles.stage2]: stage === 2,
[styles.stage3]: stage === 3,
[styles.stage4]: stage === 4,
[styles.stage5]: stage === 5,
})
function handleClick() {

View file

@ -1,11 +1,20 @@
.Transcendence.Popover {
align-items: center;
.transcendence {
display: flex;
flex-direction: column;
gap: $unit-half;
display: flex;
align-items: center;
justify-content: center;
width: $unit-10x;
height: $unit-10x;
justify-content: center;
animation: scaleIn $duration-zoom ease-out;
background: var(--dialog-bg);
border-radius: $card-corner;
border: 0.5px solid rgba(0, 0, 0, 0.18);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24);
outline: none;
padding: $unit;
transform-origin: var(--radix-popover-content-transform-origin);
z-index: 32;
&.open {
@ -18,7 +27,50 @@
font-weight: $medium;
}
.Pending {
.pending {
color: $yellow;
}
}
@keyframes scaleIn {
0% {
opacity: 0;
transform: scale(0);
}
20% {
opacity: 0.2;
transform: scale(0.4);
}
40% {
opacity: 0.4;
transform: scale(0.8);
}
60% {
opacity: 0.6;
transform: scale(1);
}
65% {
opacity: 0.65;
transform: scale(1.1);
}
70% {
opacity: 0.7;
transform: scale(1);
}
75% {
opacity: 0.75;
transform: scale(0.98);
}
80% {
opacity: 0.8;
transform: scale(1.02);
}
90% {
opacity: 0.9;
transform: scale(0.96);
}
100% {
opacity: 1;
transform: scale(1);
}
}

View file

@ -2,8 +2,8 @@ import React, { PropsWithChildren, useEffect, useState } from 'react'
import { useTranslation } from 'next-i18next'
import classNames from 'classnames'
import { Popover } from '@radix-ui/react-popover'
import {
Popover,
PopoverAnchor,
PopoverContent,
} from '~components/common/PopoverContent'
@ -40,12 +40,8 @@ const TranscendencePopover = ({
const popoverRef = React.createRef<HTMLDivElement>()
const classes = classNames({
Transcendence: true,
})
const levelClasses = classNames({
Pending: stage != currentStage,
[styles.pending]: stage != currentStage,
})
useEffect(() => {
@ -77,16 +73,20 @@ const TranscendencePopover = ({
return (
<Popover open={open} onOpenChange={onOpenChange}>
<PopoverAnchor>{children}</PopoverAnchor>
<PopoverContent className={classes} ref={popoverRef} tabIndex={tabIndex}>
<PopoverContent
className={styles.transcendence}
ref={popoverRef}
tabIndex={tabIndex}
>
<TranscendenceStar
className="Interactive Base"
className="interactive base"
editable={true}
interactive={true}
stage={stage}
onFragmentClick={handleFragmentClicked}
onFragmentHover={handleFragmentHovered}
/>
<h4>
<h4 className="name">
<span>{t('level')}&nbsp;</span>
<span className={levelClasses}>{baseLevel + 10 * currentStage}</span>
</h4>

View file

@ -46,9 +46,12 @@ const TranscendenceStar = ({
[styles.stage5]: stage === 5,
})
const baseImageClasses = classnames(className, {
const baseImageClasses = classnames(
{
[styles.figure]: true,
})
},
className?.split(' ').map((c) => styles[c])
)
useEffect(() => {
setVisibleStage(stage)
@ -87,7 +90,7 @@ const TranscendenceStar = ({
onMouseLeave={interactive ? handleMouseLeave : () => {}}
tabIndex={tabIndex}
>
<div className="Fragments">
<div className={styles.fragments}>
{[...Array(NUM_FRAGMENTS)].map((e, i) => {
const loopStage = i + 1
return interactive ? (

14
package-lock.json generated
View file

@ -23,6 +23,7 @@
"@tiptap/extension-highlight": "^2.0.3",
"@tiptap/extension-link": "^2.0.3",
"@tiptap/extension-mention": "^2.0.3",
"@tiptap/extension-placeholder": "^2.0.3",
"@tiptap/extension-typography": "^2.0.3",
"@tiptap/extension-youtube": "^2.0.3",
"@tiptap/pm": "^2.0.3",
@ -7348,6 +7349,19 @@
"@tiptap/core": "^2.0.0"
}
},
"node_modules/@tiptap/extension-placeholder": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@tiptap/extension-placeholder/-/extension-placeholder-2.0.3.tgz",
"integrity": "sha512-Z42jo0termRAf0S0L8oxrts94IWX5waU4isS2CUw8xCUigYyCFslkhQXkWATO1qRbjNFLKN2C9qvCgGf4UeBrw==",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/ueberdosis"
},
"peerDependencies": {
"@tiptap/core": "^2.0.0",
"@tiptap/pm": "^2.0.0"
}
},
"node_modules/@tiptap/extension-strike": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@tiptap/extension-strike/-/extension-strike-2.0.3.tgz",

View file

@ -30,6 +30,7 @@
"@tiptap/extension-highlight": "^2.0.3",
"@tiptap/extension-link": "^2.0.3",
"@tiptap/extension-mention": "^2.0.3",
"@tiptap/extension-placeholder": "^2.0.3",
"@tiptap/extension-typography": "^2.0.3",
"@tiptap/extension-youtube": "^2.0.3",
"@tiptap/pm": "^2.0.3",

View file

@ -557,6 +557,19 @@
"tokens": {
"remix": "Remixed"
},
"toolbar": {
"tooltips": {
"bold": "Bold",
"italic": "Italic",
"strike": "Strikethrough",
"highlight": "Highlight",
"link": "Add a link",
"youtube": "Add a Youtube video",
"heading": "Heading {{level}}",
"bulletList": "Bullet list",
"orderedList": "Numbered list"
}
},
"tooltips": {
"copy_url": "Copy the URL to this team",
"new": "Create a new team",

View file

@ -555,6 +555,19 @@
"tokens": {
"remix": "リミックスされた"
},
"toolbar": {
"tooltips": {
"bold": "太字",
"italic": "斜体",
"strike": "取り消し線",
"highlight": "ハイライト",
"link": "リンクを挿入",
"youtube": "Youtube動画を埋め込む",
"heading": "見出し {{level}}",
"bulletList": "箇条書き",
"orderedList": "番号リスト"
}
},
"tooltips": {
"copy_url": "この編成のURLをコピーする",
"new": "新しい編成を作成する",

View file

@ -180,6 +180,17 @@ class Api {
})
}
updateTranscendence(resource: 'character'|'summon', id: string, value: number) {
const pluralized = resource + 's'
const resourceUrl = `${this.url}/${pluralized}/update_uncap`
return axios.post(resourceUrl, {
[resource]: {
id: id,
transcendence_step: value
}
})
}
userInfo(id: string) {
const resourceUrl = `${this.url}/users/info/${id}`
return axios.get(resourceUrl)