Skip to content

Commit

Permalink
👷 CI: Merge dev by GitOK
Browse files Browse the repository at this point in the history
  • Loading branch information
nookery committed Sep 27, 2024
2 parents 3d444c7 + ed5543d commit 4365cb2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
78 changes: 44 additions & 34 deletions App/Views/Content/CommitList.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import MagicKit
import OSLog
import SwiftUI
import MagicKit

struct CommitList: View, SuperThread, SuperLog{
struct CommitList: View, SuperThread, SuperLog {
@EnvironmentObject var app: AppProvider
@EnvironmentObject var g: GitProvider

Expand Down Expand Up @@ -37,42 +37,19 @@ struct CommitList: View, SuperThread, SuperLog{
}
}
}
.onAppear {
refresh("OnAppear")
self.showCommitForm = project.hasUnCommittedChanges()
}
.onChange(of: selection, {
g.setCommit(selection)
})
.onChange(of: g.project, {
self.refresh("\(self.t)Project Changed")
})
.onReceive(NotificationCenter.default.publisher(for: .gitCommitSuccess)) { _ in
guard let project = g.project else {
return
}

let commits = [project.headCommit] + project.getCommits("")

self.main.async {
self.commits = commits
}
}
.onReceive(NotificationCenter.default.publisher(for: .gitPullSuccess)) { _ in
self.refresh("\(self.t)GitPullSuccess")
}
.onReceive(NotificationCenter.default.publisher(for: .gitPushSuccess)) { _ in
self.refresh("\(self.t)GitPushSuccess")
}
// .onReceive(NotificationCenter.default.publisher(for: .appWillBecomeActive)) { _ in
// self.refresh("\(self.label)AppWillBecomeActive")
// }
.onAppear(perform: onAppear)
.onChange(of: selection, onChangeOfSelection)
.onChange(of: g.project, onProjectChange)
.onReceive(NotificationCenter.default.publisher(for: .gitCommitSuccess), perform: onCommitSuccess)
.onReceive(NotificationCenter.default.publisher(for: .gitPullSuccess), perform: onPullSuccess)
.onReceive(NotificationCenter.default.publisher(for: .gitPushSuccess), perform: onPushSuccess)
// .onReceive(NotificationCenter.default.publisher(for: .appWillBecomeActive), perform: onAppWillBecomeActive)
}
}

func refresh(_ reason: String = "") {
let verbose = false

guard let project = g.project, !isRefreshing else {
return
}
Expand All @@ -85,18 +62,51 @@ struct CommitList: View, SuperThread, SuperLog{
if verbose {
os_log("\(t)Refresh(\(reason))")
}

let commits = [project.headCommit] + project.getCommits(reason)

self.main.async {
self.commits = commits
self.loading = false
self.isRefreshing = false
self.showCommitForm = project.hasUnCommittedChanges()
}
}
}
}

// MARK: Event Handlers

extension CommitList {
func onProjectChange() {
self.refresh("\(self.t)Project Changed")
}

func onCommitSuccess(_ notification: Notification) {
self.refresh("\(self.t)GitCommitSuccess")
}

func onAppear() {
refresh("OnAppear")
}

func onChangeOfSelection() {
g.setCommit(selection)
}

func onPullSuccess(_ notification: Notification) {
self.refresh("\(self.t)GitPullSuccess")
}

func onPushSuccess(_ notification: Notification) {
self.refresh("\(self.t)GitPushSuccess")
}

func onAppWillBecomeActive(_ notification: Notification) {
self.refresh("\(self.t)AppWillBecomeActive")
}
}

#Preview {
AppPreview()
.frame(width: 800)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"location" : "https://github.com/CofficLab/MagicKit",
"state" : {
"branch" : "main",
"revision" : "158fd5ff30cf47546f5d433600b86d6d6815b0c4"
"revision" : "409913a41dfffdb4d5f23f31efaf3c669685147f"
}
},
{
Expand Down

0 comments on commit 4365cb2

Please sign in to comment.