Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: extract IconNotification to separate component
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Sep 12, 2024
commit 9e1616c5603d33480780072d164b978424f143b4
105 changes: 105 additions & 0 deletions src/Components/IconNotification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<IconBell v-if="!showDot && !showWarning"
class="notifications-button__icon"
:size="20"
:title="t('notifications', 'Notifications')" />
<!-- From material design icons -->
<svg v-else
class="notifications-button__icon"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
width="20"
height="20"
viewBox="0 0 24 24"
fill="currentColor">
<path d="M 19,11.79 C 18.5,11.92 18,12 17.5,12 14.47,12 12,9.53 12,6.5 12,5.03 12.58,3.7 13.5,2.71 13.15,2.28 12.61,2 12,2 10.9,2 10,2.9 10,4 V 4.29 C 7.03,5.17 5,7.9 5,11 v 6 l -2,2 v 1 H 21 V 19 L 19,17 V 11.79 M 12,23 c 1.11,0 2,-0.89 2,-2 h -4 c 0,1.11 0.9,2 2,2 z" />
<path class="notification__dot"
:class="{
'notification__dot--warning': showWarning && !isOrangeThemed,
'notification__dot--white': isRedThemed || (showWarning && isOrangeThemed),
}"
d="M 21,6.5 C 21,8.43 19.43,10 17.5,10 15.57,10 14,8.43 14,6.5 14,4.57 15.57,3 17.5,3 19.43,3 21,4.57 21,6.5" />
</svg>
</template>

<script>
import IconBell from 'vue-material-design-icons/Bell.vue'

import { getCapabilities } from '@nextcloud/capabilities'

export default {
name: 'IconNotification',

components: {
IconBell,
},

props: {
showDot: {
type: Boolean,
default: false,
},
showWarning: {
type: Boolean,
default: false,
},
},

data() {
return {
theming: getCapabilities()?.theming || {},
}
},

computed: {
isRedThemed() {
if (this.theming?.color) {
const hsl = this.rgbToHsl(this.theming.color.substring(1, 3),
this.theming.color.substring(3, 5),
this.theming.color.substring(5, 7))
const h = hsl[0] * 360
return (h >= 330 || h <= 15) && hsl[1] > 0.4 && (hsl[2] > 0.1 || hsl[2] < 0.6)
}
return false
},
isOrangeThemed() {
if (this.theming?.color) {
const hsl = this.rgbToHsl(this.theming.color.substring(1, 3),
this.theming.color.substring(3, 5),
this.theming.color.substring(5, 7))
const h = hsl[0] * 360
return (h >= 305 || h <= 64) && hsl[1] > 0.7 && (hsl[2] > 0.1 || hsl[2] < 0.6)
}
return false
},
},

methods: {
rgbToHsl(r, g, b) {
r = parseInt(r, 16) / 255; g = parseInt(g, 16) / 255; b = parseInt(b, 16) / 255
const max = Math.max(r, g, b); const min = Math.min(r, g, b)
let h; let s; const l = (max + min) / 2

if (max === min) {
h = s = 0
} else {
const d = max - min
s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
switch (max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break
case g: h = (b - r) / d + 2; break
case b: h = (r - g) / d + 4; break
}
h /= 6
}

return [h, s, l]
},
},
}
</script>
88 changes: 14 additions & 74 deletions src/NotificationsApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,8 @@
:aria-label="t('notifications', 'Notifications')"
@open="onOpen">
<template #trigger>
<Bell v-if="notifications.length === 0 && webNotificationsGranted !== null && !hasThrottledPushNotifications"
class="notifications-button__icon"
:size="20"
:title="t('notifications', 'Notifications')" />
<!-- From material design icons -->
<svg v-else
class="notifications-button__icon"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
width="20"
height="20"
viewBox="0 0 24 24"
fill="currentColor">
<path d="M 19,11.79 C 18.5,11.92 18,12 17.5,12 14.47,12 12,9.53 12,6.5 12,5.03 12.58,3.7 13.5,2.71 13.15,2.28 12.61,2 12,2 10.9,2 10,2.9 10,4 V 4.29 C 7.03,5.17 5,7.9 5,11 v 6 l -2,2 v 1 H 21 V 19 L 19,17 V 11.79 M 12,23 c 1.11,0 2,-0.89 2,-2 h -4 c 0,1.11 0.9,2 2,2 z" />
<path :class="isRedThemed ? 'notification__dot--white' : ''" class="notification__dot" d="M 21,6.5 C 21,8.43 19.43,10 17.5,10 15.57,10 14,8.43 14,6.5 14,4.57 15.57,3 17.5,3 19.43,3 21,4.57 21,6.5" />
<path v-if="hasThrottledPushNotifications"
:class="isOrangeThemed ? 'notification__dot--white' : ''"
class="notification__dot notification__dot--warning"
d="M 21,6.5 C 21,8.43 19.43,10 17.5,10 15.57,10 14,8.43 14,6.5 14,4.57 15.57,3 17.5,3 19.43,3 21,4.57 21,6.5" />
</svg>
<IconNotification :show-dot="notifications.length !== 0 || webNotificationsGranted === null"
:show-warning="hasThrottledPushNotifications" />
</template>

<!-- Notifications list content -->
Expand Down Expand Up @@ -64,7 +45,7 @@
<NcButton type="tertiary"
@click="onDismissAll">
<template #icon>
<Close :size="20" />
<IconClose :size="20" />
</template>
{{ t('notifications', 'Dismiss all notifications') }}
</NcButton>
Expand All @@ -76,7 +57,7 @@
:name="emptyContentMessage"
:description="emptyContentDescription">
<template #icon>
<Bell v-if="!hasThrottledPushNotifications" />
<IconBell v-if="!hasThrottledPushNotifications" />
<span v-else class="icon icon-alert-outline" />
</template>

Expand All @@ -86,7 +67,7 @@
target="_blank"
rel="noreferrer noopener">
<template #icon>
<Message :size="20" />
<IconMessage :size="20" />
</template>
{{ t('notifications', 'Contact Nextcloud GmbH') }} ↗
</NcButton>
Expand All @@ -98,9 +79,12 @@
</template>

<script>
import IconBell from 'vue-material-design-icons/Bell.vue'
import IconClose from 'vue-material-design-icons/Close.vue'
import IconMessage from 'vue-material-design-icons/Message.vue'
import IconNotification from './Components/IconNotification.vue'
import Notification from './Components/Notification.vue'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import Close from 'vue-material-design-icons/Close.vue'
import axios from '@nextcloud/axios'
import { getCurrentUser } from '@nextcloud/auth'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
Expand All @@ -112,21 +96,20 @@ import {
} from '@nextcloud/router'
import { getNotificationsData } from './services/notificationsService.js'
import { listen } from '@nextcloud/notify_push'
import Bell from 'vue-material-design-icons/Bell.vue'
import Message from 'vue-material-design-icons/Message.vue'

import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import { getCapabilities } from '@nextcloud/capabilities'
import NcHeaderMenu from '@nextcloud/vue/dist/Components/NcHeaderMenu.js'
import { createWebNotification } from './services/webNotificationsService.js'

export default {
name: 'NotificationsApp',

components: {
IconBell,
IconClose,
IconMessage,
IconNotification,
NcButton,
Close,
Bell,
Message,
NcEmptyContent,
NcHeaderMenu,
Notification,
Expand All @@ -138,7 +121,6 @@ export default {
backgroundFetching: false,
hasNotifyPush: false,
shutdown: false,
theming: getCapabilities()?.theming || {},
hasThrottledPushNotifications: loadState('notifications', 'throttled_push_notifications'),
notifications: [],
lastETag: null,
Expand Down Expand Up @@ -179,27 +161,6 @@ export default {
_$icon: null,

computed: {
isRedThemed() {
if (this.theming?.color) {
const hsl = this.rgbToHsl(this.theming.color.substring(1, 3),
this.theming.color.substring(3, 5),
this.theming.color.substring(5, 7))
const h = hsl[0] * 360
return (h >= 330 || h <= 15) && hsl[1] > 0.4 && (hsl[2] > 0.1 || hsl[2] < 0.6)
}
return false
},
isOrangeThemed() {
if (this.theming?.color) {
const hsl = this.rgbToHsl(this.theming.color.substring(1, 3),
this.theming.color.substring(3, 5),
this.theming.color.substring(5, 7))
const h = hsl[0] * 360
return (h >= 305 || h <= 64) && hsl[1] > 0.7 && (hsl[2] > 0.1 || hsl[2] < 0.6)
}
return false
},

showBrowserNotifications() {
return this.backgroundFetching
&& this.webNotificationsGranted
Expand Down Expand Up @@ -315,27 +276,6 @@ export default {
this.notifications.splice(index, 1)
},

rgbToHsl(r, g, b) {
r = parseInt(r, 16) / 255; g = parseInt(g, 16) / 255; b = parseInt(b, 16) / 255
const max = Math.max(r, g, b); const min = Math.min(r, g, b)
let h; let s; const l = (max + min) / 2

if (max === min) {
h = s = 0
} else {
const d = max - min
s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
switch (max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break
case g: h = (b - r) / d + 2; break
case b: h = (r - g) / d + 4; break
}
h /= 6
}

return [h, s, l]
},

/**
* Update the title to show * if there are new notifications
*
Expand Down