@@ -31,6 +31,7 @@ import {
31
31
extractUrls ,
32
32
replaceUrlsWithAnchorTags ,
33
33
} from '../utils/url-to-link' ;
34
+ import { getAspectRatio , getInitialView , isBrowser , isMinWidth } from '../utils/view-size' ;
34
35
35
36
function Calendar ( ) {
36
37
const calendarRef = createRef ( ) ;
@@ -40,28 +41,18 @@ function Calendar() {
40
41
const [ clickedEvent , setClickedEvent ] = useState ( [ ] ) ;
41
42
const [ showEventDetails , setShowEventDetails ] = useState ( false ) ;
42
43
const [ eventDetails , setEventDetails ] = useState ( false ) ;
43
- const [ aspectRatio , setAspectRatio ] = useState (
44
- window . outerWidth > window . innerHeight
45
- ? 1.35
46
- : window . innerWidth / window . innerHeight
47
- ) ;
48
- const [ initialView , setInitialView ] = useState (
49
- window . outerWidth > 600 ? 'dayGridMonth' : 'timeGridWeek'
50
- ) ;
44
+ const [ aspectRatio , setAspectRatio ] = useState ( getAspectRatio ( ) ) ;
45
+ const [ initialView , setInitialView ] = useState ( getInitialView ( ) ) ;
51
46
52
47
useEscKey ( ( ) => setShowEventDetails ( false ) ) ;
53
48
54
49
const [ popupPosition , setPopupPosition ] = useState ( { } ) ;
55
50
56
51
const windowResize = ( ) => {
57
- setAspectRatio (
58
- window . outerWidth > window . innerHeight
59
- ? 1.35
60
- : window . innerWidth / window . innerHeight
61
- ) ;
62
- setInitialView ( window . outerWidth > 600 ? 'dayGridMonth' : 'timeGridWeek' ) ;
52
+ setAspectRatio ( getAspectRatio ( ) ) ;
53
+ setInitialView ( isMinWidth ( ) ? 'dayGridMonth' : 'timeGridWeek' ) ;
63
54
setShowEventDetails ( false ) ;
64
- window . outerWidth < 600 && setPopupPosition ( { left : 0 , top : 0 } ) ;
55
+ ! isMinWidth ( ) && setPopupPosition ( { left : 0 , top : 0 } ) ;
65
56
} ;
66
57
67
58
const createPopupPosition = ( event ) => {
@@ -85,7 +76,7 @@ function Calendar() {
85
76
86
77
const handleEventClick = useCallback (
87
78
( clickInfo ) => {
88
- window . outerWidth > 600 && createPopupPosition ( clickInfo . jsEvent ) ;
79
+ isMinWidth ( ) && createPopupPosition ( clickInfo . jsEvent ) ;
89
80
setEventDetails ( clickInfo . event ) ;
90
81
setShowEventDetails ( true ) ;
91
82
if ( clickedEvent . length ) {
@@ -165,8 +156,6 @@ function Calendar() {
165
156
< Icon path = { mdiClose } size = { 1 } />
166
157
</ button >
167
158
</ div >
168
-
169
- { /* <div>{seriesICS}</div> */ }
170
159
< h2 className = "event-title" > { eventDetails . title } </ h2 >
171
160
< div className = "event-time" >
172
161
< div className = "icon" >
0 commit comments