Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix: widget align system issues (#124)
Browse files Browse the repository at this point in the history
* fix: inner section disappearing

* fix published
  • Loading branch information
KaWaite committed Nov 11, 2021
1 parent 886302f commit 3bc9faf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export default function MobileZone({
children,
}: PropsWithChildren<Props>) {
const filteredSections = useMemo(() => {
return sections.filter(s => !!zone?.[s]);
}, [zone]);
return sections.filter(s => !!zone?.[s] || (s === "center" && children));
}, [zone, children]);

const [pos, setPos] = useState(filteredSections.indexOf("center"));
const [pos, setPos] = useState(filteredSections.length === 3 ? 1 : 0);
const publishedTheme = usePublishTheme(sceneProperty.theme);

return (
Expand Down
22 changes: 12 additions & 10 deletions src/components/molecules/Visualizer/WidgetAlignSystem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,18 @@ const WidgetAlignSystem: React.FC<Props> = ({
isEditable={isEditable}
isBuilt={isBuilt}
layoutConstraint={layoutConstraint}>
<ZoneComponent
zoneName="inner"
zone={alignSystem?.inner}
sceneProperty={sceneProperty}
pluginProperty={pluginProperty}
pluginBaseUrl={pluginBaseUrl}
isEditable={isEditable}
isBuilt={isBuilt}
layoutConstraint={layoutConstraint}
/>
{alignSystem?.inner && (
<ZoneComponent
zoneName="inner"
zone={alignSystem?.inner}
sceneProperty={sceneProperty}
pluginProperty={pluginProperty}
pluginBaseUrl={pluginBaseUrl}
isEditable={isEditable}
isBuilt={isBuilt}
layoutConstraint={layoutConstraint}
/>
)}
</MobileZone>
) : (
<ZoneComponent
Expand Down
12 changes: 8 additions & 4 deletions src/components/organisms/EarthEditor/CanvasArea/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,15 @@ export const convertWidgets = (
}),
);

const widgetZone = (zone?: Maybe<WidgetZoneType>): WidgetZone => {
const widgetZone = (zone?: Maybe<WidgetZoneType>): WidgetZone | undefined => {
const left = widgetSection(zone?.left);
const center = widgetSection(zone?.center);
const right = widgetSection(zone?.right);
if (!left && !center && !right) return;
return {
left: widgetSection(zone?.left),
center: widgetSection(zone?.center),
right: widgetSection(zone?.right),
left,
center,
right,
};
};

Expand Down
28 changes: 19 additions & 9 deletions src/components/organisms/Published/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,38 @@ export default (alias?: string) => {
);

const widgetZone = (zone?: WidgetZone | null) => {
const left = widgetSection(zone?.left);
const center = widgetSection(zone?.center);
const right = widgetSection(zone?.right);
if (!left && !center && !right) return;
return {
left: widgetSection(zone?.left),
center: widgetSection(zone?.center),
right: widgetSection(zone?.right),
left,
center,
right,
};
};

const widgetSection = (section?: WidgetSection | null) => {
const top = widgetArea(section?.top);
const middle = widgetArea(section?.middle);
const bottom = widgetArea(section?.bottom);
if (!top && !middle && !bottom) return;
return {
top: widgetArea(section?.top),
middle: widgetArea(section?.middle),
bottom: widgetArea(section?.bottom),
top,
middle,
bottom,
};
};

const widgetArea = (area?: WidgetArea | null) => {
const align = area?.align.toLowerCase() as Alignment | undefined;
const areaWidgets: Widget[] | undefined = area?.widgetIds
.map<Widget | undefined>(w => widgets?.find(w2 => w === w2.id))
.filter((w): w is Widget => !!w);
if (!areaWidgets || areaWidgets.length < 1) return;
return {
align: align ?? "start",
widgets: area?.widgetIds
.map<Widget | undefined>(w => widgets.find(w2 => w === w2.id))
.filter((w): w is Widget => !!w),
widgets: areaWidgets,
};
};

Expand Down

0 comments on commit 3bc9faf

Please sign in to comment.