Skip to content

Commit

Permalink
添加仓库的关注
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Mar 25, 2024
1 parent 5484915 commit 2af50d9
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 18 deletions.
2 changes: 1 addition & 1 deletion SwiftPamphletApp/Core/FundationFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func wrapperHtmlContent(content: String, codeStyle: String = "lioshi.min") -> St
func howLongAgo(date: Date) -> String {
let simplifiedChinese = Locale(identifier: "zh_Hans")
return date.formatted(.relative(presentation: .named,
unitsStyle: .spellOut).locale(simplifiedChinese))
unitsStyle: .wide).locale(simplifiedChinese))
}
func howLongFromNow(timeStr: String) -> String {
let cn = Region(zone: Zones.asiaShanghai, locale: Locales.chineseChina)
Expand Down
4 changes: 0 additions & 4 deletions SwiftPamphletApp/GitHubAPI/DetailView/RepoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ struct IssuesView: View {
} else {
IssueLabelView(issue: issue)
}
Divider()
} // end ForEach
} // end List
} // end body
Expand All @@ -172,7 +171,6 @@ struct IssueEventsView: View {
} else {
IssueEventLabelView(issueEvent: issueEvent)
}
Divider()
} // end ForEach
} // end List
} // end body
Expand Down Expand Up @@ -201,8 +199,6 @@ struct RepoCommitsView: View {
} else {
RepoCommitLabelView(repo: repo, commit: commit, isUnRead: unReadCount > 0 && i < unReadCount)
}

Divider()
} // end ForEach
} // end List
.frame(minWidth: SPC.detailMinWidth)
Expand Down
15 changes: 13 additions & 2 deletions SwiftPamphletApp/GitHubAPI/Developer/DeveloperListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ struct DeveloperListView: View {
AsyncImageWithPlaceholder(size: .smallSize, url: dev.avatar)
VStack {
HStack {
Text(dev.name)
if dev.repoName.isEmpty {
Text(dev.name)

} else {
VStack(alignment:.leading) {
Text(dev.repoOwner)
.font(.footnote)
.foregroundColor(light: .secondary, dark: .secondary)
Text(dev.repoName)
}
}

Spacer()
Text(howLongAgo(date: dev.updateDate))
.font(.footnote)
Expand Down Expand Up @@ -62,7 +73,7 @@ struct DeveloperListView: View {
}

func addDev() {
let dev = DeveloperModel(name: "", des: "", avatar: "", createDate: Date.now, updateDate: Date.now)
let dev = DeveloperModel(name: "", des: "", avatar: "", repoOwner: "", repoName: "", createDate: Date.now, updateDate: Date.now)
modelContext.insert(dev)
selectDev = dev
}
Expand Down
7 changes: 6 additions & 1 deletion SwiftPamphletApp/GitHubAPI/Developer/DeveloperModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ final class DeveloperModel {
var des: String = ""
var avatar: String = ""

var repoOwner: String = ""
var repoName: String = ""

var createDate: Date = Date.now
var updateDate: Date = Date.now

init(name: String, des: String, avatar: String, createDate: Date, updateDate: Date) {
init(name: String, des: String, avatar: String, repoOwner: String, repoName: String, createDate: Date, updateDate: Date) {
self.name = name
self.des = des
self.avatar = avatar
self.repoOwner = repoOwner
self.repoName = repoName
self.createDate = createDate
self.updateDate = updateDate
}
Expand Down
126 changes: 121 additions & 5 deletions SwiftPamphletApp/GitHubAPI/Developer/EditDeveloper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,142 @@ struct EditDeveloper: View {
@State var vm: UserVM
@State private var tabSelct = 1

@State var vmRepo: RepoVM
@State private var tabSelctRepo = 1


var body: some View {
Form {
HStack {
TextField("用户名:", text: $dev.name, prompt: Text("输入 Github 用户名"))
.onSubmit {
vm = UserVM(userName: dev.name)
vm.doing(.updateAll)
TextField("用户名:", text: $dev.name, prompt: Text("输入 Github 用户名 dev 或仓库名 dev/repo"))
.onChange(of: dev.name) { oldValue, newValue in
let dn = dev.name.components(separatedBy: "/")
if dn.count > 1 {
vmRepo = RepoVM(repoName: dev.name)
vmRepo.doing(.inInit)
dev.repoName = dn.last ?? ""
dev.repoOwner = dn.first ?? ""
} else {
vm = UserVM(userName: dev.name)
vm.doing(.updateAll)
dev.repoName = ""
dev.repoOwner = ""
}
}
TextField("描述:", text: $dev.des)
}
}
.padding(EdgeInsets(top: 10, leading: 10, bottom: 0, trailing: 10))

if dev.name.components(separatedBy: "/").count > 1 {
repoEventView()
} else {
devEventView()
}
}

@ViewBuilder
func repoEventView() -> some View {
HStack {
VStack(alignment: .leading, spacing: 10) {
HStack {
Text(vmRepo.repo.name).font(.system(.largeTitle))
Text("(\(vmRepo.repo.fullName))")
}
HStack {
Image(systemName: "star.fill").foregroundColor(.red)
Text("\(vmRepo.repo.stargazersCount)")
Image(systemName: "tuningfork").foregroundColor(.cyan)
Text("\(vmRepo.repo.forks)")
Text("议题 \(vmRepo.repo.openIssues)")
Text("语言 \(vmRepo.repo.language ?? "")")
ButtonGoGitHubWeb(url: vmRepo.repo.htmlUrl ?? "https:", text: "在 GitHub 上访问")

}
if vmRepo.repo.description != nil {
Text("简介:\(vmRepo.repo.description ?? "")")
}

HStack {
Text("作者:")
AsyncImageWithPlaceholder(size: .smallSize, url: vmRepo.repo.owner.avatarUrl)
ButtonGoGitHubWeb(url: vmRepo.repo.owner.login, text: vmRepo.repo.owner.login, ignoreHost: true)
}
} // end VStack
Spacer()
}
.frame(minWidth: SPC.detailMinWidth)
.onChange(of: vmRepo.repo, { oldValue, newValue in
if !newValue.owner.avatarUrl.isEmpty {
dev.avatar = newValue.owner.avatarUrl
}
})
.onChange(of: vmRepo.commits, { oldValue, newValue in
if ((newValue.first?.commit.author.date.isEmpty) != nil) {
let iso8601String = newValue.first?.commit.author.date ?? ""
let formatter = ISO8601DateFormatter()
dev.updateDate = formatter.date(from: iso8601String) ?? Date.now
}
})
.padding(EdgeInsets(top: 20, leading: 10, bottom: 0, trailing: 10))
.onAppear {
vmRepo.doing(.inInit)
}
// end HStack

TabView(selection: $tabSelct) {
RepoCommitsView(commits: vmRepo.commits, repo: vmRepo.repo)
.tabItem {
Text("新提交")
}
.onAppear {
vmRepo.doing(.inCommit)
}
.tag(1)

IssuesView(issues: vmRepo.issues, repo: vmRepo.repo)
.tabItem {
Text("议题列表")
}
.onAppear {
vmRepo.doing(.inIssues)
}
.tag(2)

IssueEventsView(issueEvents: vmRepo.issueEvents, repo: vmRepo.repo)
.tabItem {
Text("议题事件")
}
.onAppear {
vmRepo.doing(.inIssueEvents)
}
.tag(3)

ReadmeView(content: vmRepo.readme.content.replacingOccurrences(of: "\n", with: ""))
.tabItem {
Text("README")
}
.onAppear {
vmRepo.doing(.inReadme)
}
.tag(4)

} // end TabView
Spacer()
}

@ViewBuilder
func devEventView() -> some View {
HStack {
VStack(alignment: .leading, spacing: 10) {
HStack {
AsyncImageWithPlaceholder(size: .normalSize, url: vm.user.avatarUrl)
VStack(alignment: .leading, spacing: 5) {
HStack {
Text(vm.user.name ?? vm.user.login).font(.system(.title))
Text("(\(vm.user.login))")
if !vm.user.login.isEmpty {
Text("(\(vm.user.login))")
}
Text("订阅者 \(vm.user.followers) 人,仓库 \(vm.user.publicRepos)")
}
HStack {
Expand Down Expand Up @@ -97,6 +212,7 @@ struct EditDeveloper: View {
vm.doing(.inEvent)
}
.tag(1)

DeveloperEventView(events: vm.receivedEvents)
.tabItem {
Image(systemName: "keyboard.badge.ellipsis")
Expand Down
3 changes: 3 additions & 0 deletions SwiftPamphletApp/GitHubAPI/VM/RepoVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ final class RepoVM: APIVMable {
switch somethinglike {
case .inInit:
apRepoSj.send(())
apCommitsSj.send(())
apIssueEventsSj.send(())
apIssuesSj.send(())
case .inCommit:
apCommitsSj.send(())
case .inInitJustRepo:
Expand Down
6 changes: 3 additions & 3 deletions SwiftPamphletApp/HomeUI/DataLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ struct DataLink: Identifiable {
EmptyView()
}
}
case "开发者":
case "开发/仓库":
switch type {
case .content:
DeveloperListView(selectDev:selectDev)
case .detail:
if let dev = selectDevBindable {
if SPC.gitHubAccessToken.isEmpty == false || SPC.githubAccessToken().isEmpty == false {
EditDeveloper(dev: dev, vm: UserVM(userName: dev.name))
EditDeveloper(dev: dev, vm: UserVM(userName: dev.name), vmRepo: RepoVM(repoName: dev.name))
} else {
Text("请在设置里写上 Github 的 access token")
}
Expand Down Expand Up @@ -78,7 +78,7 @@ extension DataLink {
DataLink(title: "资料整理", imageName: "p11")
]),
DataLink(title: "Github", imageName: "", children: [
DataLink(title: "开发者", imageName: "p5"),
DataLink(title: "开发/仓库", imageName: "p5"),
]),
DataLink(title: "Swift指南", imageName: "", children: [
DataLink(title: "语法速查", imageName: "p23"),
Expand Down
4 changes: 2 additions & 2 deletions SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ struct EditInfoView: View {
WebUIView(html: wrapperHtmlContent(content: MarkdownParser().html(from: info.des)), baseURLStr: "")
.tabItem { Label("预览", systemImage: "circle") }
.tag(2)
if !info.url.isEmpty {
WebUIView(urlStr: info.url)
if let url = URL(string: info.url) {
WebUIView(urlStr: url.absoluteString)
.tabItem { Label("网页", systemImage: "circle") }
.tag(3)
}
Expand Down

0 comments on commit 2af50d9

Please sign in to comment.