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 (3392B)


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