-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4210 from FlowFuse/4184_notifications-inbox-view
Add notifications drawer
- Loading branch information
Showing
18 changed files
with
736 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<template> | ||
<div class="notifications-button-wrapper"> | ||
<button class="notifications-button" data-el="notifications-button" data-click-exclude="right-drawer" @click="onClick"> | ||
<MailIcon /> | ||
<ff-notification-pill v-if="hasNotifications" data-el="notification-pill" class="ml-3" :count="notifications.total" /> | ||
</button> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { MailIcon } from '@heroicons/vue/solid' | ||
import { markRaw } from 'vue' | ||
import { mapActions, mapGetters, mapState } from 'vuex' | ||
import NotificationsDrawer from './drawers/notifications/NotificationsDrawer.vue' | ||
export default { | ||
name: 'NotificationsButton', | ||
components: { MailIcon }, | ||
computed: { | ||
...mapState('ux', ['rightDrawer']), | ||
...mapGetters('account', ['hasNotifications']), | ||
...mapGetters('account', ['notifications']) | ||
}, | ||
methods: { | ||
...mapActions('ux', ['openRightDrawer', 'closeRightDrawer']), | ||
onClick () { | ||
if (this.rightDrawer.state) { | ||
this.closeRightDrawer() | ||
} else this.openRightDrawer({ component: markRaw(NotificationsDrawer) }) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.notifications-button-wrapper { | ||
.notifications-button { | ||
border-left: 1px solid $ff-grey-500; | ||
color: white; | ||
display: flex; | ||
align-items: center; | ||
flex: 1; | ||
justify-content: center; | ||
width: 100%; | ||
height: 100%; | ||
padding: 18px; | ||
position: relative; | ||
> * { | ||
pointer-events: none; | ||
} | ||
&:hover { | ||
background-color: $ff-grey-700; | ||
} | ||
svg { | ||
flex: 1; | ||
width: 24px; | ||
height: 24px; | ||
} | ||
.ff-notification-pill { | ||
bottom: 10px; | ||
right: 5px; | ||
position: absolute; | ||
font-size: 0.65rem; | ||
padding: 0 7px; | ||
background-color: $ff-red-500; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<template> | ||
<div v-click-outside="{handler: closeRightDrawer, exclude: ['right-drawer']}" class="right-drawer" :class="{open: rightDrawer.state}" data-el="right-drawer"> | ||
<component :is="rightDrawer.component" v-if="rightDrawer.component" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapActions, mapState } from 'vuex' | ||
export default { | ||
name: 'RightDrawer', | ||
computed: { | ||
...mapState('ux', ['rightDrawer']) | ||
}, | ||
methods: { | ||
...mapActions('ux', ['closeRightDrawer']) | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.right-drawer { | ||
position: absolute; | ||
border-left: 1px solid $ff-grey-300; | ||
background: white; | ||
height: 100%; | ||
right: -1000px; | ||
z-index: 500; | ||
width: 100%; | ||
max-width: 0; | ||
min-width: 0; | ||
transition: ease-in-out .3s; | ||
box-shadow: -5px 0px 8px rgba(0, 0, 0, 0.1); | ||
&.open { | ||
right: 0; | ||
width: 100%; | ||
max-width: 30vw; | ||
min-width: 400px; | ||
} | ||
} | ||
</style> |
80 changes: 80 additions & 0 deletions
80
frontend/src/components/drawers/notifications/NotificationsDrawer.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<template> | ||
<div class="ff-notifications-drawer" data-el="notifications-drawer"> | ||
<div class="header"> | ||
<h2 class="title">Notifications</h2> | ||
<!-- <div class="actions">--> | ||
<!-- <span class="forge-badge" :class="{disabled: !canSelectAll}" @click="selectAll">select all</span>--> | ||
<!-- <span class="forge-badge" :class="{disabled: !canDeselectAll}" @click="deselectAll">deselect all</span>--> | ||
<!-- <span class="forge-badge disabled">mark as read</span>--> | ||
<!-- <span class="forge-badge disabled">mark as unread</span>--> | ||
<!-- </div>--> | ||
</div> | ||
<ul v-if="hasNotificationMessages" class="messages-wrapper" data-el="messages-wrapper"> | ||
<li v-for="notification in notificationMessages" :key="notification.id" data-el="message"> | ||
<component | ||
:is="notificationsComponentMap['team-invitation']" | ||
:notification="notification" | ||
:selections="selections" | ||
@selected="onSelected" | ||
@deselected="onDeselected" | ||
/> | ||
</li> | ||
</ul> | ||
<div v-else class="empty"> | ||
<p>Nothing so far...</p> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { markRaw } from 'vue' | ||
import { mapGetters } from 'vuex' | ||
import TeamInvitationNotification from '../../notifications/TeamInvitationNotification.vue' | ||
export default { | ||
name: 'NotificationsDrawer', | ||
data () { | ||
return { | ||
notificationsComponentMap: { | ||
// todo replace hardcoded value with actual notification type | ||
'team-invitation': markRaw(TeamInvitationNotification) | ||
}, | ||
selections: [] | ||
} | ||
}, | ||
computed: { | ||
...mapGetters('account', ['notificationMessages']), | ||
canSelectAll () { | ||
return this.notificationMessages.length !== this.selections.length | ||
}, | ||
canDeselectAll () { | ||
return this.selections.length > 0 | ||
}, | ||
hasNotificationMessages () { | ||
return this.notificationMessages.length > 0 | ||
} | ||
}, | ||
methods: { | ||
onSelected (notification) { | ||
this.selections.push(notification) | ||
}, | ||
onDeselected (notification) { | ||
const index = this.selections.findIndex(n => n.id === notification.id) | ||
if (index > -1) { | ||
this.selections.splice(index, 1) | ||
} | ||
}, | ||
selectAll () { | ||
this.selections = [...this.notificationMessages] | ||
}, | ||
deselectAll () { | ||
this.selections = [] | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<template> | ||
<div class="message" @click="go(to)"> | ||
<div class="body"> | ||
<div class="icon ff-icon ff-icon-lg"> | ||
<slot name="icon" /> | ||
</div> | ||
<div class="text"> | ||
<div class="header"> | ||
<h4 class="title"><slot name="title" /></h4> | ||
<!-- <ff-checkbox :model-value="isSelected" label="" @click.prevent.stop="toggleSelection" />--> | ||
</div> | ||
<div class="content"> | ||
<slot name="message" /> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="footer"> | ||
<slot name="timestamp" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapActions } from 'vuex' | ||
import NotificationMessageMixin from '../../mixins/NotificationMessage.js' | ||
export default { | ||
name: 'TeamInvitationNotification', | ||
mixins: [NotificationMessageMixin], | ||
props: { | ||
to: { | ||
type: Object, | ||
required: true | ||
} | ||
}, | ||
computed: { | ||
invitorName () { | ||
return this.notification.invitor.name | ||
}, | ||
teamName () { | ||
return this.notification.team.name | ||
} | ||
}, | ||
methods: { | ||
...mapActions('ux', ['closeRightDrawer']), | ||
go (to) { | ||
this.closeRightDrawer() | ||
this.$router.push(to) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
</style> |
42 changes: 42 additions & 0 deletions
42
frontend/src/components/notifications/TeamInvitationNotification.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<template> | ||
<NotificationMessage data-el="invitation-message" :to="{name: 'User Invitations'}"> | ||
<template #icon> | ||
<UserAddIcon /> | ||
</template> | ||
<template #title> | ||
Team Invitation | ||
</template> | ||
<template #message> | ||
You have been invited by <i>"{{ invitorName }}"</i> to join <i>"{{ teamName }}"</i>. | ||
</template> | ||
<template #timestamp> | ||
{{ notification.createdSince }} | ||
</template> | ||
</NotificationMessage> | ||
</template> | ||
|
||
<script> | ||
import { UserAddIcon } from '@heroicons/vue/solid' | ||
import NotificationMessageMixin from '../../mixins/NotificationMessage.js' | ||
import NotificationMessage from './Notification.vue' | ||
export default { | ||
name: 'TeamInvitationNotification', | ||
components: { NotificationMessage, UserAddIcon }, | ||
mixins: [NotificationMessageMixin], | ||
computed: { | ||
invitorName () { | ||
return this.notification.invitor.name | ||
}, | ||
teamName () { | ||
return this.notification.team.name | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.