1- import { SimpleGrid } from '@mantine/core' ;
1+ import { MantineTransition , SimpleGrid , Transition } from '@mantine/core' ;
22import PouchDB from 'pouchdb-browser' ;
3- import { Suspense , useEffect , useState } from 'react' ;
3+ import { useEffect , useState } from 'react' ;
44import { useParams } from 'react-router-dom' ;
5- import Loading from '../../common/Loading' ;
65import { CENTER_INDEX } from '../../common/constants' ;
76import ShortcutType from '../../common/enums/ShortcutType' ;
87import {
@@ -17,9 +16,19 @@ import Container from './shortcuts/Container';
1716import Hotkey from './shortcuts/Hotkey' ;
1817import Script from './shortcuts/Script' ;
1918
19+ // prettier-ignore
20+ const TRANSITIONS = [
21+ 'pop-bottom-right' , 'fade-up' , 'pop-bottom-left' ,
22+ 'fade-left' , /* 'fade', */ 'fade-right' ,
23+ 'pop-top-right' , 'fade-down' , 'pop-top-left' ,
24+ ] as MantineTransition [ ] ;
25+ const TRANSITION_DURATION = 250 ;
26+ const TRANSITION_EASING = 'ease-in' ;
27+
2028export default function StageProvider ( ) {
2129 const { id : stageID } = useParams < { id ?: string } > ( ) ;
2230 const [ shortcuts , setShortcuts ] = useState < Shortcut [ ] > ( [ ] ) ;
31+ const [ mounted , setMounted ] = useState ( false ) ;
2332
2433 const loadStage = async ( id : string ) => {
2534 setShortcuts ( [ ] ) ;
@@ -31,47 +40,86 @@ export default function StageProvider() {
3140 } ;
3241
3342 useEffect ( ( ) => {
43+ setMounted ( false ) ;
44+
3445 ( async ( ) => {
3546 if ( ! stageID ) return ;
3647 await loadStage ( stageID ) ;
3748 } ) ( ) ;
49+
50+ setTimeout ( ( ) => {
51+ setMounted ( true ) ;
52+ } , 10 ) ;
3853 } , [ stageID ] ) ;
3954
4055 return (
41- < Suspense fallback = { < Loading /> } >
42- < SimpleGrid cols = { 3 } >
43- { shortcuts . flatMap ( ( shortcut , index ) => {
44- const elements = [ ] ;
45- if ( index === CENTER_INDEX ) {
46- elements . push ( < Back key = "x" /> ) ;
47- }
48- if ( shortcut . type === ShortcutType . EMPTY ) {
49- elements . push ( < div key = { shortcut . position } /> ) ;
50- } else if ( shortcut . type === ShortcutType . CONTAINER ) {
51- elements . push (
52- < Container
53- key = { shortcut . position }
54- item = { shortcut as ContainerShortcut }
55- /> ,
56- ) ;
57- } else if ( shortcut . type === ShortcutType . SCRIPT ) {
58- elements . push (
59- < Script
60- key = { shortcut . position }
61- item = { shortcut as ScriptShortcut }
62- /> ,
63- ) ;
64- } else if ( shortcut . type === ShortcutType . HOTKEY ) {
65- elements . push (
66- < Hotkey
67- key = { shortcut . position }
68- item = { shortcut as HotkeyShortcut }
69- /> ,
70- ) ;
71- }
72- return elements ;
73- } ) }
74- </ SimpleGrid >
75- </ Suspense >
56+ < SimpleGrid cols = { 3 } h = "100%" p = "xs" >
57+ { shortcuts . flatMap ( ( shortcut , index ) => {
58+ const elements = [ ] ;
59+ if ( index === CENTER_INDEX ) {
60+ elements . push (
61+ < Transition
62+ key = "x"
63+ transition = "fade"
64+ duration = { TRANSITION_DURATION }
65+ timingFunction = { TRANSITION_EASING }
66+ enterDelay = { TRANSITION_DURATION / 3 }
67+ mounted = { mounted }
68+ >
69+ { ( styles ) => < Back style = { styles } /> }
70+ </ Transition > ,
71+ ) ;
72+ }
73+ if ( shortcut . type === ShortcutType . EMPTY ) {
74+ elements . push ( < div key = { shortcut . position } /> ) ;
75+ } else if ( shortcut . type === ShortcutType . CONTAINER ) {
76+ elements . push (
77+ < Transition
78+ key = { shortcut . position }
79+ transition = { TRANSITIONS [ index ] }
80+ duration = { TRANSITION_DURATION }
81+ timingFunction = { TRANSITION_EASING }
82+ mounted = { mounted }
83+ >
84+ { ( styles ) => (
85+ < Container
86+ item = { shortcut as ContainerShortcut }
87+ style = { styles }
88+ />
89+ ) }
90+ </ Transition > ,
91+ ) ;
92+ } else if ( shortcut . type === ShortcutType . SCRIPT ) {
93+ elements . push (
94+ < Transition
95+ key = { shortcut . position }
96+ transition = { TRANSITIONS [ index ] }
97+ duration = { TRANSITION_DURATION }
98+ mounted = { mounted }
99+ timingFunction = { TRANSITION_EASING }
100+ >
101+ { ( styles ) => (
102+ < Script item = { shortcut as ScriptShortcut } style = { styles } />
103+ ) }
104+ </ Transition > ,
105+ ) ;
106+ } else if ( shortcut . type === ShortcutType . HOTKEY ) {
107+ elements . push (
108+ < Transition
109+ key = { shortcut . position }
110+ transition = { TRANSITIONS [ index ] }
111+ duration = { TRANSITION_DURATION }
112+ mounted = { mounted }
113+ timingFunction = { TRANSITION_EASING }
114+ >
115+ { ( styles ) => (
116+ < Hotkey item = { shortcut as HotkeyShortcut } style = { styles } />
117+ ) }
118+ </ Transition > ,
119+ ) ;
120+ }
121+ return elements ;
122+ } ) }
123+ </ SimpleGrid >
76124 ) ;
77125}
0 commit comments