Skip to content

Commit

Permalink
Update SettingsTabPanel behavior and UI state management.
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaoliao committed Feb 4, 2025
1 parent ce05f27 commit 376dd8e
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ const getConfigFormFields = (profileName: ProfileName) => {
*/
const handleConfigFormReset = (ev: React.FormEvent) => {
ev.preventDefault();
window.localStorage.clear();
window.location.reload();
};

Expand All @@ -129,6 +128,8 @@ const SettingsTabPanel = () => {
);
const [profilesMetadata, setProfilesMetadata] =
useState<ReadonlyMap<ProfileName, ProfileMetadata>>(listProfiles());
const [canApply, setCanApply] = useState<boolean>(false);
const [canReload, setCanReload] = useState<boolean>(false);

const handleConfigFormSubmit = useCallback((ev: React.FormEvent) => {
ev.preventDefault();
Expand Down Expand Up @@ -160,6 +161,8 @@ const SettingsTabPanel = () => {
}

setProfilesMetadata(listProfiles());
setCanApply(false);
setCanReload(true);
}, [
postPopUp,
selectedProfileName,
Expand All @@ -185,6 +188,9 @@ const SettingsTabPanel = () => {
tabIndex={-1}
onReset={handleConfigFormReset}
onSubmit={handleConfigFormSubmit}
onChange={() => {
setCanApply(true);
}}
>
<CustomTabPanel
tabName={TAB_NAME.SETTINGS}
Expand All @@ -193,14 +199,16 @@ const SettingsTabPanel = () => {
<>
<PanelTitleButton
color={"neutral"}
title={"Reset Default"}
disabled={false === canReload}
title={"Reload"}
type={"reset"}
>
<RestartAltIcon/>
</PanelTitleButton>
<PanelTitleButton
color={"primary"}
title={"Apply & Reload"}
disabled={false === canApply}
title={"Apply"}
type={"submit"}
>
<CheckIcon/>
Expand All @@ -225,7 +233,7 @@ const SettingsTabPanel = () => {
size={"sm"}
sx={{flexGrow: 1}}
value={selectedProfileName}
startDecorator={
endDecorator={
<ToggleButtonGroup
size={"sm"}
spacing={0.1}
Expand All @@ -239,14 +247,12 @@ const SettingsTabPanel = () => {
<Tooltip
title={"Delete locally stored profile"}
>
<IconButton>
<MenuButton
size={"sm"}
sx={{width: 0, paddingInline: 0}}
>
<DeleteIcon/>
</MenuButton>
</IconButton>
<MenuButton
size={"sm"}
sx={{paddingInline: "3px", zIndex: 10}}
>
<DeleteIcon/>
</MenuButton>
</Tooltip>
<Menu
size={"sm"}
Expand All @@ -272,6 +278,7 @@ const SettingsTabPanel = () => {

forceProfile(newForcedProfileName);
setProfilesMetadata(listProfiles());
setCanReload(true);
}}
>
<LockIcon/>
Expand Down

0 comments on commit 376dd8e

Please sign in to comment.