Facebook.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { UIPlugin } from '@uppy/core'
  2. import { Provider } from '@uppy/companion-client'
  3. import { ProviderViews } from '@uppy/provider-views'
  4. import { h } from 'preact'
  5. import packageJson from '../package.json'
  6. import locale from './locale.js'
  7. export default class Facebook extends UIPlugin {
  8. static VERSION = packageJson.version
  9. constructor (uppy, opts) {
  10. super(uppy, opts)
  11. this.id = this.opts.id || 'Facebook'
  12. Provider.initPlugin(this, opts)
  13. this.title = this.opts.title || 'Facebook'
  14. this.icon = () => (
  15. <svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
  16. <g fill="none" fillRule="evenodd">
  17. <path d="M27 16c0-6.075-4.925-11-11-11S5 9.925 5 16c0 5.49 4.023 10.041 9.281 10.866V19.18h-2.793V16h2.793v-2.423c0-2.757 1.642-4.28 4.155-4.28 1.204 0 2.462.215 2.462.215v2.707h-1.387c-1.366 0-1.792.848-1.792 1.718V16h3.05l-.487 3.18h-2.563v7.686C22.977 26.041 27 21.49 27 16" fill="#1777F2" />
  18. <path d="M20.282 19.18L20.77 16h-3.051v-2.063c0-.87.426-1.718 1.792-1.718h1.387V9.512s-1.258-.215-2.462-.215c-2.513 0-4.155 1.523-4.155 4.28V16h-2.793v3.18h2.793v7.686a11.082 11.082 0 003.438 0V19.18h2.563" fill="#FFFFFE" />
  19. </g>
  20. </svg>
  21. )
  22. this.provider = new Provider(uppy, {
  23. companionUrl: this.opts.companionUrl,
  24. companionHeaders: this.opts.companionHeaders,
  25. companionKeysParams: this.opts.companionKeysParams,
  26. companionCookiesRule: this.opts.companionCookiesRule,
  27. provider: 'facebook',
  28. pluginId: this.id,
  29. })
  30. this.defaultLocale = locale
  31. this.i18nInit()
  32. this.title = this.i18n('pluginNameFacebook')
  33. this.onFirstRender = this.onFirstRender.bind(this)
  34. this.render = this.render.bind(this)
  35. }
  36. install () {
  37. this.view = new ProviderViews(this, {
  38. provider: this.provider,
  39. })
  40. const { target } = this.opts
  41. if (target) {
  42. this.mount(target, this)
  43. }
  44. }
  45. uninstall () {
  46. this.view.tearDown()
  47. this.unmount()
  48. }
  49. onFirstRender () {
  50. return Promise.all([
  51. this.provider.fetchPreAuthToken(),
  52. this.view.getFolder(),
  53. ])
  54. }
  55. render (state) {
  56. const viewOptions = {}
  57. if (this.getPluginState().files.length && !this.getPluginState().folders.length) {
  58. viewOptions.viewType = 'grid'
  59. viewOptions.showFilter = false
  60. viewOptions.showTitles = false
  61. }
  62. return this.view.render(state, viewOptions)
  63. }
  64. }