Skip to content

Commit

Permalink
fix(ui): Label Position Resets After Changing Number of Rows (#131)
Browse files Browse the repository at this point in the history
* Assign labelPosition to decodedState tiers

* Add semicolon

* Minor refactor for readability

---------

Co-authored-by: infinia-yzl <dev@infinia.space>
  • Loading branch information
HecticKiwi and infinia-yzl authored Dec 28, 2024
1 parent a0afd75 commit 6865550
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions components/TierListManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,25 @@ const TierListManager: React.FC<TierListManagerProps> = ({initialItemSet, initia

useEffect(() => {
const state = searchParams.get('state');
if (state) {
const decodedState = tierCortex.decodeTierStateFromURL(state);
if (decodedState) {
if (decodedState.title) {
setName(decodedState.title);
}
setTiers(decodedState.tiers);

setUrlLength(pathname.length + state.length + 7); // 7 is the length of "?state="
}
if (!state) return;

const decodedState = tierCortex.decodeTierStateFromURL(state);
if (!decodedState) return;

// Update name if present
if (decodedState.title) {
setName(decodedState.title);
}
}, [pathname.length, searchParams, tierCortex]);

// Updated label positions
const updatedTiers = decodedState.tiers.map(tier => ({
...tier,
labelPosition
}));

setTiers(updatedTiers);
setUrlLength(pathname.length + state.length + 7); // 7 is the length of "?state="
}, [pathname.length, searchParams, tierCortex, labelPosition]);

const handleTiersUpdate = useCallback((updatedTiers: Tier[]) => {
previousTiersRef.current = updatedTiers;
Expand Down

0 comments on commit 6865550

Please sign in to comment.