Skip to content

Commit

Permalink
Let apps toggle an unread counter on app icons
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed May 11, 2021
1 parent b2ad201 commit 7db0abe
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 4 deletions.
47 changes: 47 additions & 0 deletions core/css/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,24 @@ nav[role='navigation'] {
height: 20px;
}

.unread-counter {
background-color: var(--color-primary-text);
border-radius: 50%;
width: 6px;
height: 6px;
display: block;
z-index: 999;
position: absolute;
bottom: 5px;
right: calc(50% - 3px);
text-indent: -9999px;
transition: all var(--animation-quick) ease;
&.hidden {
display: none;
}
}


/* App title */
span {
opacity: 0;
Expand Down Expand Up @@ -544,6 +562,10 @@ nav[role='navigation'] {
a::before {
border-width: 5px;
}

.unread-counter {
top: -10px;
}
}
}

Expand Down Expand Up @@ -587,6 +609,12 @@ nav[role='navigation'] {
display: none;
}

li a.active {
.unread-counter {
top: -10px;
}
}

/* triangle focus feedback */
li a.active::before,
li:hover a::before,
Expand All @@ -612,6 +640,25 @@ nav[role='navigation'] {
}
}

#apps {
.unread-counter {
background-color: var(--color-primary-element);
border-radius: 50%;
width: 6px;
height: 6px;
display: block;
z-index: 999;
position: absolute;
bottom: 7px;
left: 17px;
text-indent: -9999px;
transition: all var(--animation-quick) ease;
&.hidden {
display: none;
}
}
}

/* Skip navigation links – show only on keyboard focus */
.skip-navigation {
padding: 11px;
Expand Down
2 changes: 1 addition & 1 deletion core/js/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions core/src/components/MainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ import OC from '../OC'
* If the screen is bigger, the main menu is not a toggle any more.
*/
export const setUp = () => {

Object.assign(OC, {
setNavigationCounter(id, counter) {
if (counter === 0) {
document.getElementById('appmenu').querySelector('[data-id="' + id + '"] .unread-counter').classList.add('hidden')
document.getElementById('apps').querySelector('[data-id="' + id + '"] .unread-counter').classList.add('hidden')
} else {
document.getElementById('appmenu').querySelector('[data-id="' + id + '"] .unread-counter').classList.remove('hidden')
document.getElementById('apps').querySelector('[data-id="' + id + '"] .unread-counter').classList.remove('hidden')
}
document.getElementById('appmenu').querySelector('[data-id="' + id + '"] .unread-counter').textContent = counter
document.getElementById('apps').querySelector('[data-id="' + id + '"] .unread-counter').textContent = counter
},
})
// init the more-apps menu
OC.registerMenu($('#more-apps > a'), $('#navigation'))

Expand Down
4 changes: 3 additions & 1 deletion core/templates/layout.user.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<?php } ?>
<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet"<?php if ($_['themingInvertMenu']) { ?> filter="url(#invertMenuMain-<?php p($entry['id']); ?>)"<?php } ?> xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" class="app-icon"></image>
</svg>
<div class="unread-counter <?php if ($entry['unread'] === 0) { p('hidden'); }?>" aria-hidden="true"><?php p($entry['unread']); ?></div>
<span>
<?php p($entry['name']); ?>
</span>
Expand Down Expand Up @@ -91,7 +92,8 @@
<defs><filter id="invertMenuMore-<?php p($entry['id']); ?>"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"></feColorMatrix></filter></defs>
<image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invertMenuMore-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" class="app-icon"></image>
</svg>
<span><?php p($entry['name']); ?></span>
<div class="unread-counter <?php if ($entry['unread'] === 0) { p('hidden'); }?>" aria-hidden="true"><?php p($entry['unread']); ?></div>
<span class="app-title"><?php p($entry['name']); ?></span>
</a>
</li>
<?php endforeach; ?>
Expand Down
12 changes: 11 additions & 1 deletion lib/private/NavigationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class NavigationManager implements INavigationManager {
protected $entries = [];
protected $closureEntries = [];
protected $activeEntry;
protected $unreadCounters = [];

/** @var bool */
protected $init = false;
/** @var IAppManager|AppManager */
Expand Down Expand Up @@ -98,7 +100,11 @@ public function add($entry) {
if (!isset($entry['type'])) {
$entry['type'] = 'link';
}
$this->entries[$entry['id']] = $entry;

$id = $entry['id'];
$entry['unread'] = isset($this->unreadCounters[$id]) ? $this->unreadCounters[$id] : 0;

$this->entries[$id] = $entry;
}

/**
Expand Down Expand Up @@ -320,4 +326,8 @@ private function isSubadmin() {
}
return false;
}

public function setUnreadCounter(string $id, int $unreadCounter): void {
$this->unreadCounters[$id] = $unreadCounter;
}
}
9 changes: 9 additions & 0 deletions lib/public/INavigationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,13 @@ public function getActiveEntry();
* @since 14.0.0
*/
public function getAll(string $type = self::TYPE_APPS): array;

/**
* Set an unread counter for navigation entries
*
* @param string $id id of the navigation entry
* @param int $unreadCounter Number of unread entries (0 to hide the counter which is the default)
* @since 22.0.0
*/
public function setUnreadCounter(string $id, int $unreadCounter): void;
}

0 comments on commit 7db0abe

Please sign in to comment.