diff options
| -rw-r--r-- | gui/src/renderer/components/TransitionContainer.tsx | 6 | ||||
| -rw-r--r-- | gui/src/renderer/lib/transition-rule.ts | 42 | ||||
| -rw-r--r-- | gui/src/renderer/transitions.ts | 116 | ||||
| -rw-r--r-- | gui/test/transition-rule.spec.ts | 57 |
4 files changed, 3 insertions, 218 deletions
diff --git a/gui/src/renderer/components/TransitionContainer.tsx b/gui/src/renderer/components/TransitionContainer.tsx index 5e12acbb56..1d177319c2 100644 --- a/gui/src/renderer/components/TransitionContainer.tsx +++ b/gui/src/renderer/components/TransitionContainer.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import styled from 'styled-components'; -import { ITransitionGroupProps } from '../transitions'; +import { ITransitionSpecification } from '../lib/history'; interface ITransitioningViewProps { viewId: string; @@ -10,10 +10,10 @@ type TransitioningView = React.ReactElement<ITransitioningViewProps>; interface ITransitionQueueItem { view: TransitioningView; - transition: ITransitionGroupProps; + transition: ITransitionSpecification; } -interface IProps extends ITransitionGroupProps { +interface IProps extends ITransitionSpecification { children: TransitioningView; onTransitionEnd: () => void; } diff --git a/gui/src/renderer/lib/transition-rule.ts b/gui/src/renderer/lib/transition-rule.ts deleted file mode 100644 index 91d5cd6d4c..0000000000 --- a/gui/src/renderer/lib/transition-rule.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Action } from 'history'; - -export interface ITransitionDescriptor { - name: string; - duration: number; -} - -export interface ITransitionFork { - forward: ITransitionDescriptor; - backward: ITransitionDescriptor; -} - -export interface ITransitionMatch { - direction: 'forward' | 'backward'; - descriptor: ITransitionDescriptor; -} - -export default class TransitionRule { - constructor(private from: string | null, private to: string, private fork: ITransitionFork) {} - - public match( - fromRoute: string | null, - toRoute: string, - action?: Action, - ): ITransitionMatch | null { - if (action !== 'POP' && (!this.from || this.from === fromRoute) && this.to === toRoute) { - return { - direction: 'forward', - descriptor: this.fork.forward, - }; - } - - if (action !== 'PUSH' && (!this.from || this.from === toRoute) && this.to === fromRoute) { - return { - direction: 'backward', - descriptor: this.fork.backward, - }; - } - - return null; - } -} diff --git a/gui/src/renderer/transitions.ts b/gui/src/renderer/transitions.ts deleted file mode 100644 index cddf8c57a2..0000000000 --- a/gui/src/renderer/transitions.ts +++ /dev/null @@ -1,116 +0,0 @@ -import { Action } from 'history'; -import TransitionRule, { ITransitionDescriptor, ITransitionFork } from './lib/transition-rule'; - -export interface ITransitionGroupProps { - name: string; - duration: number; -} - -interface ITransitionMap { - [name: string]: ITransitionFork; -} - -/** - * Transition descriptors - */ -const transitions: ITransitionMap = { - slide: { - forward: { - name: 'slide-up', - duration: 450, - }, - backward: { - name: 'slide-down', - duration: 450, - }, - }, - push: { - forward: { - name: 'push', - duration: 450, - }, - backward: { - name: 'pop', - duration: 450, - }, - }, -}; - -/** - * Transition rules - * (null) is used to indicate any route. - */ -const transitionRules = [ - r('/settings', '/settings/language', transitions.push), - r('/settings', '/settings/account', transitions.push), - r('/settings', '/settings/preferences', transitions.push), - r('/settings', '/settings/advanced', transitions.push), - r('/settings/advanced', '/settings/advanced/wireguard-keys', transitions.push), - r('/settings/advanced', '/settings/advanced/linux-split-tunneling', transitions.push), - r('/settings', '/settings/support', transitions.push), - r('/main', '/main/voucher/redeem', transitions.push), - r('/main/voucher/redeem', '/main/voucher/success', transitions.push), - r('/main/voucher/success', '/main/setup-finished', transitions.push), - r('/main/voucher/success', '/main', transitions.push), - r('/main/time-added', '/main/setup-finished', transitions.push), - r('/main/time-added', '/main', transitions.push), - r('/main', '/main/time-added', transitions.push), - r('/main/setup-finished', '/main', transitions.push), - r(null, '/settings', transitions.slide), - r(null, '/select-location', transitions.slide), -]; - -/** - * Calculate TransitionGroup props. - * - * @param {string} [fromRoute] - source route - * @param {string} toRoute - target route - */ -export function getTransitionProps( - fromRoute: string | null, - toRoute: string, - action?: Action, -): ITransitionGroupProps { - // ignore initial transition and transition between the same routes - if (!fromRoute || fromRoute === toRoute) { - return noTransitionProps(); - } - - for (const rule of transitionRules) { - const match = rule.match(fromRoute, toRoute, action); - if (match) { - return toTransitionGroupProps(match.descriptor); - } - } - - return noTransitionProps(); -} - -/** - * Integrate ITransitionDescriptor into ITransitionGroupProps - * @param {ITransitionDescriptor} descriptor - */ -function toTransitionGroupProps(descriptor: ITransitionDescriptor): ITransitionGroupProps { - const { name, duration } = descriptor; - return { - name, - duration, - }; -} - -/** - * Returns default props with no animation - */ -function noTransitionProps(): ITransitionGroupProps { - return { - name: '', - duration: 0, - }; -} - -/** - * Shortcut to create TransitionRule - */ -function r(from: string | null, to: string, fork: ITransitionFork): TransitionRule { - return new TransitionRule(from, to, fork); -} diff --git a/gui/test/transition-rule.spec.ts b/gui/test/transition-rule.spec.ts deleted file mode 100644 index 6896370d21..0000000000 --- a/gui/test/transition-rule.spec.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { expect } from 'chai'; -import { it, describe } from 'mocha'; -import TransitionRule from '../src/renderer/lib/transition-rule'; - -describe('TransitionRule', () => { - const testTransition = { - forward: { name: 'forward', duration: 0.25 }, - backward: { name: 'backward', duration: 0.25 }, - }; - - it('should match wildcard rule', () => { - const rule = new TransitionRule(null, '/route', testTransition); - - expect(rule.match(null, '/route')).to.deep.equal({ - direction: 'forward', - descriptor: { name: 'forward', duration: 0.25 }, - }); - - expect(rule.match('/somewhere', '/route')).to.deep.equal({ - direction: 'forward', - descriptor: { name: 'forward', duration: 0.25 }, - }); - }); - - it('should match wildcard rule reversion', () => { - const rule = new TransitionRule(null, '/route', testTransition); - - expect(rule.match('/route', '/other')).to.deep.equal({ - direction: 'backward', - descriptor: { name: 'backward', duration: 0.25 }, - }); - }); - - it('should match exact rule', () => { - const rule = new TransitionRule('/route1', '/route2', testTransition); - - expect(rule.match('/other', '/route1')).to.be.null; - expect(rule.match('/other', '/route2')).to.be.null; - - expect(rule.match('/route1', '/route2')).to.deep.equal({ - direction: 'forward', - descriptor: { name: 'forward', duration: 0.25 }, - }); - }); - - it('should match exact rule reversion', () => { - const rule = new TransitionRule('/route1', '/route2', testTransition); - - expect(rule.match('/route1', '/other')).to.be.null; - expect(rule.match('/route2', '/other')).to.be.null; - - expect(rule.match('/route2', '/route1')).to.deep.equal({ - direction: 'backward', - descriptor: { name: 'backward', duration: 0.25 }, - }); - }); -}); |
