You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			125 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			TypeScript
		
	
		
		
			
		
	
	
			125 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			TypeScript
		
	
| 
											5 years ago
										 | import React from 'react'; | ||
|  | import { Provider } from 'react-redux'; | ||
|  | import { bindActionCreators } from 'redux'; | ||
| 
											4 years ago
										 | import { LeftPane } from './leftpane/LeftPane'; | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | // tslint:disable-next-line: no-submodule-imports
 | ||
| 
											4 years ago
										 | import { PersistGate } from 'redux-persist/integration/react'; | ||
|  | import { persistStore } from 'redux-persist'; | ||
| 
											4 years ago
										 | import { getConversationController } from '../session/conversations'; | ||
|  | import { UserUtils } from '../session/utils'; | ||
|  | import { initialCallState } from '../state/ducks/call'; | ||
|  | import { | ||
|  |   actions as conversationActions, | ||
|  |   getEmptyConversationState, | ||
|  |   openConversationWithMessages, | ||
|  | } from '../state/ducks/conversations'; | ||
|  | import { initialDefaultRoomState } from '../state/ducks/defaultRooms'; | ||
|  | import { initialModalState } from '../state/ducks/modalDialog'; | ||
|  | import { initialOnionPathState } from '../state/ducks/onion'; | ||
|  | import { initialSearchState } from '../state/ducks/search'; | ||
|  | import { initialSectionState } from '../state/ducks/section'; | ||
|  | import { getEmptyStagedAttachmentsState } from '../state/ducks/stagedAttachments'; | ||
|  | import { initialThemeState } from '../state/ducks/theme'; | ||
|  | import { TimerOptionsArray } from '../state/ducks/timerOptions'; | ||
|  | import { initialUserConfigState } from '../state/ducks/userConfig'; | ||
|  | import { StateType } from '../state/reducer'; | ||
|  | import { makeLookup } from '../util'; | ||
|  | import { SessionMainPanel } from './SessionMainPanel'; | ||
|  | import { createStore } from '../state/createStore'; | ||
| 
											4 years ago
										 | 
 | ||
| 
											5 years ago
										 | // Workaround: A react component's required properties are filtering up through connect()
 | ||
|  | //   https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31363
 | ||
|  | 
 | ||
|  | type State = { | ||
|  |   isInitialLoadComplete: boolean; | ||
|  | }; | ||
|  | 
 | ||
| 
											5 years ago
										 | export class SessionInboxView extends React.Component<any, State> { | ||
| 
											5 years ago
										 |   private store: any; | ||
|  | 
 | ||
|  |   constructor(props: any) { | ||
|  |     super(props); | ||
|  |     this.state = { | ||
|  |       isInitialLoadComplete: false, | ||
|  |     }; | ||
| 
											4 years ago
										 |   } | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 |   public componentDidMount() { | ||
|  |     this.setupLeftPane(); | ||
| 
											5 years ago
										 |   } | ||
| 
											5 years ago
										 | 
 | ||
| 
											5 years ago
										 |   public render() { | ||
|  |     if (!this.state.isInitialLoadComplete) { | ||
| 
											4 years ago
										 |       return null; | ||
| 
											5 years ago
										 |     } | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 |     const persistor = persistStore(this.store); | ||
| 
											4 years ago
										 |     window.persistStore = persistor; | ||
| 
											4 years ago
										 | 
 | ||
| 
											5 years ago
										 |     return ( | ||
|  |       <Provider store={this.store}> | ||
| 
											4 years ago
										 |         <PersistGate loading={null} persistor={persistor}> | ||
|  |           <div className="gutter"> | ||
|  |             <div className="network-status-container" /> | ||
|  |             {this.renderLeftPane()} | ||
|  |           </div> | ||
|  |           <SessionMainPanel /> | ||
|  |         </PersistGate> | ||
| 
											5 years ago
										 |       </Provider> | ||
|  |     ); | ||
|  |   } | ||
| 
											5 years ago
										 | 
 | ||
|  |   private renderLeftPane() { | ||
| 
											4 years ago
										 |     return <LeftPane />; | ||
| 
											5 years ago
										 |   } | ||
|  | 
 | ||
| 
											4 years ago
										 |   private setupLeftPane() { | ||
| 
											5 years ago
										 |     // Here we set up a full redux store with initial state for our LeftPane Root
 | ||
| 
											4 years ago
										 |     const conversations = getConversationController() | ||
|  |       .getConversations() | ||
|  |       .map(conversation => conversation.getConversationModelProps()); | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 |     const timerOptions: TimerOptionsArray = window.Whisper.ExpirationTimerOptions.map( | ||
|  |       (item: any) => ({ | ||
|  |         name: item.getName(), | ||
|  |         value: item.get('seconds'), | ||
|  |       }) | ||
|  |     ); | ||
|  | 
 | ||
| 
											4 years ago
										 |     const initialState: StateType = { | ||
| 
											5 years ago
										 |       conversations: { | ||
| 
											4 years ago
										 |         ...getEmptyConversationState(), | ||
| 
											4 years ago
										 |         conversationLookup: makeLookup(conversations, 'id'), | ||
| 
											5 years ago
										 |       }, | ||
|  |       user: { | ||
| 
											5 years ago
										 |         ourNumber: UserUtils.getOurPubKeyStrFromCache(), | ||
| 
											5 years ago
										 |       }, | ||
| 
											4 years ago
										 |       section: initialSectionState, | ||
|  |       defaultRooms: initialDefaultRoomState, | ||
|  |       search: initialSearchState, | ||
|  |       theme: initialThemeState, | ||
|  |       onionPaths: initialOnionPathState, | ||
|  |       modals: initialModalState, | ||
| 
											4 years ago
										 |       userConfig: initialUserConfigState, | ||
| 
											4 years ago
										 |       timerOptions: { | ||
|  |         timerOptions, | ||
|  |       }, | ||
| 
											4 years ago
										 |       stagedAttachments: getEmptyStagedAttachmentsState(), | ||
| 
											4 years ago
										 |       call: initialCallState, | ||
| 
											5 years ago
										 |     }; | ||
|  | 
 | ||
|  |     this.store = createStore(initialState); | ||
|  |     window.inboxStore = this.store; | ||
|  | 
 | ||
|  |     // Enables our redux store to be updated by backbone events in the outside world
 | ||
| 
											5 years ago
										 |     const { messageExpired } = bindActionCreators(conversationActions, this.store.dispatch); | ||
| 
											4 years ago
										 |     window.openConversationWithMessages = openConversationWithMessages; | ||
| 
											5 years ago
										 | 
 | ||
| 
											5 years ago
										 |     // messageExpired is currently inboked fropm js. So we link it to Redux that way
 | ||
| 
											5 years ago
										 |     window.Whisper.events.on('messageExpired', messageExpired); | ||
|  | 
 | ||
|  |     this.setState({ isInitialLoadComplete: true }); | ||
|  |   } | ||
| 
											5 years ago
										 | } |