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 3 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
16 changes: 13 additions & 3 deletions app-ios/Sources/EventMapFeature/EventItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import SwiftUI
import CommonComponents
import Theme
import shared
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this import with your modified?
I guess Model package wrapped shared package, it makes shared imports to be no needed.

import Model

struct EventItem: View {
let event: EventMapEvent
let event: Model.EventMapEvent
let onTappedMoreDetail: (URL) -> Void

var body: some View {
Expand Down Expand Up @@ -34,7 +35,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 +62,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 }
}
12 changes: 6 additions & 6 deletions app-ios/Sources/EventMapFeature/EventMapReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ComposableArchitecture
import KMPClient
import Model
import Foundation
@preconcurrency import shared
import shared
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this import with your modified?
I guess Model package wrapped shared package, it makes shared imports to be no needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!


@Reducer
public struct EventMapReducer: Sendable {
Expand All @@ -13,26 +13,26 @@ public struct EventMapReducer: Sendable {
@ObservableState
public struct State: Equatable {
public var selectedFloorMap: FloorMap = .first
public var events: [EventMapEvent] = []
public var events: [Model.EventMapEvent] = []
public var url: IdentifiableURL?

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 {
case response(Result<[EventMapEvent], any Error>)
public enum Internal: Sendable {
case response(Result<[Model.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 @@ -60,7 +60,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/KMPClient/LiveKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this _ isn't needed for iOS side code 👀

Suggested change
public let description_: MultiLangText
public let description: MultiLangText

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it.

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