Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint 1-2 #315

Merged
merged 45 commits into from
Jan 28, 2025
Merged

Sprint 1-2 #315

merged 45 commits into from
Jan 28, 2025

Conversation

LucasMaupin
Copy link
Contributor

No description provided.

Saelmala and others added 30 commits December 13, 2024 08:39
Co-authored-by: Linda Malm <[email protected]>
Co-authored-by: Sandra Larsson <[email protected]>
Co-authored-by: Linda Malm <[email protected]>
Co-authored-by: Sandra Larsson <[email protected]>
Co-authored-by: lucasmaupin <[email protected]>
@Saelmala Saelmala requested a review from martinstark January 20, 2025 08:35
Copy link
Collaborator

@martinstark martinstark left a comment

Choose a reason for hiding this comment

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

I'm not going to block merging to main, but I think there are a few things that should be changed before this goes core.

I might be wrong about the watch comments and how it triggers re-renders (I might remember wrong), but I think it would still make sense to rework it to use useWatch on single fields to avoid unnecessary re-renders.

src/api/api.ts Outdated
Comment on lines 29 to 33
export type TBasicProductionResponse = {
name: string;
productionId: string;
lines?: TLine[];
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

TFetchProductionResponse exists which has lines as well, could this type be reused instead of introducing optional lines on the basic type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

me

src/bowser.ts Show resolved Hide resolved
src/bowser.ts Show resolved Hide resolved
store.write(key, value);
};

const clearStorage = (key: keyof Schema) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

NITPICK: from the naming it sounds like this method would clear the entire storage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

me

Comment on lines 108 to 125
useEffect(() => {
if (isSomeoneSpeaking) {
if (!shouldReduceVolume) {
startTimeoutRef.current = setTimeout(() => {
setShouldReduceVolume(true);
}, 1000);
}
} else {
if (startTimeoutRef.current) {
clearTimeout(startTimeoutRef.current);
startTimeoutRef.current = null;
}

if (shouldReduceVolume) {
setShouldReduceVolume(false);
}
}
}, [isSomeoneSpeaking, shouldReduceVolume]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this effect needs to clear the timeout when the component is de-rendered

Copy link
Contributor

Choose a reason for hiding this comment

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

});

// Watch all form values
const watchedValues = watch();
Copy link
Collaborator

@martinstark martinstark Jan 23, 2025

Choose a reason for hiding this comment

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

would it make sense to useWatch here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

me

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this file should be converted to use react-hook-form instead of the custom input/error handling

payload,
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Collaborator

Choose a reason for hiding this comment

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

please rework hook to ensure this is not needed, it indicates issues with state management and can cause bugs now or down the line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

me

@malmen237 malmen237 requested a review from martinstark January 28, 2025 10:09
Comment on lines 9 to 17
// Create a store of the desired type. If it is not available,
// in-memory storage will be used as a fallback.
const store = createStorage<Schema>({
type: StorageType.LOCAL,
prefix: "id",
silent: true,
});

export function useStorage() {
const [store, setStore] = useState<StorageTS<Schema>>();

useEffect(() => {
// Create a store of the desired type. If it is not available,
// in-memory storage will be used as a fallback.
setStore(
createStorage<Schema>({
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's reasonable that the store is a global, we don't need to create a new store each time useStorage is mounted in different components. If we have several instances of store, they all manipulate the same global localstorage anyway, unless their id is unique.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently we only need one store and this is to prevent a bunch of updates when subscribing to the returned functions. +1

Comment on lines 123 to 146
const onSubmit: SubmitHandler<FormValues> = (value) => {
setLoading(true);
API.createProduction({
name: value.productionName,
lines: [
{
name: value.defaultLine,
programOutputLine: value.defaultLineProgramOutput,
},
...value.lines,
],
})
.then((v) => {
setCreatedProductionId(v.productionId);
setLoading(false);
})
.catch((error) => {
dispatch({
type: "ERROR",
payload: error,
});
setLoading(false);
});
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I realize this isn't new code, but all async side effects should be made inside a useEffect hook so that they can be cleaned up if the component is unmounted while the async action is ongoing.

The way to achieve that here would be to check formState: { isSubmitted } or submitCount state, which in turn triggers a useEffect hook that makes the API call. The effect could then have if (aborted) guards so that we don't try to call setCreatedProductionId or dispatch an error if the component has been unmounted.

@martinstark martinstark merged commit 6ded2a6 into main Jan 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants