Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 9247b88

Browse files
committed
updated boxes example
1 parent 2f9cc10 commit 9247b88

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
export type Props = { height: number };
4+
5+
const Spacer: React.FC<Props> = (props) => {
6+
const height = props.height ?? 100; // '??' because props.height can also be 0 and 0 is false
7+
8+
return <div style={{ height: height }} />;
9+
};
10+
11+
export default Spacer;

examples/react/release/boxes/src/core/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { Agile, assignSharedAgileInstance } from '@agile-ts/core';
22
import { assignSharedAgileLoggerConfig, Logger } from '@agile-ts/logger';
33

44
assignSharedAgileLoggerConfig({ level: Logger.level.WARN });
5-
export const App = new Agile();
5+
export const App = new Agile({ key: 'boxes', bucket: true });
66
assignSharedAgileInstance(App);

examples/react/release/boxes/src/core/entities/ui/ui.actions.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import {
77
ELEMENTS,
88
} from './ui.controller';
99
import core from '../../index';
10+
import { copy } from '@agile-ts/utils';
1011

1112
export const addDefaultElement = (image: boolean = false) => {
1213
if (image) addElement(defaultElementStyle, getRandomImage());
1314
else addElement(defaultElementStyle);
1415
};
1516

16-
export const addElement = (
17+
export const addElement = async (
1718
style: ElementStyleInterface,
1819
image?: ElementImageInterface,
1920
select = true
@@ -24,7 +25,13 @@ export const addElement = (
2425
style,
2526
image,
2627
});
27-
if (select) selectElement(id);
28+
29+
if (select) {
30+
// TODO figure out why this timeout is needed
31+
// (otherwise it won't select the Element initially)
32+
await new Promise((resolve) => setTimeout(resolve, 10));
33+
selectElement(id);
34+
}
2835
};
2936

3037
export const selectElement = (id: string | number) => {
@@ -133,9 +140,10 @@ export const updateElementY = (id: string | number, y: number) => {
133140
export const applyImageDimensions = async (id: string | number) => {
134141
const element = ELEMENTS.getItem(id);
135142
if (element && element.value.image?.src) {
136-
element.nextStateValue.style.size = await core.ui.getImageDimensions(
143+
const newDimensions = await core.ui.getImageDimensions(
137144
element.value.image.src
138145
);
146+
element.nextStateValue.style.size = newDimensions;
139147
element.ingest();
140148
}
141149
};

examples/react/release/boxes/src/screens/Canvas/components/EditProperties/components/ImageInfo/components/Info.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import React from 'react';
22
import styled from 'styled-components';
33

4-
const Info = ({ label, value }: { label: string; value?: string }) => {
4+
type InfoProps = {
5+
label: string;
6+
value?: string;
7+
};
8+
9+
const Info: React.FC<InfoProps> = (props) => {
10+
const { label, value } = props;
11+
512
return (
613
<Container>
714
<Title>{label}</Title>
@@ -14,6 +21,7 @@ export default Info;
1421

1522
const Container = styled.div`
1623
max-width: 175px;
24+
overflow-wrap: break-word;
1725
`;
1826

1927
const Title = styled.div`

examples/react/release/boxes/src/screens/Canvas/components/EditProperties/components/ImageInfo/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useProxy } from '@agile-ts/react';
44
import core from '../../../../../../core';
55
import Info from './components/Info';
66
import styled from 'styled-components';
7+
import Spacer from '../../../../../../components/Spacer';
78

89
type ImageInfoProps = {
910
fallback?: boolean;
@@ -29,8 +30,19 @@ const ImageInfo: React.FC<ImageInfoProps> = (props) => {
2930

3031
return (
3132
<Container>
32-
<Info label="Author" value={imageInfo?.author} />
33-
<Info label="Image URL" value={imageInfo?.url} />
33+
{!fallback ? (
34+
<>
35+
<Info label="Author" value={imageInfo?.author} />
36+
<Spacer height={10} />
37+
<Info label="Image URL" value={imageInfo?.url} />
38+
</>
39+
) : (
40+
<>
41+
<Info label="Author" value={'Failed to load'} />
42+
<Spacer height={10} />
43+
<Info label="Image URL" value={'Failed to load'} />
44+
</>
45+
)}
3446
</Container>
3547
);
3648
};

0 commit comments

Comments
 (0)