Skip to content

Commit

Permalink
fix: initial bounds loading control profile
Browse files Browse the repository at this point in the history
  • Loading branch information
thenick775 committed Feb 24, 2025
1 parent 163fbb7 commit a1651dc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gbajs3/src/components/modals/controls/control-profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { useState } from 'react';
import { BiTrash, BiEdit, BiSave } from 'react-icons/bi';
import { styled } from 'styled-components';

import { useLayoutContext } from '../../../hooks/context.tsx';
import {
useInitialBoundsContext,
useLayoutContext
} from '../../../hooks/context.tsx';
import { virtualControlProfilesLocalStorageKey } from '../../controls/consts.tsx';
import { CenteredText, StyledBiPlus } from '../../shared/styled.tsx';

Expand Down Expand Up @@ -167,6 +170,7 @@ export const ControlProfiles = ({ id }: ControlProfilesProps) => {
VirtualControlProfiles | undefined
>(virtualControlProfilesLocalStorageKey);
const { layouts, setLayouts } = useLayoutContext();
const { clearInitialBounds } = useInitialBoundsContext();

const addProfile = () => {
setVirtualControlProfiles((prevState) => [
Expand All @@ -180,6 +184,11 @@ export const ControlProfiles = ({ id }: ControlProfilesProps) => {
]);
};

const loadProfile = (layouts: Layouts) => {
setLayouts(layouts);
clearInitialBounds();
};

const updateProfile = (id: string, updatedName: string) => {
setVirtualControlProfiles((prevState) =>
prevState?.map((profile) => {
Expand Down Expand Up @@ -208,7 +217,7 @@ export const ControlProfiles = ({ id }: ControlProfilesProps) => {
<StyledLi key={`${profile.name}_${idx}_action_list_item`}>
<EditableProfileLoadButton
name={profile.name}
loadProfile={() => setLayouts(profile.layouts)}
loadProfile={() => loadProfile(profile.layouts)}
onSubmit={(name) => updateProfile(profile.id, name)}
/>
<IconButton
Expand Down

0 comments on commit a1651dc

Please sign in to comment.