Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ struct PPOAlertFlag: View {

var body: some View {
HStack {
self.image
.renderingMode(.template)
.aspectRatio(contentMode: .fit)
.foregroundStyle(self.foregroundColor)
.frame(width: Constants.imageSize, height: Constants.imageSize)
Spacer()
.frame(width: Constants.spacerWidth)
if let icon = alert.icon {
self.image(forIcon: icon)
.renderingMode(.template)
.aspectRatio(contentMode: .fit)
.foregroundStyle(self.foregroundColor)
.frame(width: Constants.imageSize, height: Constants.imageSize)
Spacer()
.frame(width: Constants.spacerWidth)
}

Text(self.alert.message)
.font(Font(PPOStyles.flagFont))
.foregroundStyle(self.foregroundColor)
.frame(minHeight: Constants.imageSize)
}
.padding(Constants.padding)
.background(self.backgroundColor)
Expand All @@ -29,8 +33,8 @@ struct PPOAlertFlag: View {
.accessibilityAddTraits(.isStaticText)
}

var image: Image {
switch self.alert.icon {
private func image(forIcon icon: PPOProjectCardModel.Alert.AlertIcon) -> Image {
switch icon {
case .time:
Image(PPOStyles.timeImage)
case .alert:
Expand All @@ -44,6 +48,8 @@ struct PPOAlertFlag: View {
Color(uiColor: PPOStyles.warningColor.foreground)
case .alert:
Color(uiColor: PPOStyles.alertColor.foreground)
case .info:
Color(uiColor: PPOStyles.infoColor.foreground)
}
}

Expand All @@ -53,6 +59,8 @@ struct PPOAlertFlag: View {
Color(uiColor: PPOStyles.warningColor.background)
case .alert:
Color(uiColor: PPOStyles.alertColor.background)
case .info:
Color(uiColor: PPOStyles.infoColor.background)
}
}

Expand All @@ -72,6 +80,7 @@ struct PPOAlertFlag: View {

#Preview("Stack of flags") {
VStack(alignment: .leading, spacing: 8) {
PPOAlertFlag(alert: .init(type: .info, icon: nil, message: "Awaiting reward"))
PPOAlertFlag(alert: .init(type: .warning, icon: .time, message: "Address locks in 8 hours"))
PPOAlertFlag(alert: .init(type: .warning, icon: .alert, message: "Survey available"))
PPOAlertFlag(alert: .init(type: .alert, icon: .alert, message: "Payment failed"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public struct PPOProjectCardModel: Identifiable, Equatable, Hashable {

public struct Alert: Identifiable, Equatable, Hashable {
public let type: AlertType
public let icon: AlertIcon
public let icon: AlertIcon?
public let message: String

public init(type: AlertType, icon: AlertIcon, message: String) {
public init(type: AlertType, icon: AlertIcon?, message: String) {
self.type = type
self.icon = icon
self.message = message
}

public var id: String {
"\(self.type)-\(self.icon)-\(self.message)"
"\(self.type)-\(self.icon?.id ?? "noIcon")-\(self.message)"
}

public enum AlertIcon: Identifiable, Equatable {
Expand All @@ -143,13 +143,16 @@ public struct PPOProjectCardModel: Identifiable, Equatable, Hashable {
public enum AlertType: Identifiable, Equatable {
case warning
case alert
case info

public var id: String {
switch self {
case .warning:
"warning"
case .alert:
"alert"
case .info:
"info"
}
}
}
Expand All @@ -172,12 +175,14 @@ extension PPOProjectCardModel.Alert {
.alert
case "warning":
.warning
case "info":
.info
default:
nil
}
let message = flag.message

guard let alertType, let alertIcon, let message else {
guard let alertType, let message else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ enum PPOStyles {
background: LegacyColors.ksr_white.uiColor()
)

static let infoColor = (
foreground: LegacyColors.Tags.Success.foreground.uiColor(),
background: LegacyColors.Tags.Success.background.uiColor()
)

static let warningColor = (
foreground: LegacyColors.Tags.Warn.foreground.uiColor(),
background: LegacyColors.Tags.Warn.background.uiColor()
Expand Down