Skip to content

Commit

Permalink
Emulate image upload (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krakabek and danil.radkovskyi authored May 10, 2024
1 parent 26d83bb commit 87b66e5
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 52 deletions.
90 changes: 45 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
"@codemirror/lint": "6.5.0",
"@codemirror/state": "6.4.1",
"@codemirror/view": "6.26.3",
"@devvit/previews": "0.10.20-next-2024-05-01-553651f2f.0",
"@devvit/protos": "0.10.20-next-2024-05-01-553651f2f.0",
"@devvit/public-api": "0.10.20-next-2024-05-01-553651f2f.0",
"@devvit/runtime-lite": "0.10.20-next-2024-05-01-553651f2f.0",
"@devvit/shared-types": "0.10.20-next-2024-05-01-553651f2f.0",
"@devvit/ui-renderer": "0.10.20-next-2024-05-01-553651f2f.0",
"@devvit/previews": "0.10.20",
"@devvit/protos": "0.10.20",
"@devvit/public-api": "0.10.20",
"@devvit/runtime-lite": "0.10.20",
"@devvit/shared-types": "0.10.20",
"@devvit/ui-renderer": "0.10.20",
"@esm-bundle/chai": "4.3.4-fix.0",
"@types/jsdom": "21.1.6",
"@types/mocha": "10.0.6",
Expand Down Expand Up @@ -117,7 +117,8 @@
"test:types:ui": "lit-analyzer --maxWarnings=0 --rules.no-invalid-css=off --rules.no-missing-element-type-definition --rules.no-unknown-event --rules.no-unknown-attribute=false --strict",
"test:ui": "wtr --config=tools/web-test-runner.config.js",
"test:unit": "vitest --config=tools/vitest.config.ts run",
"version": "npm test"
"version": "npm test",
"install:npmjs": "npm install --registry=https://registry.npmjs.org"
},
"type": "module",
"types": "dist/index.d.ts",
Expand Down
24 changes: 24 additions & 0 deletions src/elements/play-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export class PlayPreview extends LitElement {
?use-experimental-blocks=${this.useExperimentalBlocks}
?use-ui-request=${this.useUIRequest}
@devvit-ui-error=${() => (this._err = true)}
@devvit-image-upload=${mockImageUpload}
></devvit-preview>
`
: nothing}
Expand All @@ -170,3 +171,26 @@ export class PlayPreview extends LitElement {
)
}
}

const mockImageUpload = (
event: CustomEvent<{
blob: Blob
uploadRequest: Promise<UploadResponse> | null
}>
): void => {
event.detail.uploadRequest = new Promise(resolve => {
setTimeout(() => {
resolve({
url: 'https://i.redd.it/m04iwd26jbpc1.png',
mediaId: 'm04iwd26jbpc1'
// error:'Whoops!' // uncomment to emulate the error response
})
}, 2000)
})
}

type UploadResponse = {
url?: string
mediaId?: string
error?: string
}

0 comments on commit 87b66e5

Please sign in to comment.