Skip to content

Commit

Permalink
chore: Handle Express SDK initialization errors (#210)
Browse files Browse the repository at this point in the history
* chore: Handle Express SDK intialization errors

* chore: Code cleanup
  • Loading branch information
askayastha22 committed Feb 23, 2024
1 parent 903f7de commit 8d45134
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 6 additions & 2 deletions web-src/src/components/FavoriteVariantCard.js
Expand Up @@ -59,7 +59,7 @@ export function FavoriteVariantCard({ variant, ...props }) {
addImageToVariant(variant.id, publishParams.asset[0].data);
};

await expressSDKService.handleImageOperation(
const success = await expressSDKService.handleImageOperation(
'generateImage',
{
outputParams: {
Expand All @@ -73,6 +73,10 @@ export function FavoriteVariantCard({ variant, ...props }) {
},
},
);

if (!success) {
ToastQueue.negative('Something went wrong. Please try again!', { timeout: 2000 });
}
}, [expressSDKService, variant]);

const handleGenerateImagePrompt = useCallback(() => {
Expand Down Expand Up @@ -106,7 +110,7 @@ export function FavoriteVariantCard({ variant, ...props }) {
log('prompt:copyfavorite');
sampleRUM('genai:prompt:copyfavorite', { source: 'FavoriteCard#onPress' });
navigator.clipboard.writeText(toText(variant.content));
ToastQueue.positive('Copied to clipboard', { timeout: 1000 });
ToastQueue.positive('Copied text to clipboard', { timeout: 1000 });
}}>
<CopyOutlineIcon />
</ActionButton>
Expand Down
6 changes: 5 additions & 1 deletion web-src/src/components/PromptResultCard.js
Expand Up @@ -199,7 +199,7 @@ export function PromptResultCard({ result, ...props }) {
addImageToVariant(variantId, publishParams.asset[0].data);
};

await expressSDKService.handleImageOperation(
const success = await expressSDKService.handleImageOperation(
'generateImage',
{
outputParams: {
Expand All @@ -213,6 +213,10 @@ export function PromptResultCard({ result, ...props }) {
},
},
);

if (!success) {
ToastQueue.negative('Something went wrong. Please try again!', { timeout: 2000 });
}
}, [expressSDKService]);

const handleGenerateImagePrompt = useCallback((variantId) => {
Expand Down
6 changes: 5 additions & 1 deletion web-src/src/components/VariantImagesView.js
Expand Up @@ -90,7 +90,7 @@ export function VariantImagesView({ variant, isFavorite, ...props }) {
};
const assetData = variantImages[variant.id][index];

await expressSDKService.handleImageOperation(
const success = await expressSDKService.handleImageOperation(
'editImage',
{
outputParams: {
Expand All @@ -108,6 +108,10 @@ export function VariantImagesView({ variant, isFavorite, ...props }) {
},
},
);

if (!success) {
ToastQueue.negative('Something went wrong. Please try again!', { timeout: 2000 });
}
}, [expressSDKService, variantImages]);

const handleImageViewerOpen = useCallback((index) => {
Expand Down
10 changes: 9 additions & 1 deletion web-src/src/services/ExpressSDKService.js
Expand Up @@ -72,13 +72,21 @@ export class ExpressSDKService {

async handleImageOperation(operation, operationParams) {
if (this.ccEverywhereInstance == null) {
this.ccEverywhereInstance = await this.initExpressEditor();
await this.initExpressEditor()
.then((ccEverywhereInstance) => {
this.ccEverywhereInstance = ccEverywhereInstance;
})
.catch((error) => {
console.error('Error:', error);
return false;
});
}

if (operation === 'generateImage') {
this.ccEverywhereInstance.miniEditor.createImageFromText(operationParams, this.userInfo, this.authInfo);
} else if (operation === 'editImage') {
this.ccEverywhereInstance.miniEditor.editImage(operationParams, this.userInfo, this.authInfo);
}
return true;
}
}

0 comments on commit 8d45134

Please sign in to comment.