Skip to content

Commit af0b5ae

Browse files
committed
chore: add isMobile ref to the corestore
1 parent b918e69 commit af0b5ae

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

adminforth/spa/src/stores/core.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref, computed } from 'vue'
1+
import { ref, computed, onMounted, onUnmounted } from 'vue'
22
import { defineStore } from 'pinia'
33
import { callAdminForthApi } from '@/utils';
44
import websocket from '@/websocket';
@@ -21,6 +21,19 @@ export const useCoreStore = defineStore('core', () => {
2121
const userData: Ref<UserData | null> = ref(null);
2222
const isResourceFetching = ref(false);
2323
const isInternetError = ref(false);
24+
const screenWidth = ref(window.innerWidth);
25+
26+
onMounted(() => {
27+
window.addEventListener('resize', updateWidth);
28+
});
29+
onUnmounted(() => {
30+
window.removeEventListener('resize', updateWidth);
31+
});
32+
33+
const isMobile = computed(() => screenWidth.value <= 768);
34+
const updateWidth = () => {
35+
screenWidth.value = window.innerWidth
36+
}
2437

2538
const resourceColumnsWithFilters = computed(() => {
2639
if (!resource.value) {
@@ -261,5 +274,6 @@ export const useCoreStore = defineStore('core', () => {
261274
isResourceFetching,
262275
isIos,
263276
isInternetError,
277+
isMobile,
264278
}
265279
})

0 commit comments

Comments
 (0)