Skip to content

Commit

Permalink
fix: handle new data format from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Jun 27, 2024
1 parent ad23d30 commit 9b684ab
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/components/SiteProperty/SiteProperty.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ const SiteProperty = ({
...imageProps
}) => {
const site = useSelector((state) => state.site.data); //loaded by asyncPropExtender from volto

const subsite = useSelector((state) => state.subsite?.data); //if you have volto-subsites installed
const currentLang = useSelector((state) => state.intl.locale);

const hasSubsite =
subsite && Object.entries(subsite).length && subsite.constructor === Object;

const property_name = getParent ? 'parent_' + property : property;

let site_property =
Expand All @@ -41,14 +45,24 @@ const SiteProperty = ({

let value = site_property ?? defaultValue ?? defaultFromConfig;

if (subsite && getParent) {
value = site?.['plone.' + property] ?? defaultValue ?? defaultFromConfig;
}

switch (property) {
case 'site_title':
if (subsite) {
if (value.constructor === Object) {
value = value[currentLang] || value.default;
}
if (hasSubsite && !getParent) {
value = subsite?.title ?? value;
}
break;
case 'site_subtitle':
if (subsite) {
if (value.constructor === Object) {
value = value[currentLang] || '';
}
if (hasSubsite && !getParent) {
value = subsite?.description ?? value;
}
break;
Expand Down Expand Up @@ -106,10 +120,6 @@ const SiteProperty = ({
break;
}

if (subsite && getParent) {
value = site?.['plone.' + property] ?? defaultValue ?? defaultFromConfig;
}

if (forceValue) {
value = forceValue;
}
Expand Down

0 comments on commit 9b684ab

Please sign in to comment.