-
Notifications
You must be signed in to change notification settings - Fork 0
/
Explore.swift
101 lines (97 loc) · 5.37 KB
/
Explore.swift
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
//
// Explore.swift
// wasteof.money
//
// Created by Oren Lindsey on 12/1/23.
//
import SwiftUI
struct Explore: View {
let timeframeOptions = ["day", "week", "month", "all"]
@State private var selection = "day"
@EnvironmentObject var session: Session
@StateObject var explore: ExploreObject
@StateObject var exploreusers: ExploreUsersObject
var body: some View {
NavigationStack {
ScrollView {
if (explore.posts.count < 1) {
ProgressView()
} else {
HStack {
Text("Top Posts")
.padding([.horizontal])
.font(.title2)
Spacer()
}
ForEach(explore.posts.indices, id: \.self) { i in
let post = explore.posts[i]
NavigationLink {
Post(commentsState: CommentsObject(), _id: post._id, content: post.content, time: post.time, comments: post.comments, loves: post.loves, reposts: post.reposts, poster: post.poster, revisions: post.revisions, repost: post.repost, pinType: true)
} label: {
PostPreview(_id: post._id, content: post.content, time: post.time, comments: post.comments, loves: post.loves, reposts: post.reposts, poster: Poster(name: post.poster.name, id: post.poster.id, color: post.poster.color), revisions: post.revisions, edited: post.edited, repost: post.repost, navigation: true, pinType: true, recursion: 1).environmentObject(session).frame(minHeight: 100)
}
}.padding([.horizontal], 8)
}
if (exploreusers.users.count < 1) {
EmptyView()
} else {
HStack {
Text("Top Users")
.padding([.horizontal])
.font(.title2)
Spacer()
}
let exploreusers = exploreusers
VStack {
NavigationStack {
ForEach(exploreusers.users.indices, id: \.self) { i in
if i == exploreusers.users.count - 1 {
NavigationLink {
User(name: exploreusers.users[i].name, navigationType: "stack").environmentObject(session)
} label: {
UserPreview(name: exploreusers.users[i].name, id: exploreusers.users[i].id, bio: exploreusers.users[i].bio, verified: exploreusers.users[i].verified, beta: exploreusers.users[i].beta, permissions: exploreusers.users[i].permissions, links: exploreusers.users[i].links, history: exploreusers.users[i].history ?? History(joined: 0), stats: exploreusers.users[i].stats, color: exploreusers.users[i].color)
.padding([.bottom], 96)
}.buttonStyle(PlainButtonStyle())
} else {
NavigationLink {
User(name: exploreusers.users[i].name, navigationType: "stack").environmentObject(session)
} label: {
UserPreview(name: exploreusers.users[i].name, id: exploreusers.users[i].id, bio: exploreusers.users[i].bio, verified: exploreusers.users[i].verified, beta: exploreusers.users[i].beta, permissions: exploreusers.users[i].permissions, links: exploreusers.users[i].links, history: exploreusers.users[i].history ?? History(joined: 0), stats: exploreusers.users[i].stats, color: exploreusers.users[i].color)
}.buttonStyle(PlainButtonStyle())
}
}
}
}.padding([.horizontal], 8)
}
}.ignoresSafeArea(.all, edges: [.bottom, .horizontal]).refreshable {
fetchExplore(timeframe: selection) { exploreobject in
explore.posts = exploreobject.posts
explore.since = exploreobject.since
}
fetchUsers() { users in
exploreusers.users = users
}
}.navigationTitle("Explore").toolbar {
ToolbarItemGroup(placement: .primaryAction) {
Menu {
Picker("Select a timeframe", selection: $selection) {
ForEach(timeframeOptions, id: \.self) {
/*Text($0)
}*/
Text($0)
}
}
//}
} label: {
Label("Sort", systemImage: "line.3.horizontal.decrease.circle.fill")
}.onChange(of: selection) {
fetchExplore(timeframe: selection) { exploreobject in
explore.posts = exploreobject.posts
explore.since = exploreobject.since
}
}
}
}
}
}
}