Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / helpApp / src / handlers / helpAppRootHandler.ts
1 /**
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt odlux
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 // main state handler
19
20 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
21 import { IActionHandler } from '../../../../framework/src/flux/action';
22
23 import { LoadTocAction, TocLoadedAction, LoadDocumentAction, DocumentLoadedAction } from '../actions/helpActions';
24 import { TocTreeNode } from '../models/tocNode';
25
26 export interface IHelpAppStoreState {
27   busy: boolean;
28   toc: TocTreeNode[] | undefined;
29   content: string | undefined;
30   currentPath: string | undefined;
31 }
32
33 declare module '../../../../framework/src/store/applicationStore' {
34   interface IApplicationStoreState {
35     help: IHelpAppStoreState
36   }
37 }
38
39 const helpAppStoreStatcurrentPatheInit: IHelpAppStoreState = {
40   busy: false,
41   toc: undefined,
42   content: undefined,
43   currentPath: undefined
44 };
45
46 export const helpAppRootHandler: IActionHandler<IHelpAppStoreState> = (state = helpAppStoreStatcurrentPatheInit, action) => {
47   if (action instanceof LoadTocAction) {
48     state = {
49       ...state,
50       busy: true
51     };
52   } else if (action instanceof TocLoadedAction) {
53     state = {
54       ...state,
55       busy: false,
56       toc: action.toc
57     };
58   } else if (action instanceof LoadDocumentAction) {
59     state = {
60       ...state,
61       busy: true
62     };
63   } else if (action instanceof DocumentLoadedAction) {
64     state = {
65       ...state,
66       busy: false,
67       content: action.document,
68       currentPath: action.documentPath
69     };
70   }
71
72   return state;
73 }
74
75
76 export default helpAppRootHandler;