Skip to content

Commit

Permalink
[App] Move outdated count to property
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfreeman committed Jun 10, 2024
1 parent 362ee7a commit 63b90f4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Core
import SwiftUI

struct AppsCategories: View {
@EnvironmentObject var model: Applications
let categories: [Applications.Category]

var columns: [GridItem] {
Expand Down
21 changes: 5 additions & 16 deletions Flipper/Packages/UI/Sources/Apps/Components/AppsSegments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ struct AppsSegments: View {
@EnvironmentObject var model: Applications

@Binding var selected: Segment
@Namespace private var animation

enum Segment {
case all
case installed
}

@State var updatesCount: Int = 0

@Namespace private var animation
var outdatedCount: Int {
model.outdatedCount
}

var body: some View {
HStack(spacing: 2) {
Expand All @@ -30,24 +31,12 @@ struct AppsSegments: View {
id: .installed,
image: "InstalledApps",
title: "Installed",
badge: updatesCount == 0 ? nil : "\(updatesCount)",
badge: outdatedCount == 0 ? nil : "\(outdatedCount)",
namespace: animation
)
}
.background(.white.opacity(0.3))
.cornerRadius(10)
.onReceive(model.$statuses) { _ in
Task {
loadUpdates()
}
}
.task {
loadUpdates()
}
}

func loadUpdates() {
self.updatesCount = model.outdatedCount
}
}

Expand Down
8 changes: 6 additions & 2 deletions Flipper/Packages/UI/Sources/Apps/Components/Buttons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ struct UpdateAllAppButton: View {

let action: () -> Void

var outdatedCount: Int {
model.outdatedCount
}

struct Placeholder: View {
var body: some View {
AnimatedPlaceholder()
Expand All @@ -22,10 +26,10 @@ struct UpdateAllAppButton: View {
.foregroundColor(.sGreenUpdate)
.font(.born2bSportyV2(size: 18))

if model.outdatedCount > 0 {
if outdatedCount > 0 {
Group {
Group {
Text("\(model.outdatedCount)")
Text("\(outdatedCount)")
.font(.system(size: 12, weight: .bold))
.foregroundColor(.white)
.padding(.horizontal, 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ struct InstalledAppsView: View {
(!isLoading && applications.isEmpty)
}

var outdatedCount: Int {
model.outdatedCount
}

struct NetworkIssue: View {
var body: some View {
VStack(alignment: .center) {
Expand Down Expand Up @@ -61,7 +65,7 @@ struct InstalledAppsView: View {
Group {
if isNetworkIssue {
NetworkIssue()
} else if model.outdatedCount > 0 {
} else if outdatedCount > 0 {
UpdateAllAppButton {
updateAll()
}
Expand Down

0 comments on commit 63b90f4

Please sign in to comment.