Skip to content

Commit

Permalink
ExpressPOC: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ddascal committed Dec 13, 2023
1 parent e45979e commit 63b6337
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 9 deletions.
9 changes: 8 additions & 1 deletion web-src/src/components/ApplicationProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React, {
} from 'react';
import { useSetRecoilState } from 'recoil';
import { FirefallService } from '../services/FirefallService.js';
import { ExpressSDKService } from '../services/ExpressSDKService.js';
import actions from '../config.json';
import { useShellContext } from './ShellProvider.js';
import { loadPromptTemplates, promptTemplatesState } from '../state/PromptTemplatesState.js';
Expand Down Expand Up @@ -59,6 +60,11 @@ export const ApplicationProvider = ({ children }) => {

const websiteUrl = getWebsiteUrl();
const promptTemplatesPath = getPromptTemplatesPath();
const expressSDKService = new ExpressSDKService({
// TODO: replace with our own client ID
clientId: 'aem-genai-assistant',
appName: 'Partner Days Embed SDK Demo',
});

setApplication({
appVersion: APP_VERSION,
Expand All @@ -70,6 +76,7 @@ export const ApplicationProvider = ({ children }) => {
imsOrg: user.imsOrg,
accessToken: user.imsToken,
}),
expressSDKService,
});

loadPromptTemplates(websiteUrl, promptTemplatesPath).then((templates) => {
Expand All @@ -82,7 +89,7 @@ export const ApplicationProvider = ({ children }) => {
}, [user, done, setApplication]);

if (!application) {
return <Fragment/>;
return <Fragment />;
}

return (
Expand Down
41 changes: 33 additions & 8 deletions web-src/src/components/MainSidePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,32 @@ import { sessionState } from '../state/SessionState.js';
import { ViewType, viewTypeState } from '../state/ViewType.js';

export function MainSidePanel(props) {
const { appVersion } = useApplicationContext();
const { appVersion, expressSDKService } = useApplicationContext();
const sessions = useRecoilValue(sessionHistoryState);
const [currentSession, setCurrentSession] = useRecoilState(sessionState);
const [viewType, setViewType] = useRecoilState(viewTypeState);

let ccEverywhereInstance = null;

const createDesign = async () => {
if (ccEverywhereInstance == null) {
ccEverywhereInstance = await expressSDKService.initExpressEditor();
}
ccEverywhereInstance.createDesign(
// CreateDesignParams
{
outputParams: {
outputType: 'base64',
},
inputParams: {
templateType: 'brochure',
// You can also load an image into the project
// asset : "..."
},
},
);
};

const style = {
headerText: css`
font-size: 18px;
Expand Down Expand Up @@ -109,34 +130,38 @@ export function MainSidePanel(props) {

<Flex direction={'column'} gridArea={'menu'} gap={'size-100'}>
<ul className={style.menu}>
<li className={viewType === ViewType.CurrentSession ? derivedStyle.clickedMenuItem : style.menuItem}>
<Image src={PromptsIcon} width={'20px'} alt={'*New - Adobe Express'} />
<Link href="#" UNSAFE_className={style.menuItemLink} onPress={() => createDesign()}>*New - Adobe Express</Link>
</li>
<li className={viewType === ViewType.NewSession ? derivedStyle.clickedMenuItem : style.menuItem}>
<Image src={PromptsIcon} width={'20px'} alt={'New prompt template'}/>
<Image src={PromptsIcon} width={'20px'} alt={'New prompt template'} />
<Link href="#" UNSAFE_className={style.menuItemLink} onPress={() => setViewType(ViewType.NewSession)}>Prompt Templates</Link>
</li>
<li className={viewType === ViewType.Favorites ? derivedStyle.clickedMenuItem : style.menuItem}>
<Image src={FavoritesIcon} width={'20px'} alt={'Favorites'}/>
<Image src={FavoritesIcon} width={'20px'} alt={'Favorites'} />
<Link href="#" UNSAFE_className={style.menuItemLink} onPress={() => setViewType(ViewType.Favorites)}>Favorites</Link>
</li>
<li className={style.menuItem}>
<Image src={RecentsIcon} width={'20px'} alt={'Recents'}/>
<Image src={RecentsIcon} width={'20px'} alt={'Recents'} />
<Text>Recents</Text>
</li>
{ (sessions && sessions.length > 0) && sessions.map((session) => (
{(sessions && sessions.length > 0) && sessions.map((session) => (
// eslint-disable-next-line max-len
<li className={currentSession && viewType === ViewType.CurrentSession && session && session.id === currentSession.id ? derivedStyle.clickedSubMenuItem : style.subMenuItem} key={session.id}>
<Link href="#" UNSAFE_className={style.menuItemLink} onPress={() => handleRecent(session)}>{session.name}</Link>
</li>
)) }
))}
</ul>
</Flex>

<Flex direction={'column'} gridArea={'footer'} gap={'16px'}>
<Flex direction={'row'} justifyContent={'start'} alignItems={'center'} gap={'12px'}>
<Image src={HelpIcon} width={'20px'} alt={'Help'}/>
<Image src={HelpIcon} width={'20px'} alt={'Help'} />
<Link href="https://www.aem.live/docs/sidekick-generate-variations" target="_blank" UNSAFE_className={style.menu}>Help & FAQ</Link>
</Flex>
<Flex direction={'row'} justifyContent={'start'} alignItems={'center'} gap={'12px'}>
<Image src={FileTxt} width={'20px'} alt={'Guidelines'}/>
<Image src={FileTxt} width={'20px'} alt={'Guidelines'} />
<Link href={USER_GUIDELINES_URL} target="_blank" UNSAFE_className={style.menu}>User Guidelines</Link>
</Flex>
<Text UNSAFE_className={style.copyright}>Copyright © 2023 Adobe. All rights reserved</Text>
Expand Down
50 changes: 50 additions & 0 deletions web-src/src/services/ExpressSDKService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
export class ExpressSDKService {
CDN_URL = 'https://sdk.cc-embed.adobe.com/v3/CCEverywhere.js';

constructor({
clientId,
appName,
}) {
this.clientId = clientId;
this.appName = appName;
}

async initExpressEditor() {
const loadExpressSDK = (document, url) => {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = url;
script.onload = async () => {
if (!window.CCEverywhere) {
reject(new Error('CCEverywhere SDK not found'));
return;
}
try {
const ccEverywhere = await window.CCEverywhere.initialize({
clientId: this.clientId,
appName: this.appName,
});
resolve(ccEverywhere);
} catch (error) {
reject(error);
}
};
script.onerror = () => reject(new Error('Failed to load CCEverywhere SDK'));
document.body.appendChild(script);
});
};

return loadExpressSDK(document, this.CDN_URL);
}
}

0 comments on commit 63b6337

Please sign in to comment.