You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

comments-tab.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. // eslint-disable-next-line n/no-missing-import, import/no-unresolved
  23. import MessageReplyText from '@mdi/svg/svg/message-reply-text.svg?raw'
  24. import { getRequestToken } from '@nextcloud/auth'
  25. import { loadState } from '@nextcloud/initial-state'
  26. import { registerCommentsPlugins } from './comments-activity-tab.ts'
  27. // @ts-expect-error __webpack_nonce__ is injected by webpack
  28. __webpack_nonce__ = btoa(getRequestToken())
  29. if (loadState('comments', 'activityEnabled', false) && OCA?.Activity?.registerSidebarAction !== undefined) {
  30. // Do not mount own tab but mount into activity
  31. window.addEventListener('DOMContentLoaded', function() {
  32. registerCommentsPlugins()
  33. })
  34. } else {
  35. // Init Comments tab component
  36. let TabInstance = null
  37. const commentTab = new OCA.Files.Sidebar.Tab({
  38. id: 'comments',
  39. name: t('comments', 'Comments'),
  40. iconSvg: MessageReplyText,
  41. async mount(el, fileInfo, context) {
  42. if (TabInstance) {
  43. TabInstance.$destroy()
  44. }
  45. TabInstance = new OCA.Comments.View('files', {
  46. // Better integration with vue parent component
  47. parent: context,
  48. propsData: {
  49. resourceId: fileInfo.id,
  50. },
  51. })
  52. // Only mount after we have all the info we need
  53. await TabInstance.update(fileInfo.id)
  54. TabInstance.$mount(el)
  55. },
  56. update(fileInfo) {
  57. TabInstance.update(fileInfo.id)
  58. },
  59. destroy() {
  60. TabInstance.$destroy()
  61. TabInstance = null
  62. },
  63. scrollBottomReached() {
  64. TabInstance.onScrollBottomReached()
  65. },
  66. })
  67. window.addEventListener('DOMContentLoaded', function() {
  68. if (OCA.Files && OCA.Files.Sidebar) {
  69. OCA.Files.Sidebar.registerTab(commentTab)
  70. }
  71. })
  72. }