aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshpuld <shp@cock.li>2019-04-01 22:41:34 +0300
committershpuld <shp@cock.li>2019-04-01 22:41:34 +0300
commit2879495b8ab16a07d337965871e951f660fc1815 (patch)
treee5a9242aa0dfce948110dd670ad6aea88bce382d
parentc06bcf3303d89aa44ddcdad3a9d2f723303ae3d1 (diff)
remove window width copypasta
-rw-r--r--src/App.js7
-rw-r--r--src/boot/after_store.js4
-rw-r--r--src/services/window_utils/window_utils.js5
3 files changed, 11 insertions, 5 deletions
diff --git a/src/App.js b/src/App.js
index 96954e72..46145b16 100644
--- a/src/App.js
+++ b/src/App.js
@@ -10,6 +10,7 @@ import MediaModal from './components/media_modal/media_modal.vue'
import SideDrawer from './components/side_drawer/side_drawer.vue'
import MobilePostStatusModal from './components/mobile_post_status_modal/mobile_post_status_modal.vue'
import MobileNav from './components/mobile_nav/mobile_nav.vue'
+import { windowWidth } from './services/window_utils/window_utils'
export default {
name: 'app',
@@ -102,10 +103,10 @@ export default {
this.finderHidden = hidden
},
updateMobileState () {
- const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
- const changed = width <= 800 !== this.isMobileLayout
+ const mobileLayout = windowWidth() <= 800
+ const changed = mobileLayout !== this.isMobileLayout
if (changed) {
- this.$store.dispatch('setMobileLayout', width <= 800)
+ this.$store.dispatch('setMobileLayout', mobileLayout)
}
}
}
diff --git a/src/boot/after_store.js b/src/boot/after_store.js
index f86a65e3..e03b7f27 100644
--- a/src/boot/after_store.js
+++ b/src/boot/after_store.js
@@ -1,8 +1,8 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
-
import App from '../App.vue'
+import { windowWidth } from '../services/window_utils/window_utils'
const getStatusnetConfig = async ({ store }) => {
try {
@@ -230,7 +230,7 @@ const afterStoreSetup = async ({ store, i18n }) => {
})
}
- const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
+ const width = windowWidth()
store.dispatch('setMobileLayout', width <= 800)
const apiConfig = await getStatusnetConfig({ store })
diff --git a/src/services/window_utils/window_utils.js b/src/services/window_utils/window_utils.js
new file mode 100644
index 00000000..faff6cb9
--- /dev/null
+++ b/src/services/window_utils/window_utils.js
@@ -0,0 +1,5 @@
+
+export const windowWidth = () =>
+ window.innerWidth ||
+ document.documentElement.clientWidth ||
+ document.body.clientWidth