Add notifications view

This commit is contained in:
Tobias Fella
2023-11-11 17:57:03 +01:00
parent 96e62e3ebe
commit fc546d4a43
5 changed files with 342 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigami.delegates as KD
import org.kde.kirigamiaddons.components as Components
import org.kde.neochat
Kirigami.ScrollablePage {
id: root
required property NeoChatConnection connection
title: i18nc("@title", "Notifications")
ListView {
id: listView
anchors.fill: parent
verticalLayoutDirection: ListView.BottomToTop
model: NotificationsModel {
id: notificationsModel
connection: root.connection
}
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
visible: listView.count === 0
text: notificationsModel.loading ? i18n("Loading…") : i18n("No Notifications")
}
footer: Kirigami.PlaceholderMessage {
anchors.horizontalCenter: parent.horizontalCenter
text: i18n("Loading…")
visible: notificationsModel.nextToken.length > 0 && listView.count > 0
}
delegate: QQC2.ItemDelegate {
width: parent?.width ?? 0
onClicked: RoomManager.visitRoom(model.room, model.eventId)
contentItem: RowLayout {
spacing: Kirigami.Units.largeSpacing
Components.Avatar {
source: model.authorAvatar
name: model.authorName
implicitHeight: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
implicitWidth: implicitHeight
Layout.fillHeight: true
Layout.preferredWidth: height
}
ColumnLayout {
spacing: 0
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
QQC2.Label {
id: label
text: model.roomDisplayName
elide: Text.ElideRight
font.weight: Font.Normal
textFormat: Text.PlainText
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
}
QQC2.Label {
id: subtitle
text: model.text
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
opacity: root.hasNotifications ? 0.9 : 0.7
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
}
}
}
}
}
}

View File

@@ -8,6 +8,7 @@ import QtQuick.Layouts
import QtQml.Models
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.components as KirigamiComponents
import org.kde.neochat
import org.kde.neochat.config
@@ -128,6 +129,23 @@ Kirigami.Page {
topMargin: Math.round(Kirigami.Units.smallSpacing / 2)
KirigamiComponents.FloatingButton {
icon.name: "notifications"
text: i18n("View notifications")
anchors.right: parent.right
anchors.rightMargin: Kirigami.Units.largeSpacing
anchors.bottom: parent.bottom
anchors.bottomMargin: Kirigami.Units.largeSpacing
width: Kirigami.Units.gridUnit * 2
height: width
QQC2.ToolTip.text: text
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
QQC2.ToolTip.visible: hovered
onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/NotificationsView.qml", {connection: root.connection}, {
title: i18nc("@title", "Notifications")
});
}
header: QQC2.ItemDelegate {
width: visible ? ListView.view.width : 0
height: visible ? Kirigami.Units.gridUnit * 2 : 0