-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into task/ui-modernization-posts-and-pages
- Loading branch information
Showing
12 changed files
with
585 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
259 changes: 0 additions & 259 deletions
259
WordPress/Classes/ViewRelated/Domains/Domain registration/DomainListCard.swift
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
WordPress/Classes/ViewRelated/Me/All Domains/View Models/AllDomainsListItemViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.