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

feat: add flag to make additional call optional #41

Draft
wants to merge 1 commit into
base: 11.x.x
Choose a base branch
from
Draft
Changes from all commits
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
41 changes: 24 additions & 17 deletions src/components/ItaliaTheme/View/Commons/VenuesSmall.jsx
Original file line number Diff line number Diff line change
@@ -25,26 +25,28 @@ const messages = defineMessages({
* @params {object} location: object.
* @returns {string} Markup of the component.
*/
const Location = ({ location, show_icon }) => {
const Location = ({ location, show_icon, retrieve_data }) => {
const intl = useIntl();
const url = flattenToAppURL(location['@id']);
const key = `luogo${url}`;
let location_fo = location;
if (retrieve_data) {
const locationContent = useSelector(
(state) => state.content.subrequests?.[key],
);
const loaded = locationContent?.loading || locationContent?.loaded;
const dispatch = useDispatch();

const locationContent = useSelector(
(state) => state.content.subrequests?.[key],
);
const loaded = locationContent?.loading || locationContent?.loaded;
const dispatch = useDispatch();

useEffect(() => {
if (!loaded) {
dispatch(getContent(url, null, key));
}
return () => dispatch(resetContent(key));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [url]);
useEffect(() => {
if (!loaded) {
dispatch(getContent(url, null, key));
}
return () => dispatch(resetContent(key));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [url]);

let location_fo = locationContent?.data;
location_fo = locationContent?.data;
}

return location_fo ? (
<div className="card card-teaser shadow mt-3 rounded">
@@ -86,11 +88,16 @@ const Location = ({ location, show_icon }) => {
* @params {object} content: Content object.
* @returns {string} Markup of the component.
*/
const VenuesSmall = ({ venues, show_icon }) => {
const VenuesSmall = ({ venues, show_icon, retrieve_data = true }) => {
return venues ? (
<div className="card-wrapper card-teaser-wrapper">
{venues.map((item, i) => (
<Location key={item['@id']} location={item} show_icon={show_icon} />
<Location
key={item['@id']}
location={item}
show_icon={show_icon}
retrieve_data={retrieve_data}
/>
))}
</div>
) : null;