Skip to content
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] Add sendable conformance to event map feature #965

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions app-ios/Sources/EventMapFeature/EventItem.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI
import CommonComponents
import Theme
import shared
import Model

struct EventItem: View {
let event: EventMapEvent
Expand All @@ -24,7 +24,7 @@ struct EventItem: View {
.padding(.bottom, 8)

VStack(alignment: .leading ,spacing: 8) {
Text(event.description_.currentLangTitle)
Text(event.description.currentLangTitle)
.foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor)
.textStyle(.bodyLarge)

Expand All @@ -34,7 +34,7 @@ struct EventItem: View {
.textStyle(.bodyMedium)
}

if let urlString = event.moreDetailsUrl, let url = URL(string: urlString) {
if let url = event.moreDetailsUrl {
Button {
onTappedMoreDetail(url)
} label: {
Expand All @@ -61,5 +61,14 @@ struct EventItem: View {
}

#Preview {
EventItem(event: EventMapEvent.companion.fakes().first!) { _ in }
EventItem(
event: .init(
name: .init(currentLangTitle: "name", enTitle: "name", jaTitle: "name"),
roomName: .init(currentLangTitle: "roomName", enTitle: "roomName", jaTitle: "roomName"),
roomIcon: .square,
description: .init(currentLangTitle: "description", enTitle: "description", jaTitle: "description"),
moreDetailsUrl: nil,
message: nil
)
) { _ in }
}
7 changes: 3 additions & 4 deletions app-ios/Sources/EventMapFeature/EventMapReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ComposableArchitecture
import KMPClient
import Model
import Foundation
@preconcurrency import shared

@Reducer
public struct EventMapReducer: Sendable {
Expand All @@ -19,19 +18,19 @@ public struct EventMapReducer: Sendable {
public init() { }
}

public enum Action: BindableAction {
public enum Action: Sendable, BindableAction {
case binding(BindingAction<State>)
case view(View)
case `internal`(Internal)

@CasePathable
public enum View {
public enum View: Sendable {
case onAppear
case selectFloorMap(FloorMap)
case moreDetailButtonTapped(URL)
}

public enum Internal {
public enum Internal: Sendable {
case response(Result<[EventMapEvent], any Error>)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app-ios/Sources/EventMapFeature/Model/FloorMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import Model
import SwiftUI

public enum FloorMap {
public enum FloorMap: Sendable {
case first
case firstBasement
}
Expand Down
2 changes: 1 addition & 1 deletion app-ios/Sources/KMPClient/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public struct ContributorClient: Sendable {

@DependencyClient
public struct EventMapClient: Sendable {
public var streamEvents: @Sendable () throws -> AsyncThrowingStream<[EventMapEvent], any Error>
public var streamEvents: @Sendable () throws -> AsyncThrowingStream<[Model.EventMapEvent], any Error>
}

@DependencyClient
Expand Down
34 changes: 33 additions & 1 deletion app-ios/Sources/KMPClientLive/LiveKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,39 @@ extension ContributorClient: DependencyKey {

extension EventMapClient: DependencyKey {
public static let liveValue: EventMapClient = .init {
eventMapRepository.getEventMapStream().eraseToThrowingStream()
eventMapRepository
.getEventMapStream()
.map {
$0.map {
Model.EventMapEvent(
name: .init(
currentLangTitle: $0.name.currentLangTitle,
enTitle: $0.name.enTitle,
jaTitle: $0.name.jaTitle
),
roomName: .init(
currentLangTitle: $0.roomName.currentLangTitle,
enTitle: $0.roomName.enTitle,
jaTitle: $0.roomName.jaTitle
),
roomIcon: RoomIcon(rawValue: $0.roomIcon.name.lowercased()) ?? .none,
description: .init(
currentLangTitle: $0.description_.currentLangTitle,
enTitle: $0.description_.enTitle,
jaTitle: $0.description_.jaTitle
),
moreDetailsUrl: $0.moreDetailsUrl.flatMap(URL.init(string:)),
message: $0.message.map {
.init(
currentLangTitle: $0.currentLangTitle,
enTitle: $0.enTitle,
jaTitle: $0.jaTitle
)
}
)
}
}
.eraseToThrowingStream()
}
}

Expand Down
24 changes: 24 additions & 0 deletions app-ios/Sources/Model/Entity/EventMapEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation

public struct EventMapEvent: Equatable, Sendable, Hashable {
public let name: MultiLangText
public let roomName: MultiLangText
public let roomIcon: RoomIcon
public let description: MultiLangText
public let moreDetailsUrl: URL?
public let message: MultiLangText?

public init(name: MultiLangText, roomName: MultiLangText, roomIcon: RoomIcon, description: MultiLangText, moreDetailsUrl: URL?, message: MultiLangText?) {
self.name = name
self.roomName = roomName
self.roomIcon = roomIcon
self.description = description
self.moreDetailsUrl = moreDetailsUrl
self.message = message
}

public func hash(into hasher: inout Hasher) {
hasher.combine(name.enTitle)
hasher.combine(roomName.enTitle)
}
}
2 changes: 1 addition & 1 deletion app-ios/Sources/Model/Entity/MultiLangText.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public struct MultiLangText {
public struct MultiLangText: Equatable, Sendable {
public let currentLangTitle: String
public let enTitle: String
public let jaTitle: String
Expand Down
10 changes: 10 additions & 0 deletions app-ios/Sources/Model/Entity/RoomIcon.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Foundation

public enum RoomIcon: String, Sendable {
case square
case circle
case diamond
case rhombus
case triangle
case none
}
Loading