Warning, /network/tokodon/src/content/ui/ExplorePage.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 import QtQuick 0005 import QtQuick.Controls 2 as QQC2 0006 import QtQuick.Layouts 0007 import Qt.labs.qmlmodels 1.0 0008 import org.kde.kirigami 2 as Kirigami 0009 import org.kde.tokodon 0010 import org.kde.tokodon.private 0011 import org.kde.kirigamiaddons.delegates 1 as Delegates 0012 import QtQml.Models 0013 import "./StatusDelegate" 0014 import "./StatusComposer" 0015 0016 Kirigami.ScrollablePage { 0017 id: timelinePage 0018 title: i18n("Explore") 0019 0020 property var dialog: null 0021 0022 onBackRequested: if (dialog) { 0023 dialog.close(); 0024 dialog = null; 0025 event.accepted = true; 0026 } 0027 0028 actions: Kirigami.Action { 0029 icon.name: "list-add" 0030 text: i18nc("@action:button", "Post") 0031 enabled: AccountManager.hasAccounts 0032 onTriggered: Navigation.openStatusComposer() 0033 } 0034 0035 TagsModel { 0036 id: tagsModel 0037 } 0038 0039 MainTimelineModel { 0040 id: trendingPostsModel 0041 name: "trending" 0042 } 0043 0044 property Kirigami.Action tendingPostsAction: Kirigami.Action { 0045 text: i18n("Posts") 0046 icon.name: "tokodon-chat-reply" 0047 checkable: true 0048 onCheckedChanged: (checked) => { 0049 if (checked) { 0050 if (tagsModel.name.length === 0) { 0051 trendingPostsModel.name = "trending"; 0052 } else { 0053 trendingPostsModel.shouldLoadMore = false; 0054 } 0055 } 0056 } 0057 } 0058 0059 property Kirigami.Action trendingTagsAction: Kirigami.Action { 0060 text: i18n("Tags") 0061 icon.name: "tag-symbolic" 0062 checkable: true 0063 onCheckedChanged: (checked) => { 0064 if (checked) { 0065 if (tagsModel.name.length === 0) { 0066 tagsModel.name = "trending"; 0067 } else { 0068 tagsModel.shouldLoadMore = false; 0069 } 0070 } 0071 } 0072 } 0073 0074 header: Kirigami.NavigationTabBar { 0075 anchors.left: parent.left 0076 anchors.right: parent.right 0077 actions: [tendingPostsAction, trendingTagsAction] 0078 0079 Kirigami.Theme.colorSet: Kirigami.Theme.Window 0080 Kirigami.Theme.inherit: false 0081 } 0082 0083 Component.onCompleted: tendingPostsAction.checked = true 0084 0085 ListView { 0086 id: tagsView 0087 model: tendingPostsAction.checked ? trendingPostsModel : tagsModel 0088 0089 Connections { 0090 target: Navigation 0091 function onOpenFullScreenImage(attachments, identity, currentIndex) { 0092 if (timelinePage.isCurrentPage) { 0093 timelinePage.dialog = fullScreenImage.createObject(parent, { 0094 attachments: attachments, 0095 identity: identity, 0096 initialIndex: currentIndex, 0097 }); 0098 timelinePage.dialog.open(); 0099 } 0100 } 0101 } 0102 0103 Connections { 0104 target: trendingPostsModel 0105 function onPostSourceReady(backend) { 0106 pageStack.layers.push("./StatusComposer/StatusComposer.qml", { 0107 purpose: StatusComposer.Edit, 0108 backend: backend 0109 }); 0110 } 0111 } 0112 0113 Component { 0114 id: fullScreenImage 0115 FullScreenImage {} 0116 } 0117 0118 Component { 0119 id: trendingPostsModelComponent 0120 0121 StatusDelegate { 0122 width: ListView.view.width 0123 timelineModel: tagsView.model 0124 loading: tagsView.model.loading 0125 showSeparator: index !== tagsView.count - 1 0126 } 0127 } 0128 0129 Component { 0130 id: trendingTagsModelComponent 0131 0132 Delegates.RoundedItemDelegate { 0133 id: delegate 0134 0135 required property string name 0136 required property url url 0137 required property var history 0138 0139 width: ListView.view.width 0140 0141 onClicked: pageStack.push(tagModelComponent, { hashtag: delegate.name }) 0142 0143 contentItem: ColumnLayout { 0144 Kirigami.Heading { 0145 level: 4 0146 text: `#${delegate.name}` 0147 type: Kirigami.Heading.Type.Primary 0148 verticalAlignment: Text.AlignTop 0149 elide: Text.ElideRight 0150 textFormat: Text.RichText 0151 Layout.fillWidth: true 0152 } 0153 0154 QQC2.Label { 0155 font.pixelSize: Config.defaultFont.pixelSize + 1 0156 Layout.fillWidth: true 0157 elide: Text.ElideRight 0158 color: Kirigami.Theme.disabledTextColor 0159 text: i18np("%1 person is talking", "%1 people are talking", delegate.history[0].accounts) 0160 verticalAlignment: Text.AlignTop 0161 } 0162 } 0163 } 0164 } 0165 0166 delegate: tendingPostsAction.checked ? trendingPostsModelComponent : trendingTagsModelComponent 0167 0168 QQC2.ProgressBar { 0169 visible: tagsView.model.loading && tagsView.count === 0 0170 anchors.centerIn: parent 0171 indeterminate: true 0172 } 0173 0174 Kirigami.PlaceholderMessage { 0175 anchors.centerIn: parent 0176 text: tendingPostsAction.checked ? i18nc("@label", "No Trending Posts") : i18nc("@label", "No Trending Tags") 0177 visible: !tagsView.model.loading && tagsView.count === 0 0178 width: parent.width - (Kirigami.Units.largeSpacing * 4) 0179 } 0180 } 0181 }