Skip to content

Commit

Permalink
fix: setter to have better understandable params
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabhag8848 committed Aug 19, 2024
1 parent e39b6c4 commit 396faf9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,16 @@ export const useLastVisitedPageOrView = () => {
}
};

const setLastVisitedObjectOrView = (
{
objectMetadataId,
viewId,
}: {
objectMetadataId: string;
viewId: string;
},
isSlug = false,
) => {
const fallbackObjectMetadataId = isSlug
? (findActiveObjectMetadataItemBySlug(objectMetadataId)?.id ?? '')
: objectMetadataId;
const setLastVisitedObjectOrView = ({
componentId,
viewId,
}: {
componentId: string;
viewId: string;
}) => {
const fallbackObjectMetadataId =
findActiveObjectMetadataItemBySlug(componentId)?.id ?? '';

const fallbackViewId =
lastVisitedObjectMetadataId === fallbackObjectMetadataId
? viewId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getObjectAndViewIdFromPath = (path: string) => {
}

return {
objectMetadataId: result[1],
componentId: result[1],
viewId: result[2],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,11 @@ export const NavigationDrawerItem = ({
if (isNonEmptyString(to)) {
const objectAndViewId = getObjectAndViewIdFromPath(to);
if (!isEmptyObject(objectAndViewId)) {
const { objectMetadataId, viewId } = objectAndViewId;
setLastVisitedObjectOrView(
{
objectMetadataId,
viewId,
},
true,
);
const { componentId, viewId } = objectAndViewId;
setLastVisitedObjectOrView({
componentId,
viewId,
});
}
navigate(to);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,10 @@ export const ViewPickerListContent = () => {
const { setLastVisitedObjectOrView } = useLastVisitedPageOrView();

const handleViewSelect = (viewId: string) => {
setLastVisitedObjectOrView(
{
objectMetadataId: componentId,
viewId,
},
true,
);
setLastVisitedObjectOrView({
componentId,
viewId,
});
selectView(viewId);
closeDropdown();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ export const useViewPickerPersistView = () => {
});
closeAndResetViewPicker();
selectView(id);
setLastVisitedObjectOrView(
{
objectMetadataId: componentId,
viewId: id,
},
true,
);
setLastVisitedObjectOrView({
componentId,
viewId: id,
});
},
[
closeAndResetViewPicker,
Expand Down Expand Up @@ -93,13 +90,10 @@ export const useViewPickerPersistView = () => {
viewA.key === 'INDEX' ? -1 : viewA.position - viewB.position,
)
.filter((view) => view.id !== viewPickerReferenceViewId);
setLastVisitedObjectOrView(
{
objectMetadataId: componentId,
viewId: indexOrFirstView.id,
},
true,
);
setLastVisitedObjectOrView({
componentId,
viewId: indexOrFirstView.id,
});
},
[
closeAndResetViewPicker,
Expand Down

0 comments on commit 396faf9

Please sign in to comment.