Skip to content

Commit

Permalink
Fixing prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
david-shibley-contentful committed Sep 4, 2024
1 parent a4693a6 commit 2341086
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 47 deletions.
2 changes: 1 addition & 1 deletion examples/stateful-sidebar-with-dialog/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (process.env.NODE_ENV === 'development' && window.self === window.top) {
root.render(
<SDKProvider>
<GlobalStyles />
<App />
<App />
</SDKProvider>
);
}
37 changes: 22 additions & 15 deletions examples/stateful-sidebar-with-dialog/src/locations/Dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { reducer } from '../model/reducerAndInitialSidebarState';

const Dialog = () => {
const sdk = useSDK();
const { serializedSidebarState } = (sdk.parameters.invocation || {});
const { serializedSidebarState } = sdk.parameters.invocation || {};
const [state, dispatch] = useReducer(reducer, {});
/*
To use the cma, inject it as follows.
Expand All @@ -20,20 +20,27 @@ const Dialog = () => {
});
}, []);

return <>
<Paragraph>Hello Dialog Component (AppId: {sdk.ids.app})</Paragraph>
<Paragraph>{`Time is ${state.timestamp}`}</Paragraph>
<Button onClick={() => {
dispatch({
type: 'SET_TIME',
payload: new Date().toString(),
});
}}>SET TIME</Button>
<Button
onClick={() => {
sdk.close(JSON.stringify(state));
}}>CLOSE</Button>
</>;
return (
<>
<Paragraph>Hello Dialog Component (AppId: {sdk.ids.app})</Paragraph>
<Paragraph>{`Time is ${state.timestamp}`}</Paragraph>
<Button
onClick={() => {
dispatch({
type: 'SET_TIME',
payload: new Date().toString(),
});
}}>
SET TIME
</Button>
<Button
onClick={() => {
sdk.close(JSON.stringify(state));
}}>
CLOSE
</Button>
</>
);
};

export default Dialog;
62 changes: 35 additions & 27 deletions examples/stateful-sidebar-with-dialog/src/locations/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,41 @@ const Sidebar = () => {

const someParameter = 'some parameter';

return <>
<Paragraph>Hello Sidebar Component (AppId: {sdk.ids.app})</Paragraph>
<Paragraph>{`Time is ${state.timestamp}`}</Paragraph>
<Button onClick={() => {
dispatch({
type: 'SET_TIME',
payload: new Date().toString(),
});
}}>SET TIME</Button>
<Button onClick={async () => {
const serializedDialogState = await sdk.dialogs.openCurrentApp({
shouldCloseOnEscapePress: false,
shouldCloseOnOverlayClick: false,
title: 'Dialog',
minHeight: 360,
parameters: {
serializedSidebarState: JSON.stringify(state),
},
});
if (serializedDialogState) {
dispatch({
type: 'SET_WHOLE_STATE',
payload: JSON.parse(serializedDialogState),
});
}
}}>OPEN DIALOG</Button>
</>;
return (
<>
<Paragraph>Hello Sidebar Component (AppId: {sdk.ids.app})</Paragraph>
<Paragraph>{`Time is ${state.timestamp}`}</Paragraph>
<Button
onClick={() => {
dispatch({
type: 'SET_TIME',
payload: new Date().toString(),
});
}}>
SET TIME
</Button>
<Button
onClick={async () => {
const serializedDialogState = await sdk.dialogs.openCurrentApp({
shouldCloseOnEscapePress: false,
shouldCloseOnOverlayClick: false,
title: 'Dialog',
minHeight: 360,
parameters: {
serializedSidebarState: JSON.stringify(state),
},
});
if (serializedDialogState) {
dispatch({
type: 'SET_WHOLE_STATE',
payload: JSON.parse(serializedDialogState),
});
}
}}>
OPEN DIALOG
</Button>
</>
);
};

export default Sidebar;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


export function reducer(state, { type, payload }) {
if (type === 'SET_TIME') {
return {
Expand All @@ -16,6 +14,6 @@ export function reducer(state, { type, payload }) {

export function initialSidebarState() {
return {
timestamp: 'SET ME!'
timestamp: 'SET ME!',
};
}
}

0 comments on commit 2341086

Please sign in to comment.