Skip to content

Commit

Permalink
Merge pull request #63 from wishkit/new-states
Browse files Browse the repository at this point in the history
New states
  • Loading branch information
martinlasek authored Oct 27, 2024
2 parents a8de356 + ee5baf6 commit 118af81
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 98 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
.library(name: "WishKit", targets: ["WishKit"])
],
dependencies: [
.package(url: "https://github.com/wishkit/wishkit-ios-shared.git", exact: "1.4.3")
.package(url: "https://github.com/wishkit/wishkit-ios-shared.git", exact: "1.5.0")
],
targets: [
.target(name: "WishKit", dependencies: [
Expand Down
24 changes: 22 additions & 2 deletions Sources/WishKit/Configuration+Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ extension Configuration {

public var implemented: String

public var inReview: String

public var planned: String

public var inProgress: String

public var completed: String

public var wishlist: String

public var save: String
Expand Down Expand Up @@ -97,6 +105,10 @@ extension Configuration {
pending: String = Localization.default().pending,
approved: String = Localization.default().approved,
implemented: String = Localization.default().implemented,
inReview: String = Localization.default().inReview,
planned: String = Localization.default().planned,
inProgress: String = Localization.default().inProgress,
completed: String = Localization.default().completed,
wishlist: String = Localization.default().wishlist,
save: String = Localization.default().save,
title: String = Localization.default().title,
Expand Down Expand Up @@ -139,6 +151,10 @@ extension Configuration {
self.pending = pending
self.approved = approved
self.implemented = implemented
self.inReview = inReview
self.planned = planned
self.inProgress = inProgress
self.completed = completed
self.wishlist = wishlist
self.save = save
self.title = title
Expand Down Expand Up @@ -182,8 +198,12 @@ extension Configuration {
Localization(
requested: "Requested",
pending: "Pending",
approved: "Approved",
implemented: "Implemented",
approved: "In Review",
implemented: "Completed",
inReview: "In Review",
planned: "Planned",
inProgress: "In Progress",
completed: "Completed",
wishlist: "Feature Requests",
save: "Save",
title: "Title",
Expand Down
49 changes: 30 additions & 19 deletions Sources/WishKit/Model/WishModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,31 @@ import SwiftUI
final class WishModel: ObservableObject {

@Published
@available(*, deprecated, message: "Use `inReviewList` instead.")
var approvedWishlist: [WishResponse] = []

@Published
@available(*, deprecated, message: "Use `completedList` instead.")
var implementedWishlist: [WishResponse] = []

@Published
var pendingList: [WishResponse] = []

@Published
var inReviewList: [WishResponse] = []

@Published
var plannedList: [WishResponse] = []

@Published
var inProgressList: [WishResponse] = []

@Published
var completedList: [WishResponse] = []

@Published
var fullList: [WishResponse] = []

@Published
var shouldShowWatermark: Bool = false

Expand All @@ -38,9 +58,9 @@ final class WishModel: ObservableObject {
case .success(let response):
DispatchQueue.main.async {
withAnimation {
self.updateApprovedWishlist(with: response.list)
self.updateImplementedWishlist(with: response.list)
self.updateAllLists(with: response.list)
self.shouldShowWatermark = response.shouldShowWatermark
self.fullList = response.list
}
}
case .failure(let error):
Expand All @@ -61,24 +81,15 @@ final class WishModel: ObservableObject {
fetchList(completion: nil)
}

private func updateApprovedWishlist(with list: [WishResponse]) {
let userUUID = UUIDManager.getUUID()

var filteredList = list.filter { wish in
let ownPendingWish = (wish.state == .pending && wish.userUUID == userUUID)
let approvedWish = wish.state == .approved
private func updateAllLists(with list: [WishResponse]) {
let sortedList = list.sorted { $0.votingUsers.count > $1.votingUsers.count }

return ownPendingWish || approvedWish
}

filteredList.sort { $0.votingUsers.count > $1.votingUsers.count }

self.approvedWishlist = filteredList
}
self.pendingList = sortedList.filter { wish in wish.state == .pending && wish.userUUID == UUIDManager.getUUID() }
self.inReviewList = sortedList.filter { wish in wish.state == .inReview || wish.state == .approved }
self.plannedList = sortedList.filter { wish in wish.state == .planned }
self.inProgressList = sortedList.filter { wish in wish.state == .inProgress }
self.completedList = sortedList.filter { wish in wish.state == .completed || wish.state == .implemented}

private func updateImplementedWishlist(with list: [WishResponse]) {
var filteredList = list.filter { wish in wish.state == .implemented }
filteredList.sort { $0.votingUsers.count > $1.votingUsers.count }
self.implementedWishlist = filteredList
self.implementedWishlist = sortedList
}
}
2 changes: 1 addition & 1 deletion Sources/WishKit/ProjectSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ struct ProjectSettings {
let wishKitUrl = ProcessInfo.processInfo.environment["wishkit-url"]
return wishKitUrl ?? "https://www.wishkit.io/api"
}
static let sdkVersion = "4.5.0"
static let sdkVersion = "4.6.0"
}
43 changes: 0 additions & 43 deletions Sources/WishKit/SwiftUI/SegmentedView.swift

This file was deleted.

35 changes: 35 additions & 0 deletions Sources/WishKit/SwiftUI/WishState+Description.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// SegmentedView.swift
// wishkit-ios
//
// Created by Martin Lasek on 9/15/23.
// Copyright © 2023 Martin Lasek. All rights reserved.
//

import SwiftUI
import WishKitShared

extension WishState: Identifiable {
public var id: Self { self }

public var description: String {
switch self {
case .approved:
WishKit.config.localization.approved
case .implemented:
WishKit.config.localization.implemented
case .pending:
WishKit.config.localization.pending
case .inReview:
WishKit.config.localization.inReview
case .planned:
WishKit.config.localization.planned
case .inProgress:
WishKit.config.localization.inProgress
case .completed:
WishKit.config.localization.completed
default:
"Not Supported"
}
}
}
56 changes: 48 additions & 8 deletions Sources/WishKit/SwiftUI/WishView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ struct WishView: View {

func badgeColor(for wishState: WishState) -> Color {
switch wishState {
case .approved:
switch colorScheme {
case .light:
return WishKit.theme.badgeColor.approved.light
case .dark:
return WishKit.theme.badgeColor.approved.dark
@unknown default:
return WishKit.theme.badgeColor.approved.light
}
case .implemented:
switch colorScheme {
case .light:
return WishKit.theme.badgeColor.implemented.light
case .dark:
return WishKit.theme.badgeColor.implemented.dark
@unknown default:
return WishKit.theme.badgeColor.implemented.light
}

case .pending:
switch colorScheme {
case .light:
Expand All @@ -130,23 +149,42 @@ struct WishView: View {
@unknown default:
return WishKit.theme.badgeColor.pending.light
}
case .approved:
case .inReview:
switch colorScheme {
case .light:
return WishKit.theme.badgeColor.approved.light
return WishKit.theme.badgeColor.inReview.light
case .dark:
return WishKit.theme.badgeColor.approved.dark
return WishKit.theme.badgeColor.inReview.dark
@unknown default:
return WishKit.theme.badgeColor.approved.light
return WishKit.theme.badgeColor.inReview.light
}
case .implemented:
case .planned:
switch colorScheme {
case .light:
return WishKit.theme.badgeColor.implemented.light
return WishKit.theme.badgeColor.planned.light
case .dark:
return WishKit.theme.badgeColor.implemented.dark
return WishKit.theme.badgeColor.planned.dark
@unknown default:
return WishKit.theme.badgeColor.implemented.light
return WishKit.theme.badgeColor.planned.light
}
case .inProgress:
switch colorScheme {
case .light:
return WishKit.theme.badgeColor.inProgress.light
case .dark:
return WishKit.theme.badgeColor.inProgress.dark
@unknown default:
return WishKit.theme.badgeColor.inProgress.light
}

case .completed:
switch colorScheme {
case .light:
return WishKit.theme.badgeColor.completed.light
case .dark:
return WishKit.theme.badgeColor.completed.dark
@unknown default:
return WishKit.theme.badgeColor.completed.light
}
case .rejected:
switch colorScheme {
Expand All @@ -157,6 +195,8 @@ struct WishView: View {
@unknown default:
return WishKit.theme.badgeColor.rejected.light
}
default:
return .black
}
}

Expand Down
18 changes: 14 additions & 4 deletions Sources/WishKit/SwiftUI/WishlistView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ struct WishlistView: View {
func getList() -> [WishResponse] {
switch listType {
case .approved:
return wishModel.approvedWishlist
wishModel.approvedWishlist
case .implemented:
return wishModel.implementedWishlist
default:
return []
wishModel.implementedWishlist
case .pending:
wishModel.pendingList
case .inReview:
wishModel.inReviewList
case .planned:
wishModel.plannedList
case .inProgress:
wishModel.inProgressList
case .completed:
wishModel.completedList
case .rejected:
[]
}
}

Expand Down
Loading

0 comments on commit 118af81

Please sign in to comment.