From c651ae6d7a11c77a607543a1afae863b20b6d174 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 22 Sep 2024 15:37:36 -0300 Subject: Pull request description and comments working --- kodereviewer/qml/CommentDelegate.qml | 77 +++++++++++++++++++++++++++++++++ kodereviewer/qml/Main.qml | 27 +++++------- kodereviewer/qml/ProjectListPage.qml | 4 +- kodereviewer/qml/PullRequestPage.qml | 84 ++++++++++++++++++++++++++++++++++++ 4 files changed, 175 insertions(+), 17 deletions(-) create mode 100644 kodereviewer/qml/CommentDelegate.qml create mode 100644 kodereviewer/qml/PullRequestPage.qml (limited to 'kodereviewer/qml') diff --git a/kodereviewer/qml/CommentDelegate.qml b/kodereviewer/qml/CommentDelegate.qml new file mode 100644 index 0000000..bac75d0 --- /dev/null +++ b/kodereviewer/qml/CommentDelegate.qml @@ -0,0 +1,77 @@ +import QtQml +import QtQuick 6.7 +import QtQuick.Layouts 6.7 +import QtQuick.Controls 6.7 as QQC2 + +import org.kde.kirigami as Kirigami +import org.kde.kirigamiaddons.components as KirigamiComponents + +Kirigami.AbstractCard { + id: root + required property url avatarUrl + required property string createdAt + required property string username + required property string body + + header: RowLayout { + KirigamiComponents.Avatar { + name: root.username + source: root.avatarUrl + Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium + Layout.preferredHeight: Kirigami.Units.iconSizes.smallMedium + } + Kirigami.Heading { + Layout.fillWidth: true + id: commentHeading + level: 3 + text: `@${root.username}` + } + QQC2.Label { + text: new Date(root.createdAt).toLocaleString(Qt.locale(), Locale.ShortFormat) + } + Kirigami.ActionToolBar { + Layout.fillWidth: false + actions: [ + Kirigami.Action { + icon.name: "overflow-menu" + + Kirigami.Action { + text: "Edit" + icon.name: "edit-comment" + } + + Kirigami.Action { + text: "Delete" + icon.name: "delete-comment" + } + } + ] + + position: QQC2.ToolBar.Header + } + } + + contentItem: Item { + implicitWidth: delegateLayout.implicitWidth + implicitHeight: delegateLayout.implicitHeight + ColumnLayout { + id: delegateLayout + spacing: Kirigami.Units.largeSpacing + anchors { + top: parent.top + left: parent.left + right: parent.right + } + + Kirigami.Separator { + Layout.fillWidth: true + } + QQC2.Label { + Layout.fillWidth: true + text: root.body + textFormat: Text.MarkdownText + wrapMode: Text.WordWrap + } + } + } +} diff --git a/kodereviewer/qml/Main.qml b/kodereviewer/qml/Main.qml index 0b41a05..e7496a6 100644 --- a/kodereviewer/qml/Main.qml +++ b/kodereviewer/qml/Main.qml @@ -53,33 +53,28 @@ Kirigami.ApplicationWindow { ProjectListPage { connection: root.connection project: root.project + + onPullRequestSelected: pr => { + print(pr) + pullRequestPageLoader.item.pullRequest = pr + + } } } } Loader { - id: placeHolderPageLoader + id: pullRequestPageLoader active: false - sourceComponent: Component { - Kirigami.Page { - - Kirigami.Theme.colorSet: Kirigami.Theme.View - Kirigami.Theme.inherit: false - title: "Select a pull request" - spacing: Kirigami.Units.largeSpacing * 2 - Kirigami.PlaceholderMessage { - anchors.centerIn: parent - icon.name: "org.deprecated.kodereviewer" - text: "Select a pull request" - } - } + sourceComponent: PullRequestPage { + connection: root.connection } } onProjectSelected: { projectListPageLoader.active = true - placeHolderPageLoader.active = true + pullRequestPageLoader.active = true pageStack.replace(projectListPageLoader.item) - pageStack.push(placeHolderPageLoader.item) + pageStack.push(pullRequestPageLoader.item) } } diff --git a/kodereviewer/qml/ProjectListPage.qml b/kodereviewer/qml/ProjectListPage.qml index 334799e..7ffa8b9 100644 --- a/kodereviewer/qml/ProjectListPage.qml +++ b/kodereviewer/qml/ProjectListPage.qml @@ -14,7 +14,7 @@ Kirigami.Page { required property NetworkManager connection required property Project project - + signal pullRequestSelected(var pullRequest) readonly property int currentWidth: _private.currentWidth + 1 @@ -77,6 +77,8 @@ Kirigami.Page { text: `${number} - ${title}` icon.name: "vcs-merge-request" + + onClicked: root.pullRequestSelected(pullRequestModel.get(index)) } } } diff --git a/kodereviewer/qml/PullRequestPage.qml b/kodereviewer/qml/PullRequestPage.qml new file mode 100644 index 0000000..19defdc --- /dev/null +++ b/kodereviewer/qml/PullRequestPage.qml @@ -0,0 +1,84 @@ +pragma ComponentBehavior: Bound +import QtQuick +import QtCore +import QtQuick.Controls as QQC2 +import QtQuick.Layouts + +import org.kde.kirigami as Kirigami +import org.kde.kirigamiaddons.formcard as FormCard + +import org.deprecated.kodereviewer 1.0 + +Kirigami.ScrollablePage { + id: root + + property var pullRequest + property NetworkManager connection + + Kirigami.Theme.colorSet: Kirigami.Theme.View + Kirigami.Theme.inherit: false + + + CommentModel { + id: commentModel + pullRequest: root.pullRequest + + onPullRequestChanged: root.connection.getPullRequestComments(pullRequest.number) + } + + ListView { + id: listView + model: commentModel + + spacing: Kirigami.Units.largeSpacing * 2 + topMargin: Kirigami.Units.largeSpacing * 2 + rightMargin: Kirigami.Units.largeSpacing * 2 + leftMargin: Kirigami.Units.largeSpacing * 2 + bottomMargin: Kirigami.Units.largeSpacing * 2 // + commentToolbar.heigh + + header: ColumnLayout { + id: headerLayout + visible: !!root.pullRequest + width: ListView.view ? ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin : 0 + + Kirigami.Heading { + Layout.fillWidth: true + Layout.alignment: Qt.AlignHCenter + leftPadding: Kirigami.Units.largeSpacing + rightPadding: Kirigami.Units.largeSpacing + level: 1 + text: root.pullRequest ? root.pullRequest.title : "" + wrapMode: Text.WordWrap + } + + Kirigami.ListSectionHeader { + Layout.fillWidth: true + text: "description" + } + + QQC2.Label { + Layout.fillWidth: true + Layout.fillHeight: false + leftPadding: Kirigami.Units.largeSpacing + rightPadding: Kirigami.Units.largeSpacing + text: root.pullRequest ? root.pullRequest.body : "" + textFormat: Text.MarkdownText + wrapMode: Text.WordWrap + } + + Kirigami.ListSectionHeader { + Layout.fillWidth: true + text: "Comments" + } + } + + delegate: CommentDelegate {} + + Kirigami.PlaceholderMessage { + visible: !root.pullRequest + anchors.centerIn: parent + icon.name: "org.deprecated.kodereviewer" + text: "Select a pull request" + } + } +} -- cgit v1.2.3-70-g09d2