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