Skip to content

Commit 41aa4eb

Browse files
committed
Merge remote-tracking branch 'origin/shared-state-beta' into lukeredpath/default-providing-key
2 parents 9ba1499 + a3dcc65 commit 41aa4eb

20 files changed

+368
-197
lines changed

Examples/SyncUps/SyncUps/AppFeature.swift

+7-12
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,13 @@ struct AppView: View {
7171
}
7272

7373
#Preview {
74-
AppView(
75-
store: Store(
76-
initialState: AppFeature.State(
77-
syncUpsList: SyncUpsList.State(
78-
syncUps: [
79-
.mock,
80-
.productMock,
81-
.engineeringMock,
82-
]
83-
)
84-
)
85-
) {
74+
@Shared(.syncUps) var syncUps: IdentifiedArrayOf<SyncUp> = [
75+
.mock,
76+
.productMock,
77+
.engineeringMock
78+
]
79+
return AppView(
80+
store: Store(initialState: AppFeature.State()) {
8681
AppFeature()
8782
}
8883
)

Examples/SyncUps/SyncUps/Meeting.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ struct MeetingView: View {
77
var body: some View {
88
Form {
99
Section {
10-
ForEach(self.syncUp.attendees) { attendee in
10+
ForEach(syncUp.attendees) { attendee in
1111
Text(attendee.name)
1212
}
1313
} header: {
1414
Text("Attendees")
1515
}
1616
Section {
17-
Text(self.meeting.transcript)
17+
Text(meeting.transcript)
1818
} header: {
1919
Text("Transcript")
2020
}
2121
}
22-
.navigationTitle(Text(self.meeting.date, style: .date))
22+
.navigationTitle(Text(meeting.date, style: .date))
2323
}
2424
}
2525

Examples/SyncUps/SyncUps/Models.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct SyncUp: Equatable, Identifiable, Codable {
1111
var title = ""
1212

1313
var durationPerAttendee: Duration {
14-
self.duration / self.attendees.count
14+
duration / attendees.count
1515
}
1616
}
1717

@@ -56,9 +56,9 @@ enum Theme: String, CaseIterable, Equatable, Identifiable, Codable {
5656
}
5757
}
5858

59-
var mainColor: Color { Color(self.rawValue) }
59+
var mainColor: Color { Color(rawValue) }
6060

61-
var name: String { self.rawValue.capitalized }
61+
var name: String { rawValue.capitalized }
6262
}
6363

6464
extension SyncUp {

Examples/SyncUps/SyncUps/RecordMeeting.swift

+37-37
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct RecordMeeting {
1313
var transcript = ""
1414

1515
var durationRemaining: Duration {
16-
self.syncUp.duration - .seconds(self.secondsElapsed)
16+
syncUp.duration - .seconds(secondsElapsed)
1717
}
1818
}
1919

@@ -41,11 +41,11 @@ struct RecordMeeting {
4141
Reduce { state, action in
4242
switch action {
4343
case .alert(.presented(.confirmDiscard)):
44-
return .run { _ in await self.dismiss() }
44+
return .run { _ in await dismiss() }
4545

4646
case .alert(.presented(.confirmSave)):
4747
state.syncUp.insert(transcript: state.transcript)
48-
return .run { _ in await self.dismiss() }
48+
return .run { _ in await dismiss() }
4949

5050
case .alert:
5151
return .none
@@ -68,18 +68,18 @@ struct RecordMeeting {
6868
case .onTask:
6969
return .run { send in
7070
let authorization =
71-
await self.speechClient.authorizationStatus() == .notDetermined
72-
? self.speechClient.requestAuthorization()
73-
: self.speechClient.authorizationStatus()
71+
await speechClient.authorizationStatus() == .notDetermined
72+
? speechClient.requestAuthorization()
73+
: speechClient.authorizationStatus()
7474

7575
await withTaskGroup(of: Void.self) { group in
7676
if authorization == .authorized {
7777
group.addTask {
78-
await self.startSpeechRecognition(send: send)
78+
await startSpeechRecognition(send: send)
7979
}
8080
}
8181
group.addTask {
82-
await self.startTimer(send: send)
82+
await startTimer(send: send)
8383
}
8484
}
8585
}
@@ -92,9 +92,9 @@ struct RecordMeeting {
9292

9393
let secondsPerAttendee = Int(state.syncUp.durationPerAttendee.components.seconds)
9494
if state.secondsElapsed.isMultiple(of: secondsPerAttendee) {
95-
if state.speakerIndex == state.syncUp.attendees.count - 1 {
95+
if state.secondsElapsed == state.syncUp.duration.components.seconds {
9696
state.syncUp.insert(transcript: state.transcript)
97-
return .run { _ in await self.dismiss() }
97+
return .run { _ in await dismiss() }
9898
}
9999
state.speakerIndex += 1
100100
}
@@ -118,7 +118,7 @@ struct RecordMeeting {
118118

119119
private func startSpeechRecognition(send: Send<Action>) async {
120120
do {
121-
let speechTask = await self.speechClient.startTask(SFSpeechAudioBufferRecognitionRequest())
121+
let speechTask = await speechClient.startTask(SFSpeechAudioBufferRecognitionRequest())
122122
for try await result in speechTask {
123123
await send(.speechResult(result))
124124
}
@@ -128,7 +128,7 @@ struct RecordMeeting {
128128
}
129129

130130
private func startTimer(send: Send<Action>) async {
131-
for await _ in self.clock.timer(interval: .seconds(1)) {
131+
for await _ in clock.timer(interval: .seconds(1)) {
132132
await send(.timerTick)
133133
}
134134
}
@@ -138,7 +138,7 @@ extension SyncUp {
138138
fileprivate mutating func insert(transcript: String) {
139139
@Dependency(\.date.now) var now
140140
@Dependency(\.uuid) var uuid
141-
self.meetings.insert(
141+
meetings.insert(
142142
Meeting(
143143
id: Meeting.ID(uuid()),
144144
date: now,
@@ -239,22 +239,22 @@ struct MeetingHeaderView: View {
239239

240240
var body: some View {
241241
VStack {
242-
ProgressView(value: self.progress)
243-
.progressViewStyle(MeetingProgressViewStyle(theme: self.theme))
242+
ProgressView(value: progress)
243+
.progressViewStyle(MeetingProgressViewStyle(theme: theme))
244244
HStack {
245245
VStack(alignment: .leading) {
246246
Text("Time Elapsed")
247247
.font(.caption)
248248
Label(
249-
Duration.seconds(self.secondsElapsed).formatted(.units()),
249+
Duration.seconds(secondsElapsed).formatted(.units()),
250250
systemImage: "hourglass.bottomhalf.fill"
251251
)
252252
}
253253
Spacer()
254254
VStack(alignment: .trailing) {
255255
Text("Time Remaining")
256256
.font(.caption)
257-
Label(self.durationRemaining.formatted(.units()), systemImage: "hourglass.tophalf.fill")
257+
Label(durationRemaining.formatted(.units()), systemImage: "hourglass.tophalf.fill")
258258
.font(.body.monospacedDigit())
259259
.labelStyle(.trailingIcon)
260260
}
@@ -264,12 +264,12 @@ struct MeetingHeaderView: View {
264264
}
265265

266266
private var totalDuration: Duration {
267-
.seconds(self.secondsElapsed) + self.durationRemaining
267+
.seconds(secondsElapsed) + durationRemaining
268268
}
269269

270270
private var progress: Double {
271-
guard self.totalDuration > .seconds(0) else { return 0 }
272-
return Double(self.secondsElapsed) / Double(self.totalDuration.components.seconds)
271+
guard totalDuration > .seconds(0) else { return 0 }
272+
return Double(secondsElapsed) / Double(totalDuration.components.seconds)
273273
}
274274
}
275275

@@ -279,11 +279,11 @@ struct MeetingProgressViewStyle: ProgressViewStyle {
279279
func makeBody(configuration: Configuration) -> some View {
280280
ZStack {
281281
RoundedRectangle(cornerRadius: 10)
282-
.fill(self.theme.accentColor)
282+
.fill(theme.accentColor)
283283
.frame(height: 20)
284284

285285
ProgressView(configuration)
286-
.tint(self.theme.mainColor)
286+
.tint(theme.mainColor)
287287
.frame(height: 12)
288288
.padding(.horizontal)
289289
}
@@ -300,8 +300,8 @@ struct MeetingTimerView: View {
300300
.overlay {
301301
VStack {
302302
Group {
303-
if self.speakerIndex < self.syncUp.attendees.count {
304-
Text(self.syncUp.attendees[self.speakerIndex].name)
303+
if speakerIndex < syncUp.attendees.count {
304+
Text(syncUp.attendees[speakerIndex].name)
305305
} else {
306306
Text("Someone")
307307
}
@@ -312,14 +312,14 @@ struct MeetingTimerView: View {
312312
.font(.largeTitle)
313313
.padding(.top)
314314
}
315-
.foregroundStyle(self.syncUp.theme.accentColor)
315+
.foregroundStyle(syncUp.theme.accentColor)
316316
}
317317
.overlay {
318-
ForEach(Array(self.syncUp.attendees.enumerated()), id: \.element.id) { index, attendee in
319-
if index < self.speakerIndex + 1 {
320-
SpeakerArc(totalSpeakers: self.syncUp.attendees.count, speakerIndex: index)
318+
ForEach(Array(syncUp.attendees.enumerated()), id: \.element.id) { index, attendee in
319+
if index < speakerIndex + 1 {
320+
SpeakerArc(totalSpeakers: syncUp.attendees.count, speakerIndex: index)
321321
.rotation(Angle(degrees: -90))
322-
.stroke(self.syncUp.theme.mainColor, lineWidth: 12)
322+
.stroke(syncUp.theme.mainColor, lineWidth: 12)
323323
}
324324
}
325325
}
@@ -339,21 +339,21 @@ struct SpeakerArc: Shape {
339339
path.addArc(
340340
center: center,
341341
radius: radius,
342-
startAngle: self.startAngle,
343-
endAngle: self.endAngle,
342+
startAngle: startAngle,
343+
endAngle: endAngle,
344344
clockwise: false
345345
)
346346
}
347347
}
348348

349349
private var degreesPerSpeaker: Double {
350-
360 / Double(self.totalSpeakers)
350+
360 / Double(totalSpeakers)
351351
}
352352
private var startAngle: Angle {
353-
Angle(degrees: self.degreesPerSpeaker * Double(self.speakerIndex) + 1)
353+
Angle(degrees: degreesPerSpeaker * Double(speakerIndex) + 1)
354354
}
355355
private var endAngle: Angle {
356-
Angle(degrees: self.startAngle.degrees + self.degreesPerSpeaker - 1)
356+
Angle(degrees: startAngle.degrees + degreesPerSpeaker - 1)
357357
}
358358
}
359359

@@ -365,13 +365,13 @@ struct MeetingFooterView: View {
365365
var body: some View {
366366
VStack {
367367
HStack {
368-
if self.speakerIndex < self.syncUp.attendees.count - 1 {
369-
Text("Speaker \(self.speakerIndex + 1) of \(self.syncUp.attendees.count)")
368+
if speakerIndex < syncUp.attendees.count - 1 {
369+
Text("Speaker \(speakerIndex + 1) of \(syncUp.attendees.count)")
370370
} else {
371371
Text("No more speakers.")
372372
}
373373
Spacer()
374-
Button(action: self.nextButtonTapped) {
374+
Button(action: nextButtonTapped) {
375375
Image(systemName: "forward.fill")
376376
}
377377
}

Examples/SyncUps/SyncUps/SyncUpDetail.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ struct SyncUpDetail {
6565
case .confirmDeletion:
6666
@Shared(.syncUps) var syncUps: IdentifiedArrayOf<SyncUp> = []
6767
syncUps.remove(id: state.syncUp.id)
68-
return .run { _ in await self.dismiss() }
68+
return .run { _ in await dismiss() }
6969

7070
case .continueWithoutRecording:
7171
return .send(.delegate(.startMeeting))
7272

7373
case .openSettings:
74-
return .run { _ in await self.openSettings() }
74+
return .run { _ in await openSettings() }
7575
}
7676

7777
case .destination:
@@ -89,7 +89,7 @@ struct SyncUpDetail {
8989
return .none
9090

9191
case .startMeetingButtonTapped:
92-
switch self.authorizationStatus() {
92+
switch authorizationStatus() {
9393
case .notDetermined, .authorized:
9494
return .send(.delegate(.startMeeting))
9595

Examples/SyncUps/SyncUps/SyncUpForm.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct SyncUpForm {
3737
Reduce { state, action in
3838
switch action {
3939
case .addAttendeeButtonTapped:
40-
let attendee = Attendee(id: Attendee.ID(self.uuid()))
40+
let attendee = Attendee(id: Attendee.ID(uuid()))
4141
state.syncUp.attendees.append(attendee)
4242
state.focus = .attendee(attendee.id)
4343
return .none
@@ -48,7 +48,7 @@ struct SyncUpForm {
4848
case let .deleteAttendees(atOffsets: indices):
4949
state.syncUp.attendees.remove(atOffsets: indices)
5050
if state.syncUp.attendees.isEmpty {
51-
state.syncUp.attendees.append(Attendee(id: Attendee.ID(self.uuid())))
51+
state.syncUp.attendees.append(Attendee(id: Attendee.ID(uuid())))
5252
}
5353
guard let firstIndex = indices.first
5454
else { return .none }
@@ -104,7 +104,7 @@ struct ThemePicker: View {
104104
@Binding var selection: Theme
105105

106106
var body: some View {
107-
Picker("Theme", selection: self.$selection) {
107+
Picker("Theme", selection: $selection) {
108108
ForEach(Theme.allCases) { theme in
109109
ZStack {
110110
RoundedRectangle(cornerRadius: 4)
@@ -122,7 +122,7 @@ struct ThemePicker: View {
122122

123123
extension Duration {
124124
fileprivate var minutes: Double {
125-
get { Double(self.components.seconds / 60) }
125+
get { Double(components.seconds / 60) }
126126
set { self = .seconds(newValue * 60) }
127127
}
128128
}

0 commit comments

Comments
 (0)