Skip to content

Commit 55f4b6d

Browse files
committed
Properly handle initial start
1 parent d2d91c0 commit 55f4b6d

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

streak-bar/streak-bar/ViewModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class ViewModel: ObservableObject {
1212
@Default(.daysBefore) var daysBefore
1313
@Default(.viewMode) var viewMode
1414

15-
1615
private var client = Client()
1716

1817
@Published var contributions: [ContributionWeek] = []
@@ -27,7 +26,7 @@ class ViewModel: ObservableObject {
2726
case .success(let contributionWeeks):
2827
self.contributions = contributionWeeks
2928
case .failure(_):
30-
NSLog("vse ochen ploho")
29+
self.contributions = [ContributionWeek(contributionDays: [])]
3130
}
3231
}
3332
}

streak-bar/streak-bar/Views/StatusItemView.swift

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,33 @@ struct StatusItemView: View {
1717
@Default(.viewMode) var viewMode
1818

1919
var body: some View {
20-
if viewMode == .week {
21-
HStack(alignment: .top, spacing: borders ? 1 : 0) {
22-
ForEach(viewModel.contributions, id:\.self) { week in
23-
VStack(alignment: .leading, spacing: borders ? 1 : 0) {
24-
ForEach(week.contributionDays, id:\.date) { day in
25-
Rectangle()
26-
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
27-
.frame(width: borders ? 2 : 3, height: borders ? 2 : 3)
20+
21+
if viewModel.contributions.first?.contributionDays.isEmpty ?? false {
22+
RoundedRectangle(cornerRadius: 4)
23+
.fill(Theme.themes[theme]![.SECOND_QUARTILE]!.opacity(1))
24+
.frame(width: 16, height: 16)
25+
}
26+
else {
27+
if viewMode == .week {
28+
HStack(alignment: .top, spacing: borders ? 1 : 0) {
29+
ForEach(viewModel.contributions, id:\.self) { week in
30+
VStack(alignment: .leading, spacing: borders ? 1 : 0) {
31+
ForEach(week.contributionDays, id:\.date) { day in
32+
Rectangle()
33+
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
34+
.frame(width: borders ? 2 : 3, height: borders ? 2 : 3)
35+
}
2836
}
2937
}
3038
}
31-
}
32-
} else {
33-
HStack(spacing: 1) {
34-
ForEach(viewModel.contributions, id:\.self) { week in
35-
ForEach(week.contributionDays, id:\.date) { day in
36-
RoundedRectangle(cornerRadius: 4)
37-
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
38-
.frame(width: 16, height: 16)
39+
} else {
40+
HStack(spacing: 1) {
41+
ForEach(viewModel.contributions, id:\.self) { week in
42+
ForEach(week.contributionDays, id:\.date) { day in
43+
RoundedRectangle(cornerRadius: 4)
44+
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
45+
.frame(width: 16, height: 16)
46+
}
3947
}
4048
}
4149
}

0 commit comments

Comments
 (0)