-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] Implement staffs base #913
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,22 @@ import Theme | |
enum AboutRouting: Hashable { | ||
case contributors | ||
case license | ||
case staffs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nits] |
||
case sponsors | ||
} | ||
|
||
public struct AboutView<ContributorView: View, SponsorView: View>: View { | ||
public struct AboutView<ContributorView: View, StaffView: View, SponsorView: View>: View { | ||
private let contributorViewProvider: ViewProvider<Void, ContributorView> | ||
private let staffViewProvider: ViewProvider<Void, StaffView> | ||
private let sponsorViewProvider: ViewProvider<Void, SponsorView> | ||
|
||
public init( | ||
contributorViewProvider: @escaping ViewProvider<Void, ContributorView>, | ||
staffViewProvider: @escaping ViewProvider<Void, StaffView>, | ||
sponsorViewProvider: @escaping ViewProvider<Void, SponsorView> | ||
) { | ||
self.contributorViewProvider = contributorViewProvider | ||
self.staffViewProvider = staffViewProvider | ||
self.sponsorViewProvider = sponsorViewProvider | ||
} | ||
|
||
|
@@ -56,10 +60,12 @@ public struct AboutView<ContributorView: View, SponsorView: View>: View { | |
.clipShape(RoundedRectangle(cornerRadius: 12)) | ||
Spacer().frame(height: 32) | ||
SectionTitle(title: "Credits") | ||
ListTile( | ||
icon: Assets.Icons.sentimentVerySatisfied.swiftUIImage, | ||
title: "スタッフ" | ||
) | ||
NavigationLink(value: AboutRouting.staffs) { | ||
ListTile( | ||
icon: Assets.Icons.sentimentVerySatisfied.swiftUIImage, | ||
title: "スタッフ" | ||
) | ||
} | ||
Divider() | ||
NavigationLink(value: AboutRouting.contributors) { | ||
ListTile( | ||
|
@@ -123,6 +129,8 @@ public struct AboutView<ContributorView: View, SponsorView: View>: View { | |
switch routing { | ||
case .contributors: | ||
contributorViewProvider(()) | ||
case .staffs: | ||
staffViewProvider(()) | ||
case .sponsors: | ||
sponsorViewProvider(()) | ||
case .license: | ||
|
@@ -136,6 +144,7 @@ public struct AboutView<ContributorView: View, SponsorView: View>: View { | |
#Preview { | ||
AboutView( | ||
contributorViewProvider: {_ in EmptyView()}, | ||
staffViewProvider: {_ in EmptyView()}, | ||
sponsorViewProvider: {_ in EmptyView()} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app-ios/Modules/Sources/KMPContainer/StaffsDataProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Dependencies | ||
import shared | ||
|
||
public struct StaffsDataProvider { | ||
private static var staffRepository: StaffRepository { | ||
Container.shared.get(type: StaffRepository.self) | ||
} | ||
|
||
public let refresh: () async throws -> Void | ||
public let staffs: () -> AsyncThrowingStream<[Staff], Error> | ||
} | ||
|
||
extension StaffsDataProvider: DependencyKey { | ||
@MainActor | ||
public static var liveValue: StaffsDataProvider = StaffsDataProvider( | ||
refresh: { @MainActor in | ||
try await staffRepository.refresh() | ||
}, | ||
staffs: { | ||
staffRepository.staffs().stream() | ||
} | ||
) | ||
|
||
public static var testValue: StaffsDataProvider = StaffsDataProvider( | ||
refresh: {}, | ||
staffs: { | ||
.init { | ||
Staff.companion.fakes() | ||
} | ||
} | ||
) | ||
} | ||
|
||
public extension DependencyValues { | ||
var staffsData: StaffsDataProvider { | ||
get { self[StaffsDataProvider.self] } | ||
set { self[StaffsDataProvider.self] = newValue } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
|
||
public struct IdentifiableURL: Identifiable { | ||
public var id: URL? | ||
|
||
public init(_ id: URL?) { | ||
self.id = id | ||
} | ||
|
||
public init(string: String) { | ||
self.id = URL(string: string) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Component | ||
import Model | ||
import shared | ||
import SwiftUI | ||
|
||
public struct StaffView: View { | ||
@State var presentingURL: IdentifiableURL? | ||
@ObservedObject var viewModel: StaffViewModel = .init() | ||
|
||
public init() {} | ||
|
||
public var body: some View { | ||
Group { | ||
switch viewModel.state.staffs { | ||
case .initial, .loading: | ||
ProgressView() | ||
.task { | ||
await viewModel.load() | ||
} | ||
case .failed: | ||
EmptyView() | ||
case .loaded(let staffs): | ||
ScrollView { | ||
LazyVStack(spacing: 20) { | ||
ForEach(staffs, id: \.id) { staff in | ||
Button { | ||
presentingURL = IdentifiableURL(string: staff.profileUrl) | ||
} label: { | ||
PersonLabel( | ||
name: staff.username, | ||
iconUrlString: staff.iconUrl | ||
) | ||
} | ||
} | ||
} | ||
.padding(16) | ||
} | ||
} | ||
} | ||
.navigationTitle("Staff") | ||
.sheet(item: $presentingURL) { url in | ||
if let url = url.id { | ||
SafariView(url: url) | ||
.ignoresSafeArea() | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
StaffView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Dependencies | ||
import Foundation | ||
import KMPContainer | ||
import Model | ||
import shared | ||
|
||
struct StaffState: ViewModelState { | ||
var staffs: LoadingState<[Staff]> = .initial | ||
} | ||
|
||
@MainActor | ||
final class StaffViewModel: ObservableObject { | ||
@Dependency(\.staffsData) var staffsData | ||
@Published private(set) var state: StaffState = .init() | ||
|
||
func load() async { | ||
state.staffs = .loading | ||
do { | ||
for try await staffs in staffsData.staffs() { | ||
state.staffs = .loaded(staffs) | ||
} | ||
} catch let error { | ||
state.staffs = .failed(error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@testable import Staff | ||
import XCTest | ||
|
||
final class StaffTests: XCTestCase { | ||
func testExample() throws { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct | ||
// results. | ||
XCTAssertEqual("Hello, World!", "Hello, World!") | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nits]
Placing under Sponsor looks better.