@@ -25,7 +25,6 @@ import {
2525 useMediaQuery ,
2626 useTheme ,
2727} from '@mui/material' ;
28- import { createSlice , PayloadAction } from '@reduxjs/toolkit' ;
2928import { clamp , throttle } from 'lodash' ;
3029import React , {
3130 createContext ,
@@ -43,6 +42,7 @@ import { useHotkeys } from 'react-hotkeys-hook';
4342import { Trans , useTranslation } from 'react-i18next' ;
4443import { useTypedSelector } from '../../redux/hooks' ;
4544import store from '../../redux/stores/store' ;
45+ import { activitySlice } from './activitySlice' ;
4646
4747const areWindowsEnabled = false ;
4848
@@ -74,97 +74,6 @@ export interface Activity {
7474 cluster ?: string ;
7575}
7676
77- export interface ActivityState {
78- /** History of opened activites, list of IDs */
79- history : string [ ] ;
80- /** Map of all open activities, key is the ID */
81- activities : Record < string , Activity > ;
82- }
83-
84- const initialState : ActivityState = {
85- history : [ ] ,
86- activities : { } ,
87- } ;
88-
89- export const activitySlice = createSlice ( {
90- name : 'activity' ,
91- initialState,
92- reducers : {
93- launchActivity ( state , action : PayloadAction < Activity > ) {
94- // Add to history
95- if ( ! action . payload . minimized ) {
96- state . history = state . history . filter ( it => it !== action . payload . id ) ;
97- state . history . push ( action . payload . id ) ;
98- }
99-
100- // Close other temporary tabs
101- Object . values ( state . activities ) . forEach ( activity => {
102- if ( activity . temporary ) {
103- delete state . activities [ activity . id ] ;
104- state . history = state . history . filter ( it => it !== activity . id ) ;
105- }
106- } ) ;
107-
108- if ( ! state . activities [ action . payload . id ] ) {
109- // New activity, add it to the state
110- state . activities [ action . payload . id ] = action . payload ;
111- } else {
112- // Existing activity, un-minimize it
113- state . activities [ action . payload . id ] . minimized = false ;
114- }
115-
116- // Make it fullscreen on small windows
117- if ( window . innerWidth < 1280 ) {
118- state . activities [ action . payload . id ] = {
119- ...state . activities [ action . payload . id ] ,
120- location : 'full' ,
121- } ;
122- }
123-
124- // Dispatch resize event so the content adjusts
125- // 200ms delay for animations
126- setTimeout ( ( ) => {
127- window ?. dispatchEvent ?.( new Event ( 'resize' ) ) ;
128- } , 200 ) ;
129- } ,
130- close ( state , action : PayloadAction < string > ) {
131- // Remove the activity from history
132- state . history = state . history . filter ( it => it !== action . payload ) ;
133- // Remove from state
134- delete state . activities [ action . payload ] ;
135- } ,
136- update ( state , action : PayloadAction < Partial < Activity > & { id : string } > ) {
137- // Bump this activity in history
138- if ( ! action . payload . minimized ) {
139- state . history = state . history . filter ( it => it !== action . payload . id ) ;
140- state . history . push ( action . payload . id ) ;
141- }
142-
143- // Remove from history it it's minimized
144- if ( action . payload . minimized ) {
145- state . history = state . history . filter ( it => it !== action . payload . id ) ;
146- }
147-
148- // Update the state
149- state . activities [ action . payload . id ] = {
150- ...state . activities [ action . payload . id ] ,
151- ...action . payload ,
152- } ;
153-
154- // Dispatch resize event so the content adjusts
155- // 200ms delay for animations
156- setTimeout ( ( ) => {
157- window ?. dispatchEvent ?.( new Event ( 'resize' ) ) ;
158- } , 200 ) ;
159- } ,
160- reset ( ) {
161- return initialState ;
162- } ,
163- } ,
164- } ) ;
165-
166- export const activityReducer = activitySlice . reducer ;
167-
16877export const Activity = {
16978 /** Launches new Activity */
17079 launch ( activity : Activity ) {
0 commit comments