Skip to content

Commit

Permalink
Properly handle initial start
Browse files Browse the repository at this point in the history
  • Loading branch information
streetturtle committed Sep 11, 2023
1 parent d2d91c0 commit 55f4b6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
3 changes: 1 addition & 2 deletions streak-bar/streak-bar/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class ViewModel: ObservableObject {
@Default(.daysBefore) var daysBefore
@Default(.viewMode) var viewMode


private var client = Client()

@Published var contributions: [ContributionWeek] = []
Expand All @@ -27,7 +26,7 @@ class ViewModel: ObservableObject {
case .success(let contributionWeeks):
self.contributions = contributionWeeks
case .failure(_):
NSLog("vse ochen ploho")
self.contributions = [ContributionWeek(contributionDays: [])]
}
}
}
Expand Down
40 changes: 24 additions & 16 deletions streak-bar/streak-bar/Views/StatusItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,33 @@ struct StatusItemView: View {
@Default(.viewMode) var viewMode

var body: some View {
if viewMode == .week {
HStack(alignment: .top, spacing: borders ? 1 : 0) {
ForEach(viewModel.contributions, id:\.self) { week in
VStack(alignment: .leading, spacing: borders ? 1 : 0) {
ForEach(week.contributionDays, id:\.date) { day in
Rectangle()
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
.frame(width: borders ? 2 : 3, height: borders ? 2 : 3)

if viewModel.contributions.first?.contributionDays.isEmpty ?? false {
RoundedRectangle(cornerRadius: 4)
.fill(Theme.themes[theme]![.SECOND_QUARTILE]!.opacity(1))
.frame(width: 16, height: 16)
}
else {
if viewMode == .week {
HStack(alignment: .top, spacing: borders ? 1 : 0) {
ForEach(viewModel.contributions, id:\.self) { week in
VStack(alignment: .leading, spacing: borders ? 1 : 0) {
ForEach(week.contributionDays, id:\.date) { day in
Rectangle()
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
.frame(width: borders ? 2 : 3, height: borders ? 2 : 3)
}
}
}
}
}
} else {
HStack(spacing: 1) {
ForEach(viewModel.contributions, id:\.self) { week in
ForEach(week.contributionDays, id:\.date) { day in
RoundedRectangle(cornerRadius: 4)
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
.frame(width: 16, height: 16)
} else {
HStack(spacing: 1) {
ForEach(viewModel.contributions, id:\.self) { week in
ForEach(week.contributionDays, id:\.date) { day in
RoundedRectangle(cornerRadius: 4)
.fill(Theme.themes[theme]![day.contributionLevel]!.opacity(day.contributionLevel == .NONE && !transparency ? 0.2 : 1))
.frame(width: 16, height: 16)
}
}
}
}
Expand Down

0 comments on commit 55f4b6d

Please sign in to comment.