Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/components-react/widgets/GenericGoal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ export function GenericGoal() {
};
}

// Note: the loading state `w.state.isLoading` must be checked directly for reactivity. `w.hasLoadedSettings` is only called
// once and on component load will always show the loading state as false
Comment thread
michelinewu marked this conversation as resolved.
Outdated
return (
<WidgetLayout>
<Menu onClick={e => w.setSelectedTab(e.key)} selectedKeys={[w.selectedTab]}>
<Menu.Item key="general">{$t('Visual Settings')}</Menu.Item>
{!isCharity && <Menu.Item key="goal">{$t('Goal Settings')}</Menu.Item>}
</Menu>
<Form>
{w.hasLoadedSettings() && w.selectedTab === 'goal' && !hasGoal && (
{!w.state.isLoading && w.hasLoadedSettings() && w.selectedTab === 'goal' && !hasGoal && (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed this is happening, though it's not an issue in the actual prod flow since it's already loaded.

I don't think that we can't both get reactivity and TypeScript predicates to play nice, since the way it works would require mutating the object to use useMemo or useCallback and corrupt the underlying service object.

Let's just remove hasLoadedSettings and inline its check in all the widgets, I'd prefer that over using the sugar and then also having to re-write half of its logic outside the function every time.

Should just need to:

  1. Delete hasLoadedSettings function
  2. Find target: w.hasLoadedSettings()
    • Replace with: !w.state.isLoading && w.settings
  3. Find target: this.hasLoadedSettings()
    • Replace with: !this.state.isLoading && this.settings
  4. Find target: [w.settings, w.hasLoadedSettings]
    • Replace with: [w.state.isLoading, w.settings]

<>
<FormFactory
metadata={w.createGoalMeta}
Expand All @@ -91,10 +93,10 @@ export function GenericGoal() {
</Button>
</>
)}
{w.hasLoadedSettings() && w.selectedTab === 'goal' && hasGoal && (
{!w.state.isLoading && w.hasLoadedSettings() && w.selectedTab === 'goal' && hasGoal && (
<DisplayGoal goal={w.goalSettings} resetGoal={w.resetGoal} />
)}
{w.hasLoadedSettings() && w.selectedTab === 'general' && (
{!w.state.isLoading && w.hasLoadedSettings() && w.selectedTab === 'general' && (
<FormFactory
metadata={w.visualMeta}
values={w.settings}
Expand Down
7 changes: 7 additions & 0 deletions test/regular/widgets/goals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { addSource } from '../../helpers/modules/sources';
import { logIn } from '../../helpers/webdriver/user';
import { waitForWidgetSettingsSync } from '../../helpers/widget-helpers';
import { assertFormContains, fillForm, useForm } from '../../helpers/modules/forms';
import { closeWindow } from '../../helpers/modules/core';
import { platform } from 'os';
Comment thread
michelinewu marked this conversation as resolved.

// not a react hook
// eslint-disable-next-line react-hooks/rules-of-hooks
useWebdriver();

testGoal('Tip Goal');
Expand Down Expand Up @@ -73,6 +77,9 @@ function testGoal(goalType: string) {
await fillForm('visualSettingsForm', testSet2);
await waitForWidgetSettingsSync(t);
await assertFormContains(testSet2);
if (platform() !== 'darwin') {
await closeWindow('child');
}
Comment thread
michelinewu marked this conversation as resolved.

t.pass();
});
Expand Down
Loading