-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfileView.swift
73 lines (62 loc) · 1.91 KB
/
ProfileView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// ProfileView.swift
// RecursiveSampleAppTCA
//
// Created by Yosuke NAKAYAMA on 2022/04/16.
//
import Foundation
import ComposableArchitecture
import SwiftUI
struct ProfileState: Equatable, Identifiable {
@Cow var id = UUID()
@Cow var timelineLogCellStateList: IdentifiedArrayOf<TimelineLogCellState> = []
}
enum ProfileAction: Equatable {
case timelineLogCellAction(index: TimelineLogCellState.ID, action: TimelineLogCellAction)
}
struct ProfileEnvironment {
}
let profileReducer = Reducer<ProfileState, ProfileAction, ProfileEnvironment>.recurse { `self`, state, action, env in
switch action {
case .timelineLogCellAction:
return self.forEach(state: \ProfileState.timelineLogCellStateList,
action: /ProfileAction.timelineLogCellAction(index:action:),
environment: {_ in ProfileEnvironment() })
.run(&state, action, env)
default:
return .none
}
}
struct ProfileView: View {
var store: Store<ProfileState, ProfileAction>
var body: some View {
WithViewStore(store) { viewStore in
List {
timelineView
}
.listStyle(PlainListStyle())
}
}
var timelineView: some View {
WithViewStore(store) { viewStore in
ForEachStore(
self.store.scope(
state: \.timelineLogCellStateList,
action: ProfileAction.timelineLogCellAction(index:action:)
),
content: TimelineLogCell.init(store:)
)
.listRowInsets(EdgeInsets())
}
}
}
struct ProfileView_Previews: PreviewProvider {
static var previews: some View {
ProfileView(
store: .init(
initialState: .init(),
reducer: profileReducer,
environment: ProfileEnvironment()
))
}
}