Skip to content

Commit

Permalink
@uppy/instagram: refactor to ESM (#3696)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored May 11, 2022
1 parent 010a6b1 commit b561116
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 74 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ module.exports = {
'packages/@uppy/form/src/**/*.js',
'packages/@uppy/google-drive/src/**/*.js',
'packages/@uppy/image-editor/src/**/*.js',
'packages/@uppy/instagram/src/**/*.js',
'packages/@uppy/locales/src/**/*.js',
'packages/@uppy/locales/template.js',
'packages/@uppy/progress-bar/src/**/*.js',
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/instagram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "MIT",
"main": "lib/index.js",
"types": "types/index.d.ts",
"type": "module",
"keywords": [
"file uploader",
"uppy",
Expand Down
74 changes: 74 additions & 0 deletions packages/@uppy/instagram/src/Instagram.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { h } from 'preact'

import { UIPlugin } from '@uppy/core'
import { Provider } from '@uppy/companion-client'
import { ProviderViews } from '@uppy/provider-views'

import packageJson from '../package.json'
import locale from './locale.js'

export default class Instagram extends UIPlugin {
static VERSION = packageJson.version

constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'Instagram'
Provider.initPlugin(this, opts)
this.icon = () => (
<svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
<g fill="none" fillRule="evenodd">
<rect className="uppy-ProviderIconBg" fill="#E1306C" width="32" height="32" rx="16" />
<path d="M16 8.622c2.403 0 2.688.009 3.637.052.877.04 1.354.187 1.67.31.392.144.745.374 1.036.673.299.29.529.644.673 1.035.123.317.27.794.31 1.671.043.95.052 1.234.052 3.637s-.009 2.688-.052 3.637c-.04.877-.187 1.354-.31 1.671a2.98 2.98 0 0 1-1.708 1.708c-.317.123-.794.27-1.671.31-.95.043-1.234.053-3.637.053s-2.688-.01-3.637-.053c-.877-.04-1.354-.187-1.671-.31a2.788 2.788 0 0 1-1.035-.673 2.788 2.788 0 0 1-.673-1.035c-.123-.317-.27-.794-.31-1.671-.043-.949-.052-1.234-.052-3.637s.009-2.688.052-3.637c.04-.877.187-1.354.31-1.67.144-.392.374-.745.673-1.036.29-.299.644-.529 1.035-.673.317-.123.794-.27 1.671-.31.95-.043 1.234-.052 3.637-.052zM16 7c-2.444 0-2.75.01-3.71.054-.959.044-1.613.196-2.185.419-.6.225-1.145.58-1.594 1.038-.458.45-.813.993-1.039 1.594-.222.572-.374 1.226-.418 2.184C7.01 13.25 7 13.556 7 16s.01 2.75.054 3.71c.044.959.196 1.613.419 2.185.226.6.58 1.145 1.038 1.594.45.458.993.813 1.594 1.038.572.223 1.227.375 2.184.419.96.044 1.267.054 3.711.054s2.75-.01 3.71-.054c.959-.044 1.613-.196 2.185-.419a4.602 4.602 0 0 0 2.632-2.632c.223-.572.375-1.226.419-2.184.044-.96.054-1.267.054-3.711s-.01-2.75-.054-3.71c-.044-.959-.196-1.613-.419-2.185A4.412 4.412 0 0 0 23.49 8.51a4.412 4.412 0 0 0-1.594-1.039c-.572-.222-1.226-.374-2.184-.418C18.75 7.01 18.444 7 16 7zm0 4.5a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9zm0 7.421a2.921 2.921 0 1 1 0-5.842 2.921 2.921 0 0 1 0 5.842zm4.875-6.671a1.125 1.125 0 1 1 0-2.25 1.125 1.125 0 0 1 0 2.25z" fill="#FFF" />
</g>
</svg>
)

this.defaultLocale = locale

this.i18nInit()
this.title = this.i18n('pluginNameInstagram')

this.provider = new Provider(uppy, {
companionUrl: this.opts.companionUrl,
companionHeaders: this.opts.companionHeaders,
companionKeysParams: this.opts.companionKeysParams,
companionCookiesRule: this.opts.companionCookiesRule,
provider: 'instagram',
pluginId: this.id,
})

this.onFirstRender = this.onFirstRender.bind(this)
this.render = this.render.bind(this)
}

install () {
this.view = new ProviderViews(this, {
provider: this.provider,
viewType: 'grid',
showTitles: false,
showFilter: false,
showBreadcrumbs: false,
})

const { target } = this.opts
if (target) {
this.mount(target, this)
}
}

uninstall () {
this.view.tearDown()
this.unmount()
}

onFirstRender () {
return Promise.all([
this.provider.fetchPreAuthToken(),
this.view.getFolder('recent'),
])
}

render (state) {
return this.view.render(state)
}
}
73 changes: 1 addition & 72 deletions packages/@uppy/instagram/src/index.js
Original file line number Diff line number Diff line change
@@ -1,72 +1 @@
const { UIPlugin } = require('@uppy/core')
const { Provider } = require('@uppy/companion-client')
const { ProviderViews } = require('@uppy/provider-views')
const { h } = require('preact')

const locale = require('./locale.js')

module.exports = class Instagram extends UIPlugin {
static VERSION = require('../package.json').version

constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'Instagram'
Provider.initPlugin(this, opts)
this.icon = () => (
<svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
<g fill="none" fillRule="evenodd">
<rect className="uppy-ProviderIconBg" fill="#E1306C" width="32" height="32" rx="16" />
<path d="M16 8.622c2.403 0 2.688.009 3.637.052.877.04 1.354.187 1.67.31.392.144.745.374 1.036.673.299.29.529.644.673 1.035.123.317.27.794.31 1.671.043.95.052 1.234.052 3.637s-.009 2.688-.052 3.637c-.04.877-.187 1.354-.31 1.671a2.98 2.98 0 0 1-1.708 1.708c-.317.123-.794.27-1.671.31-.95.043-1.234.053-3.637.053s-2.688-.01-3.637-.053c-.877-.04-1.354-.187-1.671-.31a2.788 2.788 0 0 1-1.035-.673 2.788 2.788 0 0 1-.673-1.035c-.123-.317-.27-.794-.31-1.671-.043-.949-.052-1.234-.052-3.637s.009-2.688.052-3.637c.04-.877.187-1.354.31-1.67.144-.392.374-.745.673-1.036.29-.299.644-.529 1.035-.673.317-.123.794-.27 1.671-.31.95-.043 1.234-.052 3.637-.052zM16 7c-2.444 0-2.75.01-3.71.054-.959.044-1.613.196-2.185.419-.6.225-1.145.58-1.594 1.038-.458.45-.813.993-1.039 1.594-.222.572-.374 1.226-.418 2.184C7.01 13.25 7 13.556 7 16s.01 2.75.054 3.71c.044.959.196 1.613.419 2.185.226.6.58 1.145 1.038 1.594.45.458.993.813 1.594 1.038.572.223 1.227.375 2.184.419.96.044 1.267.054 3.711.054s2.75-.01 3.71-.054c.959-.044 1.613-.196 2.185-.419a4.602 4.602 0 0 0 2.632-2.632c.223-.572.375-1.226.419-2.184.044-.96.054-1.267.054-3.711s-.01-2.75-.054-3.71c-.044-.959-.196-1.613-.419-2.185A4.412 4.412 0 0 0 23.49 8.51a4.412 4.412 0 0 0-1.594-1.039c-.572-.222-1.226-.374-2.184-.418C18.75 7.01 18.444 7 16 7zm0 4.5a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9zm0 7.421a2.921 2.921 0 1 1 0-5.842 2.921 2.921 0 0 1 0 5.842zm4.875-6.671a1.125 1.125 0 1 1 0-2.25 1.125 1.125 0 0 1 0 2.25z" fill="#FFF" />
</g>
</svg>
)

this.defaultLocale = locale

this.i18nInit()
this.title = this.i18n('pluginNameInstagram')

this.provider = new Provider(uppy, {
companionUrl: this.opts.companionUrl,
companionHeaders: this.opts.companionHeaders,
companionKeysParams: this.opts.companionKeysParams,
companionCookiesRule: this.opts.companionCookiesRule,
provider: 'instagram',
pluginId: this.id,
})

this.onFirstRender = this.onFirstRender.bind(this)
this.render = this.render.bind(this)
}

install () {
this.view = new ProviderViews(this, {
provider: this.provider,
viewType: 'grid',
showTitles: false,
showFilter: false,
showBreadcrumbs: false,
})

const { target } = this.opts
if (target) {
this.mount(target, this)
}
}

uninstall () {
this.view.tearDown()
this.unmount()
}

onFirstRender () {
return Promise.all([
this.provider.fetchPreAuthToken(),
this.view.getFolder('recent'),
])
}

render (state) {
return this.view.render(state)
}
}
export { default } from './Instagram.jsx'
2 changes: 1 addition & 1 deletion packages/@uppy/instagram/src/locale.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
strings: {
pluginNameInstagram: 'Instagram',
},
Expand Down
2 changes: 1 addition & 1 deletion website/src/docs/instagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ This option correlates to the [RequestCredentials value](https://developer.mozil
<!-- eslint-disable no-restricted-globals, no-multiple-empty-lines -->

```js
module.exports = {
export default {
strings: {
pluginNameInstagram: 'Instagram',
},
Expand Down

0 comments on commit b561116

Please sign in to comment.