-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
TimelinePage.qml
220 lines (179 loc) · 6.78 KB
/
TimelinePage.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// SPDX-FileCopyrightText: 2021 Carl Schwan <[email protected]>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import org.kde.kirigami 2 as Kirigami
import org.kde.kirigamiaddons.labs.components 1 as LabComponents
import org.kde.kirigamiaddons.components 1 as Components
import org.kde.kirigamiaddons.statefulapp as StatefulApp
import QtQuick.Controls 2 as QQC2
import QtQuick.Layouts
import org.kde.tokodon
import './PostDelegate'
import './StatusComposer'
Kirigami.ScrollablePage {
id: root
property var dialog: null
required property var model
property bool expandedPost: false
property alias listViewHeader: listview.header
property alias showPostAction: postAction.visible
property bool completedInitialLoad: false
property alias listView: listview
readonly property bool showReplies: showRepliesAction.checked
readonly property bool showBoosts: showBoostsAction.checked
property alias showFilterAction: filterAction.visible
property alias originalPostUrl: listview.originalPostUrl
property string iconName
property alias placeholderText: placeholderMessage.text
property alias placeholderExplanation: placeholderMessage.explanation
Keys.onPressed: event => listview.handleKeyEvent(event)
title: {
// Show the account name if the drawer is not open, so there's no way to tell which account you're on.
if (model.name === "home" && !applicationWindow().globalDrawer.drawerOpen) {
if (AccountManager.rowCount() > 1) {
if (AccountManager.selectedAccount === null) {
return i18n("Loading");
}
return i18n("Home (%1)", AccountManager.selectedAccount.identity.displayNameHtml);
}
}
return model.displayName ?? "";
}
titleDelegate: Kirigami.Heading {
// identical to normal Kirigami headers
Layout.fillWidth: true
Layout.maximumWidth: implicitWidth + 1
Layout.minimumWidth: 0
maximumLineCount: 1
elide: Text.ElideRight
text: root.title
textFormat: TextEdit.RichText
}
header: LabComponents.Banner {
id: message
type: Kirigami.MessageType.Error
width: parent.width
showCloseButton: true
actions: Kirigami.Action {
fromQAction: (root.QQC2.ApplicationWindow.window as StatefulApp.StatefulWindow)?.application.action('options_configure') ?? null
}
}
globalToolBarStyle: Kirigami.ApplicationHeaderStyle.ToolBar
onBackRequested: if (dialog) {
dialog.close();
dialog = null;
event.accepted = true;
}
actions: [
Kirigami.Action {
id: postAction
icon.name: "list-add"
text: i18nc("@action:button", "Post")
enabled: AccountManager.hasAccounts
onTriggered: Navigation.openComposer("")
},
Kirigami.Action {
id: filterAction
text: i18nc("@action:button", "Filters")
icon.name: "view-filter"
Kirigami.Action {
id: showBoostsAction
text: i18n("Show Boosts")
icon.name: "tokodon-post-boost"
checkable: true
checked: true
}
Kirigami.Action {
id: showRepliesAction
text: i18n("Show Replies")
icon.name: "tokodon-post-reply"
checkable: true
checked: true
}
}
]
Component.onCompleted: {
// TODO: When we can require KF 6.8, set it as a normal property
if (root.verticalScrollBarInteractive !== undefined) {
root.verticalScrollBarInteractive = false;
}
}
Connections {
target: Controller
function onNetworkErrorOccurred(error) {
message.text = i18nc("@info:status Network status", "Failed to contact server: %1. Please check your settings.", error)
message.visible = true
}
}
background: Rectangle {
color: Kirigami.Theme.backgroundColor
Kirigami.PlaceholderMessage {
id: placeholderMessage
anchors.centerIn: parent
icon.name: root.iconName
visible: listview.count === 0 && !listview.model.loading
width: parent.width - Kirigami.Units.gridUnit * 4
}
}
TimelineView {
id: listview
model: root.model
isCurrentPage: root.isCurrentPage
header: Kirigami.FlexColumn {
id: flexColumn
spacing: 0
padding: 0
maximumWidth: Kirigami.Units.gridUnit * 40
width: parent.width
height: visible ? Kirigami.Units.gridUnit * 3 : 0
visible: root.model.hasPrevious ?? false
QQC2.Button {
text: i18nc("@action:button Load more posts above this", "Load More")
icon.name: "content-loading-symbolic"
onClicked: timelineModel.fetchPrevious()
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: Kirigami.Units.largeSpacing
}
}
section {
property: "showReadMarker"
delegate: Kirigami.FlexColumn {
id: flexColumn
required property bool section
spacing: 0
padding: 0
maximumWidth: Kirigami.Units.gridUnit * 40
width: parent.width
height: marker.visible ? Kirigami.Units.gridUnit * 2 : 0
RowLayout {
spacing: Kirigami.Units.smallSpacing
visible: flexColumn.section
Layout.fillWidth: true
Layout.fillHeight: true
Layout.topMargin: Kirigami.Units.largeSpacing
Layout.bottomMargin: Kirigami.Units.largeSpacing
Item {
Layout.fillWidth: true
}
Kirigami.Icon {
source: "view-readermode"
color: Kirigami.Theme.disabledTextColor
Layout.preferredWidth: Kirigami.Units.iconSizes.sizeForLabels
Layout.preferredHeight: Kirigami.Units.iconSizes.sizeForLabels
}
ReadMarker {
id: marker
date: root.model.lastReadTime
}
Item {
Layout.fillWidth: true
}
}
Kirigami.Separator {
visible: flexColumn.section
Layout.fillWidth: true
}
}
}
}
}