Skip to content

Commit

Permalink
Merge branch 'trunk' into task/ui-modernization-posts-and-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Nov 1, 2023
2 parents 6737579 + 60a98e5 commit fe35d53
Show file tree
Hide file tree
Showing 12 changed files with 585 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ extension DomainsService {

typealias AllDomainsEndpointResult = DomainsServiceRemote.AllDomainsEndpointResult
typealias AllDomainsEndpointParams = DomainsServiceRemote.AllDomainsEndpointParams
typealias AllDomainsListItem = DomainsServiceRemote.AllDomainsListItem
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import Foundation

struct AllDomainsListItemViewModel {

let name: String
let description: String?
let status: Status?
let expiryDate: String?
}

// MARK: - Convenience Inits

extension AllDomainsListItemViewModel {

private static let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .none
return formatter
}()

init(domain: Domain) {
self.init(
name: domain.domain,
description: Self.description(from: domain),
status: domain.status,
expiryDate: Self.expiryDate(from: domain)
)
}

private static func description(from domain: Domain) -> String? {
guard !domain.isDomainOnlySite else {
return nil
}
return !domain.blogName.isEmpty ? domain.blogName : domain.siteSlug
}

private static func expiryDate(from domain: Domain) -> String? {
guard let date = domain.expiryDate, domain.hasRegistration else {
return nil
}
let expired = date < Date()
let notice = expired ? Strings.expired : Strings.renews
let formatted = Self.dateFormatter.string(from: date)
return "\(notice) \(formatted)"
}
}

// MARK: - Types

extension AllDomainsListItemViewModel {

private enum Strings {

static let expired = NSLocalizedString(
"domain.management.card.expired.label",
value: "Expired",
comment: "The expired label of the domain card in My Domains screen."
)
static let renews = NSLocalizedString(
"domain.management.card.renews.label",
value: "Renews",
comment: "The renews label of the domain card in My Domains screen."
)
}

typealias Domain = DomainsService.AllDomainsListItem
typealias Status = Domain.Status
typealias StatusType = DomainsService.AllDomainsListItem.StatusType
}
Loading

0 comments on commit fe35d53

Please sign in to comment.