Skip to content

Commit 72c7287

Browse files
committed
Merge branch 'milestone2k' into milestone3m
2 parents 6116cd9 + 85a552f commit 72c7287

4 files changed

Lines changed: 112 additions & 53 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,9 @@ label: element.label,
9999
onclick: () => openDashboardPane(outliner, element.tabName || element.paneName)
100100
}
101101
})
102-
}
102+
}
103+
104+
* Auto: each #sym:MenuItem has an icon which i want displayed on the left side of each menu item when rendered
105+
106+
* Auto: don't add each menu item in a button looking border. Simply list them.
107+
Upon hover apply background color e6dcff and selected or active to be background color: cbb9ff

src/mainPage/menu.css

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,40 @@
55
}
66

77
.menu-item {
8-
display: block;
9-
border: 1px solid var(--color-border);
10-
border-radius: 0.35rem;
8+
display: flex;
9+
align-items: center;
10+
gap: 0.625rem;
11+
border: 0;
12+
border-radius: 0;
1113
padding: 0.5rem 0.75rem;
12-
background: var(--color-background);
14+
background: transparent;
1315
color: var(--color-text);
1416
text-decoration: none;
1517
width: 100%;
1618
text-align: left;
1719
cursor: pointer;
1820
}
1921

22+
.menu-item-icon {
23+
width: 1rem;
24+
height: 1rem;
25+
flex: 0 0 1rem;
26+
object-fit: contain;
27+
}
28+
29+
.menu-item-label {
30+
min-width: 0;
31+
}
32+
2033
.menu-item:hover,
2134
.menu-item:focus {
22-
background: var(--color-highlight-bg);
35+
background: #e6dcff;
36+
}
37+
38+
.menu-item-active,
39+
.menu-item-active:hover,
40+
.menu-item-active:focus {
41+
background: #cbb9ff;
2342
}
2443

2544
.menu-toggle {

src/mainPage/menu.ts

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import './menu.css'
22
import { OutlineManager } from '../outline/manager'
3-
import { authSession, authn } from 'solid-logic'
3+
import { authSession } from 'solid-logic'
44

55
type MenuItem = {
66
id?: string
7+
icon?: string
8+
paneName?: string
79
label: string
810
onclick: () => void | Promise<void>
911
}
@@ -64,6 +66,8 @@ const getMenuItems = async (outliner: any): Promise<MenuItem[]> => {
6466
const items = await outliner.getDashboardItems()
6567
return items.map((element) => {
6668
return {
69+
icon: element.icon,
70+
paneName: element.tabName || element.paneName,
6771
label: element.label,
6872
onclick: () => openDashboardPane(outliner, element.tabName || element.paneName)
6973
}
@@ -78,7 +82,23 @@ const createMenuButton = (item: MenuItem) => {
7882
const button = document.createElement('button')
7983
button.className = 'menu-item'
8084
button.type = 'button'
81-
button.textContent = item.label
85+
if (item.paneName) {
86+
button.dataset.paneName = item.paneName
87+
}
88+
89+
if (item.icon) {
90+
const icon = document.createElement('img')
91+
icon.className = 'menu-item-icon'
92+
icon.src = item.icon
93+
icon.alt = ''
94+
icon.setAttribute('aria-hidden', 'true')
95+
button.appendChild(icon)
96+
}
97+
98+
const label = document.createElement('span')
99+
label.className = 'menu-item-label'
100+
label.textContent = item.label
101+
button.appendChild(label)
82102

83103
if (item.id) {
84104
button.id = item.id
@@ -91,21 +111,38 @@ const createMenuButton = (item: MenuItem) => {
91111
return button
92112
}
93113

94-
const renderMenuItems = async (outliner: OutlineManager, container: HTMLElement) => {
95-
const me = authn.currentUser()
96-
const menuItems = me ? await getMenuItems(outliner) : []
97-
98-
if (me) {
99-
menuItems.push({
100-
id: 'MenuLogoutItem',
101-
label: 'Logout',
102-
onclick: async () => {
103-
await authSession.logout()
104-
}
105-
})
114+
const setActiveMenuItem = (container: HTMLElement, paneName?: string) => {
115+
const menuItems = Array.from(container.querySelectorAll<HTMLButtonElement>('.menu-item'))
116+
let activeItem: HTMLButtonElement | undefined
117+
118+
menuItems.forEach((item) => {
119+
const isActive = Boolean(paneName) && item.dataset.paneName === paneName
120+
item.classList.toggle('menu-item-active', isActive)
121+
if (isActive) {
122+
item.setAttribute('aria-current', 'page')
123+
activeItem = item
124+
} else {
125+
item.removeAttribute('aria-current')
126+
}
127+
})
128+
129+
if (!activeItem && menuItems[0]) {
130+
menuItems[0].classList.add('menu-item-active')
131+
menuItems[0].setAttribute('aria-current', 'page')
132+
container.dataset.activePaneName = menuItems[0].dataset.paneName || ''
133+
return
134+
}
135+
136+
if (paneName) {
137+
container.dataset.activePaneName = paneName
106138
}
139+
}
140+
141+
const renderMenuItems = async (outliner: OutlineManager, container: HTMLElement) => {
142+
const menuItems = await getMenuItems(outliner)
107143

108144
container.replaceChildren(...menuItems.map(createMenuButton))
145+
setActiveMenuItem(container, container.dataset.activePaneName)
109146
}
110147

111148
const applyMobileMenuStyles = (navMenu: HTMLElement, isOpen: boolean) => {
@@ -223,6 +260,9 @@ export const createLeftSideMenu = async (outliner: OutlineManager) => {
223260

224261
navMenuContent.addEventListener('click', (event) => {
225262
const item = (event.target as HTMLElement).closest('.menu-item')
263+
if (item instanceof HTMLButtonElement) {
264+
setActiveMenuItem(navMenuContent, item.dataset.paneName)
265+
}
226266
const isMobile = outliner.context?.environment?.layout === 'mobile'
227267
if (item && isMobile) {
228268
closeMobileMenu()
@@ -234,7 +274,6 @@ export const createLeftSideMenu = async (outliner: OutlineManager) => {
234274
}
235275

236276
async function openDashboardPane (outliner: any, pane: string): Promise<void> {
237-
console.log('-----Opening profile pane')
238277
outliner.showDashboard({
239278
pane
240279
})

src/outline/manager.js

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -361,32 +361,47 @@ export default function (context) {
361361

362362
async function getDashboardItems () {
363363
const me = authn.currentUser()
364-
if (!me) return []
365-
const div = dom.createElement('div')
366-
const [pods] = await Promise.all([getPods()])
367-
return [
364+
const panes = [
368365
{
369366
paneName: 'home',
370-
label: 'Your stuff',
367+
label: 'Dashboard',
371368
icon: UI.icons.iconBase + 'noun_547570.svg'
372369
},
373-
{
374-
paneName: 'basicPreferences',
375-
label: 'Preferences',
376-
icon: UI.icons.iconBase + 'noun_Sliders_341315_00000.svg'
377-
},
378370
{
379371
paneName: 'profile',
380-
label: 'Your Profile',
372+
label: 'Profile',
381373
icon: UI.icons.iconBase + 'noun_15059.svg'
382374
},
375+
{
376+
paneName: 'socialPane',
377+
label: 'Friends',
378+
icon: UI.icons.originalIconBase + 'foaf/foafTiny.gif'
379+
}
380+
]
381+
382+
if (!me) {
383+
return panes
384+
}
385+
386+
const [pods] = await Promise.all([getPods()])
387+
panes.push(
388+
/* not in use since redesign of profile-pane
383389
{
384390
paneName: 'editProfile',
385391
label: 'Edit your Profile',
386392
icon: UI.icons.iconBase + 'noun_492246.svg'
393+
},
394+
*/
395+
{
396+
paneName: 'basicPreferences',
397+
label: 'Preferences',
398+
icon: UI.icons.iconBase + 'noun_Sliders_341315_00000.svg'
387399
}
388-
]
389-
.concat(pods)
400+
)
401+
402+
panes.push(...pods)
403+
404+
return panes
390405

391406
async function getPods () {
392407
async function addPodStorage (pod) { // namedNode
@@ -452,25 +467,6 @@ export default function (context) {
452467
}
453468
})
454469
}
455-
456-
async function getAddressBooks () {
457-
try {
458-
const context = await UI.login.findAppInstances(
459-
{ me, div, dom },
460-
ns.vcard('AddressBook')
461-
)
462-
return (context.instances || []).map((book, index) => ({
463-
paneName: 'contact',
464-
tabName: `contact-${index}`,
465-
label: 'Contacts',
466-
subject: book,
467-
icon: UI.icons.iconBase + 'noun_15695.svg'
468-
}))
469-
} catch (err) {
470-
console.error('oops in globalAppTabs AddressBook')
471-
}
472-
return []
473-
}
474470
}
475471
this.getDashboardItems = getDashboardItems
476472

0 commit comments

Comments
 (0)