refactor timeline and nav
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
4C75EFB728049D990006080F /* RelayPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB628049D990006080F /* RelayPool.swift */; };
|
4C75EFB728049D990006080F /* RelayPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB628049D990006080F /* RelayPool.swift */; };
|
||||||
4C75EFB92804A2740006080F /* EventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB82804A2740006080F /* EventView.swift */; };
|
4C75EFB92804A2740006080F /* EventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB82804A2740006080F /* EventView.swift */; };
|
||||||
4C75EFBB2804A34C0006080F /* ProofOfWork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFBA2804A34C0006080F /* ProofOfWork.swift */; };
|
4C75EFBB2804A34C0006080F /* ProofOfWork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFBA2804A34C0006080F /* ProofOfWork.swift */; };
|
||||||
|
4CA2EFA0280E37AC0044ACD8 /* TimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */; };
|
||||||
4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */; };
|
4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */; };
|
||||||
4CACA9DC280C38C000D9BBE8 /* Profiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9DB280C38C000D9BBE8 /* Profiles.swift */; };
|
4CACA9DC280C38C000D9BBE8 /* Profiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9DB280C38C000D9BBE8 /* Profiles.swift */; };
|
||||||
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE6DEE627F7A08100C66700 /* damusApp.swift */; };
|
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE6DEE627F7A08100C66700 /* damusApp.swift */; };
|
||||||
@@ -68,6 +69,7 @@
|
|||||||
4C75EFB628049D990006080F /* RelayPool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayPool.swift; sourceTree = "<group>"; };
|
4C75EFB628049D990006080F /* RelayPool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayPool.swift; sourceTree = "<group>"; };
|
||||||
4C75EFB82804A2740006080F /* EventView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventView.swift; sourceTree = "<group>"; };
|
4C75EFB82804A2740006080F /* EventView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventView.swift; sourceTree = "<group>"; };
|
||||||
4C75EFBA2804A34C0006080F /* ProofOfWork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProofOfWork.swift; sourceTree = "<group>"; };
|
4C75EFBA2804A34C0006080F /* ProofOfWork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProofOfWork.swift; sourceTree = "<group>"; };
|
||||||
|
4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineView.swift; sourceTree = "<group>"; };
|
||||||
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyView.swift; sourceTree = "<group>"; };
|
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyView.swift; sourceTree = "<group>"; };
|
||||||
4CACA9DB280C38C000D9BBE8 /* Profiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profiles.swift; sourceTree = "<group>"; };
|
4CACA9DB280C38C000D9BBE8 /* Profiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profiles.swift; sourceTree = "<group>"; };
|
||||||
4CE6DEE327F7A08100C66700 /* damus.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = damus.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
4CE6DEE327F7A08100C66700 /* damus.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = damus.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
@@ -131,6 +133,7 @@
|
|||||||
4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */,
|
4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */,
|
||||||
4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */,
|
4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */,
|
||||||
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */,
|
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */,
|
||||||
|
4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */,
|
||||||
);
|
);
|
||||||
path = Views;
|
path = Views;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -367,6 +370,7 @@
|
|||||||
4C75EFB92804A2740006080F /* EventView.swift in Sources */,
|
4C75EFB92804A2740006080F /* EventView.swift in Sources */,
|
||||||
4C75EFA627FF87A20006080F /* Nostr.swift in Sources */,
|
4C75EFA627FF87A20006080F /* Nostr.swift in Sources */,
|
||||||
4C75EFB328049D640006080F /* NostrEvent.swift in Sources */,
|
4C75EFB328049D640006080F /* NostrEvent.swift in Sources */,
|
||||||
|
4CA2EFA0280E37AC0044ACD8 /* TimelineView.swift in Sources */,
|
||||||
4C75EFB128049D510006080F /* NostrResponse.swift in Sources */,
|
4C75EFB128049D510006080F /* NostrResponse.swift in Sources */,
|
||||||
4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */,
|
4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */,
|
||||||
4CEE2B02280B39E800AB5EEF /* EventActionBar.swift in Sources */,
|
4CEE2B02280B39E800AB5EEF /* EventActionBar.swift in Sources */,
|
||||||
|
|||||||
@@ -24,58 +24,44 @@ enum Sheets: Identifiable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Timeline {
|
enum Timeline: String, CustomStringConvertible {
|
||||||
case friends
|
case home
|
||||||
case global
|
case notifications
|
||||||
case debug
|
|
||||||
|
var description: String {
|
||||||
|
return self.rawValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@State var status: String = "Not connected"
|
@State var status: String = "Not connected"
|
||||||
@State var active_sheet: Sheets? = nil
|
@State var active_sheet: Sheets? = nil
|
||||||
@State var events: [NostrEvent] = []
|
|
||||||
@State var profiles: Profiles = Profiles()
|
@State var profiles: Profiles = Profiles()
|
||||||
@State var friends: [String: ()] = [:]
|
@State var friends: [String: ()] = [:]
|
||||||
@State var has_events: [String: ()] = [:]
|
|
||||||
@State var profile_count: Int = 0
|
|
||||||
@State var last_event_of_kind: [Int: NostrEvent] = [:]
|
|
||||||
@State var loading: Bool = true
|
@State var loading: Bool = true
|
||||||
@State var timeline: Timeline = .friends
|
|
||||||
@State var pool: RelayPool? = nil
|
@State var pool: RelayPool? = nil
|
||||||
|
@State var selected_timeline: Timeline? = .home
|
||||||
|
@State var last_event_of_kind: [Int: NostrEvent] = [:]
|
||||||
|
@State var has_events: [String: ()] = [:]
|
||||||
|
|
||||||
|
@State var events: [NostrEvent] = []
|
||||||
|
@State var notifications: [NostrEvent] = []
|
||||||
|
|
||||||
let sub_id = UUID().description
|
let sub_id = UUID().description
|
||||||
let pubkey = "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"
|
let pubkey = "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"
|
||||||
|
|
||||||
func MainContent(pool: RelayPool) -> some View {
|
|
||||||
ScrollView {
|
|
||||||
ForEach(self.events, id: \.id) { (ev: NostrEvent) in
|
|
||||||
if ev.is_local && timeline == .debug || (timeline == .global && !ev.is_local) || (timeline == .friends && is_friend(ev.pubkey)) {
|
|
||||||
let evdet = EventDetailView(event: ev, pool: pool)
|
|
||||||
.navigationBarTitle("Thread")
|
|
||||||
.environmentObject(profiles)
|
|
||||||
NavigationLink(destination: evdet) {
|
|
||||||
EventView(event: ev, highlight: .none, has_action_bar: true)
|
|
||||||
}
|
|
||||||
.buttonStyle(PlainButtonStyle())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.environmentObject(profiles)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TimelineButton(timeline: Timeline, img: String) -> some View {
|
func TimelineButton(timeline: Timeline, img: String) -> some View {
|
||||||
Button(action: {switch_timeline(timeline)}) {
|
NavigationLink(destination: Text("\(timeline.description)"), tag: timeline, selection: $selected_timeline){
|
||||||
Label("", systemImage: img)
|
Label("", systemImage: img)
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
.foregroundColor(self.timeline != timeline ? .gray : .primary)
|
.foregroundColor(selected_timeline != timeline ? .gray : .primary)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TopBar(selected: Timeline) -> some View {
|
func TopBar(selected: Timeline) -> some View {
|
||||||
HStack {
|
HStack {
|
||||||
TimelineButton(timeline: .friends, img: selected == .friends ? "person.2.fill" : "person.2")
|
TimelineButton(timeline: .home, img: selected == .home ? "house.fill" : "house")
|
||||||
TimelineButton(timeline: .global, img: selected == .global ? "globe.americas.fill" : "globe.americas")
|
TimelineButton(timeline: .notifications, img: selected == .notifications ? "bell.fill" : "bell")
|
||||||
TimelineButton(timeline: .debug, img: selected == .debug ? "wrench.fill" : "wrench")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,24 +79,26 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
VStack {
|
||||||
VStack {
|
if self.loading {
|
||||||
if self.loading {
|
ProgressView()
|
||||||
ProgressView()
|
.progressViewStyle(.circular)
|
||||||
.progressViewStyle(.circular)
|
.padding([.bottom], 4)
|
||||||
.padding([.bottom], 4)
|
}
|
||||||
}
|
|
||||||
|
NavigationView {
|
||||||
ZStack {
|
ZStack {
|
||||||
if let pool = self.pool {
|
if let pool = self.pool {
|
||||||
MainContent(pool: pool)
|
TimelineView(events: $events, pool: pool)
|
||||||
|
.environmentObject(profiles)
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
PostButtonContainer
|
PostButtonContainer
|
||||||
}
|
}
|
||||||
TopBar(selected: self.timeline ?? .friends)
|
.navigationBarTitle("Damus", displayMode: .inline)
|
||||||
}
|
}
|
||||||
.navigationBarTitle("Damus", displayMode: .inline)
|
|
||||||
|
TopBar(selected: selected_timeline ?? .home)
|
||||||
}
|
}
|
||||||
.onAppear() {
|
.onAppear() {
|
||||||
self.connect()
|
self.connect()
|
||||||
@@ -135,7 +123,7 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func switch_timeline(_ timeline: Timeline) {
|
func switch_timeline(_ timeline: Timeline) {
|
||||||
self.timeline = timeline
|
self.selected_timeline = timeline
|
||||||
}
|
}
|
||||||
|
|
||||||
func add_relay(_ pool: RelayPool, _ relay: String) {
|
func add_relay(_ pool: RelayPool, _ relay: String) {
|
||||||
@@ -294,7 +282,6 @@ struct ContentView_Previews: PreviewProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func get_metadata_since_time(_ metadata_event: NostrEvent?) -> Int64? {
|
func get_metadata_since_time(_ metadata_event: NostrEvent?) -> Int64? {
|
||||||
if metadata_event == nil {
|
if metadata_event == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
38
damus/Views/TimelineView.swift
Normal file
38
damus/Views/TimelineView.swift
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
//
|
||||||
|
// TimelineView.swift
|
||||||
|
// damus
|
||||||
|
//
|
||||||
|
// Created by William Casarin on 2022-04-18.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct TimelineView: View {
|
||||||
|
@Binding var events: [NostrEvent]
|
||||||
|
@EnvironmentObject var profiles: Profiles
|
||||||
|
|
||||||
|
let pool: RelayPool
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ScrollView {
|
||||||
|
ForEach(events, id: \.id) { (ev: NostrEvent) in
|
||||||
|
let evdet = EventDetailView(event: ev, pool: pool)
|
||||||
|
.navigationBarTitle("Thread")
|
||||||
|
.environmentObject(profiles)
|
||||||
|
NavigationLink(destination: evdet) {
|
||||||
|
EventView(event: ev, highlight: .none, has_action_bar: true)
|
||||||
|
}
|
||||||
|
.buttonStyle(PlainButtonStyle())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.environmentObject(profiles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
struct TimelineView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
TimelineView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user