forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.ts
More file actions
80 lines (68 loc) · 2.29 KB
/
header.ts
File metadata and controls
80 lines (68 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { authSession, authn } from 'solid-logic-jss'
import { icons, initHeader } from 'solid-ui-jss'
/**
* menu icons
*/
const HELP_MENU_ICON = icons.iconBase + 'noun_help.svg'
const SOLID_ICON_URL = 'https://solidproject.org/assets/img/solid-emblem.svg'
/**
* menu elements
*/
const USER_GUIDE_MENU_ITEM = 'User guide'
const REPORT_A_PROBLEM_MENU_ITEM = 'Report a problem'
const SHOW_YOUR_PROFILE_MENU_ITEM = 'Show your profile'
const LOG_OUT_MENU_ITEM = 'Log out'
type UserMenuItem = { label: string; onclick: () => void }
/**
* URLS
*/
const USER_GUIDE_MENU_URL = 'https://solidos.github.io/userguide/'
const REPORT_A_PROBLEM_MENU_URL = 'https://github.com/solidos/solidos/issues'
export async function createHeader (store, outliner) {
initHeader(store, await setUserMenu(outliner), setHeaderOptions())
}
function setHeaderOptions () {
const helpMenuList = [
{ label: USER_GUIDE_MENU_ITEM, url: USER_GUIDE_MENU_URL, target: '_blank' },
{ label: REPORT_A_PROBLEM_MENU_ITEM, url: REPORT_A_PROBLEM_MENU_URL, target: '_blank' }
]
const headerOptions = { logo: SOLID_ICON_URL, helpIcon: HELP_MENU_ICON, helpMenuList }
return headerOptions
}
async function setUserMenu (outliner: any) {
// @ts-ignore: showProfile is used conditionally
const showProfile = {
label: SHOW_YOUR_PROFILE_MENU_ITEM,
onclick: () => openUserProfile(outliner)
}
const logOut: UserMenuItem = {
label: LOG_OUT_MENU_ITEM,
onclick: () => {
authSession.logout()
}
}
// the order of the menu is important here, show profile first and logout last
let userMenuList:UserMenuItem[] = [] // was [showProfile]
userMenuList = userMenuList.concat(await getMenuItems(outliner))
userMenuList.push(logOut)
return userMenuList
}
// Does not work to jump to user profile,
function openUserProfile (outliner: any) {
outliner.GotoSubject(authn.currentUser(), true, undefined, true, undefined)
location.reload()
}
async function getMenuItems (outliner: any) {
const items = await outliner.getDashboardItems()
return items.map((element) => {
return {
label: element.label,
onclick: () => openDashboardPane(outliner, element.tabName || element.paneName)
}
})
}
async function openDashboardPane (outliner: any, pane: string): Promise<void> {
outliner.showDashboard({
pane
})
}