Compare commits
	
		
			2 Commits 
		
	
	
		
			8c1a284151
			...
			0ac847c88c
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								 | 
						0ac847c88c | |
| 
							
							
								 | 
						6f7eed1e81 | 
| 
						 | 
				
			
			@ -88,7 +88,7 @@ struct Pane: View {
 | 
			
		|||
    @State var width: CGFloat
 | 
			
		||||
    @State var height: CGFloat
 | 
			
		||||
 | 
			
		||||
    @State var dragOffset = CGFloat()
 | 
			
		||||
    var dragOffset = CGFloat()
 | 
			
		||||
 | 
			
		||||
    @State var refresh: Bool = false
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -119,8 +119,7 @@ struct Pane: View {
 | 
			
		|||
                               destRibbon: selectedRibbon[0],
 | 
			
		||||
                               appDatabase: appDatabase,
 | 
			
		||||
                               paneConnector: paneConnector,
 | 
			
		||||
                               loading: true,
 | 
			
		||||
                               bump: false)
 | 
			
		||||
                               loading: true)
 | 
			
		||||
                }
 | 
			
		||||
                .onChange(of: paneConnector.refresh) { _ in
 | 
			
		||||
                    print("inside change")
 | 
			
		||||
| 
						 | 
				
			
			@ -178,8 +177,8 @@ struct Pane: View {
 | 
			
		|||
                    //     let reactive = self.paneConnector
 | 
			
		||||
                    // }
 | 
			
		||||
 | 
			
		||||
                    if paneConnector.setScrollOffset != nil {
 | 
			
		||||
                        DispatchQueue.main.async {
 | 
			
		||||
                    if paneConnector.setScrollOffset != nil {
 | 
			
		||||
                            scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
 | 
			
		||||
                            paneConnector.setScrollOffset = nil
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -236,7 +235,10 @@ struct Pane: View {
 | 
			
		|||
        currentId = tracker.sortedViewIDs[0]
 | 
			
		||||
        currentOffset = tracker.visibleViews[currentId!]!
 | 
			
		||||
 | 
			
		||||
        self.paneConnector.currentId = tracker.sortedViewIDs[0]
 | 
			
		||||
        if self.paneConnector.currentId != tracker.sortedViewIDs[0] {
 | 
			
		||||
            self.paneConnector.currentId = tracker.sortedViewIDs[0]
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        self.paneConnector.currentOffset = tracker.visibleViews[currentId!]!
 | 
			
		||||
 | 
			
		||||
        if self.paneConnector.currentId == self.paneConnector.scrollId
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,9 +8,6 @@ struct NaviBar: View {
 | 
			
		|||
    @ObservedObject var paneConnector: PaneConnector
 | 
			
		||||
 | 
			
		||||
    @Query(RibbonRequest(dir: .prev, groupId: 1)) private var backRibbon: [Ribbon]
 | 
			
		||||
 | 
			
		||||
    // @Query(RibbonRequest(dir: .current, groupId: 1)) private var currentRibbon: [Ribbon]
 | 
			
		||||
 | 
			
		||||
    @Query(RibbonRequest(dir: .next, groupId: 1)) private var nextRibbon: [Ribbon]
 | 
			
		||||
 | 
			
		||||
    @Query(SelectedRibbonRequest()) private var selectedRibbon: [Ribbon]
 | 
			
		||||
| 
						 | 
				
			
			@ -20,7 +17,7 @@ struct NaviBar: View {
 | 
			
		|||
    var body: some View {
 | 
			
		||||
        VStack {
 | 
			
		||||
            HStack {
 | 
			
		||||
                //Print("meow navi reloaded back ribbon: \(backRibbon[0])")
 | 
			
		||||
                // Print("meow navi reloaded back ribbon: \(backRibbon[0])")
 | 
			
		||||
 | 
			
		||||
                Print("rendering navi")
 | 
			
		||||
                Print("dog backRibbon: \(backRibbon)")
 | 
			
		||||
| 
						 | 
				
			
			@ -32,67 +29,37 @@ struct NaviBar: View {
 | 
			
		|||
                    .if(!paneConnector.hasMoved) { $0.foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) }
 | 
			
		||||
                    .onTapGesture {
 | 
			
		||||
                        Task {
 | 
			
		||||
                            if backRibbon.count == 0 {
 | 
			
		||||
                                return
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            var br = backRibbon[0]
 | 
			
		||||
                            var sr = selectedRibbon[0]
 | 
			
		||||
 | 
			
		||||
                            do {
 | 
			
		||||
                                if paneConnector.hasMoved {
 | 
			
		||||
                                // if true {
 | 
			
		||||
                                    print("has moved")
 | 
			
		||||
 | 
			
		||||
                                    let updatedRibbon = try await createUndoState(selectedRibbon: sr,
 | 
			
		||||
                                                          appDatabase: appDatabase,
 | 
			
		||||
                                                          paneConnector: paneConnector)
 | 
			
		||||
                                                                                  appDatabase: appDatabase,
 | 
			
		||||
                                                                                  paneConnector: paneConnector)
 | 
			
		||||
                                    goToRibbon(selectedRibbon: sr,
 | 
			
		||||
                                               destRibbon: sr,
 | 
			
		||||
                                               appDatabase: appDatabase,
 | 
			
		||||
                                               paneConnector: paneConnector,
 | 
			
		||||
                                               loading: false,
 | 
			
		||||
                                               bump: true)
 | 
			
		||||
                                               loading: false)
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    if backRibbon.count == 0 {
 | 
			
		||||
                                        return
 | 
			
		||||
                                    }
 | 
			
		||||
 | 
			
		||||
                                    try await appDatabase.undoRibbon(&sr)
 | 
			
		||||
 | 
			
		||||
                                    goToRibbon(selectedRibbon: sr,
 | 
			
		||||
                                               destRibbon: br,
 | 
			
		||||
                                               appDatabase: appDatabase,
 | 
			
		||||
                                               paneConnector: paneConnector,
 | 
			
		||||
                                               loading: false,
 | 
			
		||||
                                               bump: true)
 | 
			
		||||
 | 
			
		||||
                                               loading: false)
 | 
			
		||||
                                }
 | 
			
		||||
 | 
			
		||||
                                // var sr = try await appDatabase.getSelectedRibbon()
 | 
			
		||||
                                // print("meow first sr:\(sr)")
 | 
			
		||||
                                // print("meow first selectedRibbon:\(selectedRibbon[0])")
 | 
			
		||||
 | 
			
		||||
                                // try await appDatabase.dbWriter.write { db in
 | 
			
		||||
                                //     var ribs = RibbonRequest().fetchValue(db)
 | 
			
		||||
                                // }
 | 
			
		||||
 | 
			
		||||
                                // try await updateRibbon(selectedRibbon: selectedRibbon[0],
 | 
			
		||||
                                //              appDatabase: appDatabase,
 | 
			
		||||
                                //              paneConnector: paneConnector)
 | 
			
		||||
 | 
			
		||||
                                // print("meow back from update in main")
 | 
			
		||||
                                // sr = try await appDatabase.getSelectedRibbon()
 | 
			
		||||
                                // print("meow second sr:\(sr)")
 | 
			
		||||
                                // print("meow backribbon br:\(br)")
 | 
			
		||||
 | 
			
		||||
                                // _ = try await appDatabase.undoRibbon(&sr[0])
 | 
			
		||||
 | 
			
		||||
                                // goToRibbon(selectedRibbon: sr[0],
 | 
			
		||||
                                //            destRibbon: br,
 | 
			
		||||
                                //            appDatabase: appDatabase,
 | 
			
		||||
                                //            paneConnector: paneConnector,
 | 
			
		||||
                                //            loading: false,
 | 
			
		||||
                                //            bump:false)
 | 
			
		||||
 | 
			
		||||
                            } catch {
 | 
			
		||||
                                print("back 2 error")
 | 
			
		||||
                                print("Error info: \(error)")
 | 
			
		||||
                                print("Back Arrow Error info: \(error)")
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
| 
						 | 
				
			
			@ -101,6 +68,23 @@ struct NaviBar: View {
 | 
			
		|||
                    .frame(width: CGFloat(30), height: CGFloat(30))
 | 
			
		||||
                    .background(Color(red: 0.1, green: 0.1, blue: 0.1))
 | 
			
		||||
                    .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
 | 
			
		||||
                    .onTapGesture {
 | 
			
		||||
                        if nextRibbon.count == 0 {
 | 
			
		||||
                            return
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        Task {
 | 
			
		||||
                            var sr = selectedRibbon[0]
 | 
			
		||||
                            var nr = nextRibbon[0]
 | 
			
		||||
                            try await appDatabase.redoRibbon(&sr)
 | 
			
		||||
 | 
			
		||||
                            goToRibbon(selectedRibbon: sr,
 | 
			
		||||
                                       destRibbon: nr,
 | 
			
		||||
                                       appDatabase: appDatabase,
 | 
			
		||||
                                       paneConnector: paneConnector,
 | 
			
		||||
                                       loading: false)
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
            }
 | 
			
		||||
            .cornerRadius(5)
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -218,6 +218,31 @@ extension AppDatabase {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    func redoRibbon(_ ribbon: inout Ribbon) async throws {
 | 
			
		||||
        let currentLevel = ribbon.currentLevel
 | 
			
		||||
        let minLevel = ribbon.maxLevel
 | 
			
		||||
 | 
			
		||||
        if currentLevel == minLevel {
 | 
			
		||||
            print("no where to redo")
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let newCurrent = (ribbon.currentLevel + 1) %% totalLevels
 | 
			
		||||
 | 
			
		||||
        do {
 | 
			
		||||
            try await dbWriter.write { [ribbon] db in
 | 
			
		||||
                try db.execute(sql: """
 | 
			
		||||
                               UPDATE Ribbon  \
 | 
			
		||||
                               SET currentLevel = ? WHERE groupId = ?
 | 
			
		||||
                               """, arguments: [newCurrent, ribbon.groupId])
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        } catch {
 | 
			
		||||
            print("Redo Ribbon Error info: \(error)")
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // this sets the current undoLevel to the previous value
 | 
			
		||||
    // if you can go back
 | 
			
		||||
    func undoRibbon(_ ribbon: inout Ribbon) async throws {
 | 
			
		||||
| 
						 | 
				
			
			@ -237,12 +262,6 @@ extension AppDatabase {
 | 
			
		|||
                               UPDATE Ribbon  \
 | 
			
		||||
                               SET currentLevel = ? WHERE groupId = ?
 | 
			
		||||
                               """, arguments: [newCurrent, ribbon.groupId])
 | 
			
		||||
 | 
			
		||||
                var ret3 = try Ribbon.fetchAll(db, sql: """
 | 
			
		||||
                               SELECT * from Ribbon \
 | 
			
		||||
                               WHERE groupId = ?
 | 
			
		||||
                               """, arguments: [ribbon.groupId])
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        } catch {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,8 +72,7 @@ func goToRibbon(selectedRibbon: Ribbon,
 | 
			
		|||
                destRibbon: Ribbon,
 | 
			
		||||
                appDatabase: AppDatabase,
 | 
			
		||||
                paneConnector: PaneConnector,
 | 
			
		||||
                loading: Bool,
 | 
			
		||||
                bump: Bool)
 | 
			
		||||
                loading: Bool)
 | 
			
		||||
{
 | 
			
		||||
    print("meow goto ribbon - selected ribbon: \(selectedRibbon), dest ribbon: \(destRibbon) ")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -112,26 +111,6 @@ func goToRibbon(selectedRibbon: Ribbon,
 | 
			
		|||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // // this gets run regardless of if we switch ribbons or not
 | 
			
		||||
            // // so if you click the same ribbon or a different ribbon
 | 
			
		||||
            // if !loading || bump {
 | 
			
		||||
            //     print("not loading")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            //     print("saving ribbon")
 | 
			
		||||
            //     // updating the ribbon location
 | 
			
		||||
            //     updatedRibbon.scrollOffset = Int(floor(scrollOffsetToSave))
 | 
			
		||||
            //     updatedRibbon.scrollId = scrollIdToSave
 | 
			
		||||
            //     // updatedRibbon.undoLevel = updatedRibbon.undoLevel + 1
 | 
			
		||||
            //     // updatedRibbon.currentLevel = updatedRibbon.currentLevel + 1
 | 
			
		||||
 | 
			
		||||
            //     if bump {
 | 
			
		||||
            //         _ = try await appDatabase.bumpRibbon(&updatedRibbon)
 | 
			
		||||
            //     }
 | 
			
		||||
 | 
			
		||||
            // } else {
 | 
			
		||||
            //     print("loading")
 | 
			
		||||
            // }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -202,8 +181,7 @@ struct RibbonCrown: View {
 | 
			
		|||
                               destRibbon: ribbon,
 | 
			
		||||
                               appDatabase: appDatabase,
 | 
			
		||||
                               paneConnector: paneConnector,
 | 
			
		||||
                               loading: false,
 | 
			
		||||
                               bump: true)
 | 
			
		||||
                               loading: false)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -271,6 +249,8 @@ struct ContentView: View {
 | 
			
		|||
    @State var draggedRibbon: Ribbon?
 | 
			
		||||
    @State var isDragging = false
 | 
			
		||||
 | 
			
		||||
    @State var dragOffset = CGFloat(0)
 | 
			
		||||
 | 
			
		||||
    @Environment(\.appDatabase) private var appDatabase
 | 
			
		||||
 | 
			
		||||
    @Query(RibbonRequest()) private var ribbons: [Ribbon]
 | 
			
		||||
| 
						 | 
				
			
			@ -331,10 +311,15 @@ struct ContentView: View {
 | 
			
		|||
 | 
			
		||||
                VStack {
 | 
			
		||||
                    // Top pane
 | 
			
		||||
 | 
			
		||||
                    // if viewState.width > -50 {
 | 
			
		||||
                    //     dragOffset = viewState.width + pulledOut.width + 50
 | 
			
		||||
                    // }
 | 
			
		||||
                    Pane(paneConnector: paneConnector,
 | 
			
		||||
                         selectedRibbon: selectedRibbon,
 | 
			
		||||
                         width: geometry.size.width - 50,
 | 
			
		||||
                         height: geometry.size.height / 2)
 | 
			
		||||
                         height: geometry.size.height / 2,
 | 
			
		||||
                         dragOffset: dragOffset)
 | 
			
		||||
                    //////
 | 
			
		||||
 | 
			
		||||
                    Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
 | 
			
		||||
| 
						 | 
				
			
			@ -391,8 +376,9 @@ struct ContentView: View {
 | 
			
		|||
                .gesture(
 | 
			
		||||
                    DragGesture()
 | 
			
		||||
                        .onChanged { gesture in
 | 
			
		||||
                            let margin = CGFloat(50)
 | 
			
		||||
 | 
			
		||||
                            print(viewState.width)
 | 
			
		||||
                            print("mao viewState :\(viewState.width)")
 | 
			
		||||
                            print(pulledOut.width)
 | 
			
		||||
                            // threshold of how much to swipe before the view drags
 | 
			
		||||
                            if abs(gesture.translation.width) > 10 {
 | 
			
		||||
| 
						 | 
				
			
			@ -400,21 +386,45 @@ struct ContentView: View {
 | 
			
		|||
                                // if gesture.translation.width < -50, pulledOut.width == CGFloat(0) {
 | 
			
		||||
                                // }
 | 
			
		||||
                            }
 | 
			
		||||
                            if viewState.width < -50 && pulledOut.width <= 0 {
 | 
			
		||||
                                dragOffset = margin + viewState.width + pulledOut.width
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                            if viewState.width > 0 && pulledOut.width != 0 {
 | 
			
		||||
                                dragOffset = margin + viewState.width + pulledOut.width
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        .onEnded { _ in
 | 
			
		||||
                            let pulledOutRight = CGFloat(-300)
 | 
			
		||||
                            let pulledOutLeft = CGFloat(200)
 | 
			
		||||
                            let margin = CGFloat(50)
 | 
			
		||||
 | 
			
		||||
                            var setPulledOutWith = CGFloat(0)
 | 
			
		||||
                            var setDragOffset = CGFloat(0)
 | 
			
		||||
                            if viewState.width < 0 && pulledOut.width > 0 {
 | 
			
		||||
                                setPulledOutWith = CGFloat(0)
 | 
			
		||||
                            } else if viewState.width > 0 && pulledOut.width < 0 {
 | 
			
		||||
                                setPulledOutWith = CGFloat(0)
 | 
			
		||||
                            } else if viewState.width < 0 && pulledOut.width == 0 {
 | 
			
		||||
                                setPulledOutWith = CGFloat(-300)
 | 
			
		||||
                                setPulledOutWith = pulledOutRight
 | 
			
		||||
                                setDragOffset = margin +  setPulledOutWith
 | 
			
		||||
                            } else if abs(viewState.width + pulledOut.width) > 30 {
 | 
			
		||||
                                setPulledOutWith = CGFloat(200)
 | 
			
		||||
                                setPulledOutWith = pulledOutLeft
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            // if setPulledOutWith < 0 {
 | 
			
		||||
                            //     setDragOffset = CGFloat(50) +  setPulledOutWith
 | 
			
		||||
                            // } else if setPulledOutWith > 0 {
 | 
			
		||||
                            //     setDragOffset = setPulledOutWith
 | 
			
		||||
                            // } else {
 | 
			
		||||
                            //     setDragOffset = .zero
 | 
			
		||||
                            // }
 | 
			
		||||
 | 
			
		||||
                            print("mao setPulledOutWith \(setPulledOutWith)")
 | 
			
		||||
                            withAnimation(.spring(response: 0.2)) {
 | 
			
		||||
                                pulledOut.width = setPulledOutWith
 | 
			
		||||
                                dragOffset = setDragOffset
 | 
			
		||||
                                viewState = .zero
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue