@things-factory/shell 4.0.37 → 4.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,66 +0,0 @@
1
- import {
2
- UPDATE_PAGE,
3
- UPDATE_CONTEXT,
4
- UPDATE_ACTIVE_PAGE,
5
- REGISTER_NAVIGATION_CALLBACK,
6
- UNREGISTER_NAVIGATION_CALLBACK
7
- } from '../actions/route.js'
8
- import { updateMetadata } from 'pwa-helpers/metadata.js'
9
- import startCase from 'lodash/startCase'
10
-
11
- const APP_TITLE_EL = document.querySelector('meta[name="application-name"]')
12
- var appTitle
13
- if (APP_TITLE_EL) appTitle = APP_TITLE_EL.content
14
-
15
- const INITIAL_STATE = {
16
- page: '',
17
- resourceId: '',
18
- params: {},
19
- activePage: null,
20
- context: {},
21
- callbacks: []
22
- }
23
-
24
- const route = (state = INITIAL_STATE, action) => {
25
- switch (action.type) {
26
- case UPDATE_PAGE:
27
- return {
28
- ...state,
29
- page: action.page,
30
- resourceId: action.resourceId,
31
- params: action.params
32
- }
33
- case UPDATE_CONTEXT:
34
- let title = action.context?.title
35
- let text = typeof title === 'object' ? title.text : title
36
-
37
- updateMetadata({
38
- title: appTitle + (text ? ` - ${startCase(text)}` : '')
39
- })
40
- return {
41
- ...state,
42
- context: action.context || (state.activePage && state.activePage.context) || {}
43
- }
44
- case UPDATE_ACTIVE_PAGE:
45
- return {
46
- ...state,
47
- activePage: action.activePage
48
- }
49
-
50
- case REGISTER_NAVIGATION_CALLBACK:
51
- return {
52
- ...state,
53
- callbacks: [...state.callbacks, action.callback]
54
- }
55
- case UNREGISTER_NAVIGATION_CALLBACK:
56
- return {
57
- ...state,
58
- callbacks: state.callbacks.filter(callback => callback !== action.callback)
59
- }
60
-
61
- default:
62
- return state
63
- }
64
- }
65
-
66
- export default route