Skip to content

Commit

Permalink
fix: fix rate-limit naming jank when a single token
Browse files Browse the repository at this point in the history
  • Loading branch information
dayvar14 committed Oct 29, 2024
1 parent 4bbe67e commit 52aba4d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/components/InitiativeList/InitiativeSubListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import { Group, Player, Token } from '@obr'
import clsx from 'clsx'
import { useContext, useEffect, useState } from 'react'

import { PLACE_HOLDER_TOKEN_IMAGE } from 'config'
import { GroupContext } from 'context/GroupContext'
import { PartyContext } from 'context/PartyContext'
import { PermissionContext } from 'context/PermissionContext'
import { PlayerContext } from 'context/PlayerContext'
import { SettingsContext } from 'context/SettingsContext'

import InitiativeSubListSubItem from './InitiativeSubListSubItem'
import { PLACE_HOLDER_TOKEN_IMAGE } from 'config'

const InitiativeSubListItem: React.FC<{
subGroup: SubGroup
Expand Down Expand Up @@ -120,27 +120,27 @@ const InitiativeSubListItem: React.FC<{
}

useEffect(() => {
if (tokens.length === 1) {
if (tokens.length === 1 && tokens[0]) {
setIsExpanded(false)

const tokenName = tokens[0]?.plainTextName || tokens[0]?.name

const tokenName = tokens[0]?.plainTextName
? tokens[0]?.plainTextName
: tokens[0]?.name
if (tokenName !== subGroup.subGroupName) {
subGroup.subGroupName = tokenName
Group.updateSubgroupByGroupType(subGroup.groupType, subGroup)
}
}

setImageSrc(tokens[0]?.imageUrl || PLACE_HOLDER_TOKEN_IMAGE)
}, [tokens])
}, [tokens, subGroup])

const handleNameChange = async () => {
let updatedName = newName || tokens[0]?.name
const { subGroupName, groupType } = subGroup

if (updatedName !== subGroupName) {
const subGroupCopy = { ...subGroup, subGroupName: updatedName }
await Group.updateSubgroupByGroupType(groupType, subGroupCopy)

if (tokens.length === 1) {
const tokenName = tokens[0]?.plainTextName || tokens[0]?.name
Expand All @@ -151,6 +151,8 @@ const InitiativeSubListItem: React.FC<{
}
}

await Group.updateSubgroupByGroupType(groupType, subGroupCopy)

setNewName(updatedName)
}

Expand Down

0 comments on commit 52aba4d

Please sign in to comment.