2023-07-29 11:01:56 +02:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import ScreenPlayAssets
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
height: wrapper.childrenRect.height
|
|
|
|
|
|
|
|
property string points
|
|
|
|
property string commentCount
|
|
|
|
property string pubDate
|
|
|
|
property string pubDateFormatted
|
|
|
|
onPubDateChanged: {
|
2023-08-20 11:59:02 +02:00
|
|
|
var date = new Date(pubDate);
|
|
|
|
root.pubDateFormatted = date.toLocaleDateString(Qt.locale(), "ddd, dd MMM yyyy") + ' ' + date.toLocaleTimeString(Qt.locale(), "HH:mm:ss");
|
2023-07-29 11:01:56 +02:00
|
|
|
}
|
|
|
|
property string description
|
|
|
|
onDescriptionChanged: {
|
2023-08-20 11:59:02 +02:00
|
|
|
print("description");
|
2023-07-29 11:01:56 +02:00
|
|
|
// See https://hnrss.org/frontpage <description> content
|
|
|
|
// We need to manually parse it here to get the points and comments
|
2023-08-20 11:59:02 +02:00
|
|
|
points = parsePoints(description);
|
|
|
|
commentCount = parseCommentCount(description);
|
|
|
|
print(points, commentCount);
|
2023-07-29 11:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseCommentCount(raw) {
|
2023-08-20 11:59:02 +02:00
|
|
|
var commentPrefix = "<p># Comments: ";
|
|
|
|
var commentSuffix = "</p>";
|
|
|
|
var startIdx = raw.indexOf(commentPrefix);
|
2023-07-29 11:01:56 +02:00
|
|
|
if (startIdx === -1)
|
2023-08-20 11:59:02 +02:00
|
|
|
return "N/A"; // return "N/A" if comment count is not found in the description
|
|
|
|
startIdx += commentPrefix.length;
|
|
|
|
var endIdx = raw.indexOf(commentSuffix, startIdx);
|
|
|
|
return raw.substring(startIdx, endIdx);
|
2023-07-29 11:01:56 +02:00
|
|
|
}
|
|
|
|
function parsePoints(raw) {
|
2023-08-20 11:59:02 +02:00
|
|
|
var pointsPrefix = "<p>Points: ";
|
|
|
|
var pointsSuffix = "</p>";
|
|
|
|
var startIdx = raw.indexOf(pointsPrefix);
|
2023-07-29 11:01:56 +02:00
|
|
|
if (startIdx === -1)
|
2023-08-20 11:59:02 +02:00
|
|
|
return "N/A"; // return "N/A" if points are not found in the description
|
|
|
|
startIdx += pointsPrefix.length;
|
|
|
|
var endIdx = raw.indexOf(pointsSuffix, startIdx);
|
|
|
|
return raw.substring(startIdx, endIdx);
|
2023-07-29 11:01:56 +02:00
|
|
|
}
|
|
|
|
RowLayout {
|
|
|
|
id: wrapper
|
|
|
|
width: root.width
|
|
|
|
spacing: 5
|
|
|
|
ColumnLayout {
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: titleText
|
|
|
|
text: model.title
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
font.pointSize: 14
|
|
|
|
font.bold: true
|
|
|
|
color: "white"
|
|
|
|
Layout.maximumWidth: wrapper.width * .9
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onClicked: {
|
2023-08-20 11:59:02 +02:00
|
|
|
Qt.openUrlExternally(model.link);
|
2023-07-29 11:01:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: descriptionText
|
2023-08-20 11:59:02 +02:00
|
|
|
text: root.points + " Points • " + root.commentCount + " Comments 🔗 " + "• Published: " + root.pubDateFormatted
|
2023-07-29 11:01:56 +02:00
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
font.pointSize: 10
|
|
|
|
opacity: .7
|
|
|
|
color: "white"
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onClicked: {
|
2023-08-20 11:59:02 +02:00
|
|
|
Qt.openUrlExternally(model.commentsLink);
|
2023-07-29 11:01:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|