logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

mobile_post_status_button.js (3334B)


  1. import { debounce } from 'lodash'
  2. import { library } from '@fortawesome/fontawesome-svg-core'
  3. import {
  4. faPen
  5. } from '@fortawesome/free-solid-svg-icons'
  6. library.add(
  7. faPen
  8. )
  9. const HIDDEN_FOR_PAGES = new Set([
  10. 'chats',
  11. 'chat',
  12. 'lists-edit'
  13. ])
  14. const MobilePostStatusButton = {
  15. data () {
  16. return {
  17. hidden: false,
  18. scrollingDown: false,
  19. inputActive: false,
  20. oldScrollPos: 0,
  21. amountScrolled: 0
  22. }
  23. },
  24. created () {
  25. if (this.autohideFloatingPostButton) {
  26. this.activateFloatingPostButtonAutohide()
  27. }
  28. window.addEventListener('resize', this.handleOSK)
  29. },
  30. unmounted () {
  31. if (this.autohideFloatingPostButton) {
  32. this.deactivateFloatingPostButtonAutohide()
  33. }
  34. window.removeEventListener('resize', this.handleOSK)
  35. },
  36. computed: {
  37. isLoggedIn () {
  38. return !!this.$store.state.users.currentUser
  39. },
  40. isHidden () {
  41. if (HIDDEN_FOR_PAGES.has(this.$route.name)) { return true }
  42. return this.autohideFloatingPostButton && (this.hidden || this.inputActive)
  43. },
  44. isPersistent () {
  45. return !!this.$store.getters.mergedConfig.alwaysShowNewPostButton
  46. },
  47. autohideFloatingPostButton () {
  48. return !!this.$store.getters.mergedConfig.autohideFloatingPostButton
  49. }
  50. },
  51. watch: {
  52. autohideFloatingPostButton: function (isEnabled) {
  53. if (isEnabled) {
  54. this.activateFloatingPostButtonAutohide()
  55. } else {
  56. this.deactivateFloatingPostButtonAutohide()
  57. }
  58. }
  59. },
  60. methods: {
  61. activateFloatingPostButtonAutohide () {
  62. window.addEventListener('scroll', this.handleScrollStart)
  63. window.addEventListener('scroll', this.handleScrollEnd)
  64. },
  65. deactivateFloatingPostButtonAutohide () {
  66. window.removeEventListener('scroll', this.handleScrollStart)
  67. window.removeEventListener('scroll', this.handleScrollEnd)
  68. },
  69. openPostForm () {
  70. this.$store.dispatch('openPostStatusModal')
  71. },
  72. handleOSK () {
  73. // This is a big hack: we're guessing from changed window sizes if the
  74. // on-screen keyboard is active or not. This is only really important
  75. // for phones in portrait mode and it's more important to show the button
  76. // in normal scenarios on all phones, than it is to hide it when the
  77. // keyboard is active.
  78. // Guesswork based on https://www.mydevice.io/#compare-devices
  79. // for example, iphone 4 and android phones from the same time period
  80. const smallPhone = window.innerWidth < 350
  81. const smallPhoneKbOpen = smallPhone && window.innerHeight < 345
  82. const biggerPhone = !smallPhone && window.innerWidth < 450
  83. const biggerPhoneKbOpen = biggerPhone && window.innerHeight < 560
  84. if (smallPhoneKbOpen || biggerPhoneKbOpen) {
  85. this.inputActive = true
  86. } else {
  87. this.inputActive = false
  88. }
  89. },
  90. handleScrollStart: debounce(function () {
  91. if (window.scrollY > this.oldScrollPos) {
  92. this.hidden = true
  93. } else {
  94. this.hidden = false
  95. }
  96. this.oldScrollPos = window.scrollY
  97. }, 100, { leading: true, trailing: false }),
  98. handleScrollEnd: debounce(function () {
  99. this.hidden = false
  100. this.oldScrollPos = window.scrollY
  101. }, 100, { leading: false, trailing: true })
  102. }
  103. }
  104. export default MobilePostStatusButton