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

[Platform] Use React for state management in literature section #416

Open
wants to merge 13 commits into
base: ot-literature-section
Choose a base branch
from

Conversation

gjmcn
Copy link
Contributor

@gjmcn gjmcn commented Jul 18, 2024

Description

Use React instead of Recoil for state management in literature section.

Issue: #3292

Type of change

How Has This Been Tested?

Checked in dev.

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have made corresponding changes to the documentation

Copy link
Contributor

@carcruz carcruz left a comment

Choose a reason for hiding this comment

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

Please remove old highlighted folder/files of the PR to reflect the concise changes

@gjmcn
Copy link
Contributor Author

gjmcn commented Jul 19, 2024

Is it best to leave them until we are sure no other tweaks for the state mgmt are needed? - all profile pages show only the new literature widget then the old for easy comparison. (Admittedly, it would have been better to leave the original folder name unchanged!)

@carcruz
Copy link
Contributor

carcruz commented Jul 19, 2024

Is it best to leave them until we are sure no other tweaks for the state mgmt are needed? - all profile pages show only the new literature widget then the old for easy comparison. (Admittedly, it would have been better to leave the original folder name unchanged!)

No. We have tools as git, GitHub, GitHub spaces and our dev environments to compare and/or revert. It is important for better PRs reviews to be clear about the intended code added/removed

@gjmcn
Copy link
Contributor Author

gjmcn commented Jul 19, 2024

OK, should be cleaner now.

Comment on lines +18 to +24
// type LiteratureListParameter = {
// id: string,
// name: string,
// entity: any, // ADD LATER
// BODY_QUERY: string,
// definition: any, // ADD LATER
// };
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove commented

const DetailsDispatchContext = createContext(null as any);

function literatureReducer(literatureState: LiteratureStateType, action: any) {
console.log(`LITERATURE REDUCER: ${action.type}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove log

loadingEntities: false,
};

const LiteratureContext = createContext(null as any);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the LiteratureStateType

const LiteratureContex = createContext<LiteratureStateType>(initial_state);

};

const LiteratureContext = createContext(null as any);
const LiteratureDispatchContext = createContext(null as any);
Copy link
Contributor

Choose a reason for hiding this comment

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

For typing the actions, you can use the same pattern of AotF FocusState

}

function detailsReducer(detailsState: DetailsStateType, action: any) {
console.log(`DETAILS REDUCER: ${action.type}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove log

Comment on lines +96 to +119
export function useLiterature() {
return useContext(LiteratureContext);
}

export function useLiteratureDispatch() {
return useContext(LiteratureDispatchContext);
}

export function useSelectedCategories() {
const { category } = useLiterature();
return [...category].sort();
}

export function useDisplayedPublications() {
const { page, pageSize, litsIds } = useLiterature();
return isEmpty(litsIds) ? [] : getPage(litsIds, page, pageSize);
}

export function useDetails() {
return useContext(DetailsContext);
}

export function useDetailsDispatch() {
return useContext(DetailsDispatchContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Like this approach. cc: @chinmehta

<Fade in>
<Box mb={2}>
<Skeleton height={60} />
{/* <Box pt="1px"> */}
Copy link
Contributor

Choose a reason for hiding this comment

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

remove comment

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.

2 participants