Add description view to macOS
This commit is contained in:
parent
f920e3aa9e
commit
145f635768
3 changed files with 48 additions and 66 deletions
|
@ -75,44 +75,22 @@ struct ProfileView: View {
|
||||||
.navigationBarItems(trailing: NavigationLink(destination: DescriptionView(username: username)) {
|
.navigationBarItems(trailing: NavigationLink(destination: DescriptionView(username: username)) {
|
||||||
Text("Sidebar")
|
Text("Sidebar")
|
||||||
})
|
})
|
||||||
.onAppear {
|
.onAppear(perform: load)
|
||||||
let url = URL(string: "https://www.pillowfort.social/" + self.username + "/json")!
|
|
||||||
|
|
||||||
URLSession.shared.dataTask(with: url) { (data, response, error) in
|
|
||||||
do {
|
|
||||||
if let jsonData = data {
|
|
||||||
struct Posts : Decodable {
|
|
||||||
let posts: [Post]
|
|
||||||
}
|
|
||||||
|
|
||||||
let decoder = JSONDecoder()
|
|
||||||
decoder.keyDecodingStrategy = .convertFromSnakeCase
|
|
||||||
|
|
||||||
let decodedPosts = try decoder.decode(Posts.self, from: jsonData)
|
|
||||||
|
|
||||||
var postArray = [ParsedPostContainer]()
|
|
||||||
|
|
||||||
for post in decodedPosts.posts {
|
|
||||||
let container = ParsedPostContainer(post: post, contentAttributed: (try? NSMutableAttributedString(data: post.getContent().data(using: .utf8)!, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil))!)
|
|
||||||
postArray.append(container)
|
|
||||||
}
|
|
||||||
|
|
||||||
DispatchQueue.main.sync {
|
|
||||||
self.posts = postArray
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
print("\(error)")
|
|
||||||
}
|
|
||||||
}.resume()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
HStack {
|
||||||
List(posts, id: \.post.id) { post in
|
List(posts, id: \.post.id) { post in
|
||||||
PostView(post: post)
|
PostView(post: post)
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear(perform: load)
|
||||||
|
|
||||||
|
DescriptionView(username: username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private func load() {
|
||||||
let url = URL(string: "https://www.pillowfort.social/" + self.username + "/json")!
|
let url = URL(string: "https://www.pillowfort.social/" + self.username + "/json")!
|
||||||
|
|
||||||
URLSession.shared.dataTask(with: url) { (data, response, error) in
|
URLSession.shared.dataTask(with: url) { (data, response, error) in
|
||||||
|
@ -144,8 +122,6 @@ struct ProfileView: View {
|
||||||
}.resume()
|
}.resume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ProfileView_Previews: PreviewProvider {
|
struct ProfileView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
|
|
|
@ -8,7 +8,7 @@ struct MainView: View {
|
||||||
VStack {
|
VStack {
|
||||||
TextField("Username", text: $username)
|
TextField("Username", text: $username)
|
||||||
.disableAutocorrection(true)
|
.disableAutocorrection(true)
|
||||||
//.autocapitalization(.none)
|
.autocapitalization(.none)
|
||||||
NavigationLink(destination: ProfileView(username: username)) {
|
NavigationLink(destination: ProfileView(username: username)) {
|
||||||
Text("Show Feed")
|
Text("Show Feed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,14 @@ struct MainView: View {
|
||||||
@State private var username: String = ""
|
@State private var username: String = ""
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
NavigationView {
|
||||||
VStack {
|
VStack {
|
||||||
ProfileView(username: "redstrate")
|
TextField("Username", text: $username)
|
||||||
|
.disableAutocorrection(true)
|
||||||
|
NavigationLink(destination: ProfileView(username: username)) {
|
||||||
|
Text("Show Feed")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue