Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date flairs in PersonView #1497

Merged
merged 4 commits into from
Dec 13, 2024
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
4 changes: 4 additions & 0 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
0369B3562BFA6824001EFEDF /* InboxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0369B3552BFA6824001EFEDF /* InboxView.swift */; };
0369B35D2BFB86E3001EFEDF /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0369B35A2BFB86E3001EFEDF /* Account.swift */; };
036CC3AF2B8145C30098B6A1 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036CC3AE2B8145C30098B6A1 /* AppState.swift */; };
036ED6832D0C483B0018E5EA /* Profile2Providing+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036ED6822D0C483B0018E5EA /* Profile2Providing+Extensions.swift */; };
037331A42C9CB12D00C826E1 /* EnvironmentValues+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 037331A32C9CB12D00C826E1 /* EnvironmentValues+Extensions.swift */; };
037386472BDAFE81007492B5 /* LemmyMarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = 037386462BDAFE81007492B5 /* LemmyMarkdownUI */; };
037658DF2BE7D9EF00F4DD4D /* Community1Providing+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 037658DE2BE7D9EF00F4DD4D /* Community1Providing+Extensions.swift */; };
Expand Down Expand Up @@ -549,6 +550,7 @@
0369B3552BFA6824001EFEDF /* InboxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxView.swift; sourceTree = "<group>"; };
0369B35A2BFB86E3001EFEDF /* Account.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; };
036CC3AE2B8145C30098B6A1 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
036ED6822D0C483B0018E5EA /* Profile2Providing+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Profile2Providing+Extensions.swift"; sourceTree = "<group>"; };
037331A32C9CB12D00C826E1 /* EnvironmentValues+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EnvironmentValues+Extensions.swift"; sourceTree = "<group>"; };
037658DE2BE7D9EF00F4DD4D /* Community1Providing+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Community1Providing+Extensions.swift"; sourceTree = "<group>"; };
037DE0742CE023E3007F7B92 /* BlockListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockListView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1772,6 +1774,7 @@
CD7743882C20EDEE0085BB43 /* VotesModel+Extensions.swift */,
035EDF042C2ED35500F51144 /* Person1Providing+Extensions.swift */,
CD8DCAF82C5E92E8003E4DD7 /* Profile1Providing+Extensions.swift */,
036ED6822D0C483B0018E5EA /* Profile2Providing+Extensions.swift */,
0320B6532C8B65EB00D38548 /* Captcha+Extensions.swift */,
);
path = "Content Models";
Expand Down Expand Up @@ -2450,6 +2453,7 @@
038028F62CB096960091A8A2 /* SearchView+FilterModels.swift in Sources */,
033FCB292C5E3933007B7CD1 /* IconSettingsView.swift in Sources */,
035394932CA1AE2C00795AA5 /* UptimeData.swift in Sources */,
036ED6832D0C483B0018E5EA /* Profile2Providing+Extensions.swift in Sources */,
033FCB2A2C5E3933007B7CD1 /* AlternateIconCell.swift in Sources */,
0389DDC72C389F840005B808 /* UnreadCount+Extensions.swift in Sources */,
03500C242BF55D0E00CAA076 /* Toast.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@ extension Person1Providing {
output.insert(.bannedFromInstance)
}

let intervalSinceCreation = Date.now.timeIntervalSince(created)
if intervalSinceCreation < 30 * 24 * 60 * 60 {
output.insert(.new(intervalSinceCreation))
} else {
let calendar = Calendar.current
let createdComponents = calendar.dateComponents([.month, .day], from: created)
let currentComponents = calendar.dateComponents([.month, .day], from: .now)
if createdComponents.month == currentComponents.month, createdComponents.day == currentComponents.day {
output.insert(.cakeDay)
}
if createdRecently {
output.insert(.new(Date.now.timeIntervalSince(created)))
} else if isCakeDay {
output.insert(.cakeDay)
}

if let interactable {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Profile2Providing+Extensions.swift
// Mlem
//
// Created by Sjmarf on 2024-12-13.
//

import Foundation
import MlemMiddleware

extension Profile2Providing {
var isCakeDay: Bool { created.isAnniversaryToday }

var createdRecently: Bool {
let intervalSinceCreation = Date.now.timeIntervalSince(created)
return intervalSinceCreation < 30 * 24 * 60 * 60
}
}
7 changes: 7 additions & 0 deletions Mlem/App/Utility/Extensions/Date+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ extension Date {
let value = formatter.string(from: interval)
return value ?? String(localized: "Unknown")
}

var isAnniversaryToday: Bool {
let calendar = Calendar.current
let date = calendar.dateComponents([.month, .day, .year], from: self)
let current = calendar.dateComponents([.month, .day, .year], from: .now)
return date.month == current.month && date.day == current.day && date.year != current.year
}
}
29 changes: 26 additions & 3 deletions Mlem/App/Views/Shared/ProfileDateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,36 @@ struct ProfileDateView: View {
var profilable: any Profile2Providing

var body: some View {
Label(format(profilable.created), systemImage: Icons.cakeDay)
.foregroundStyle(palette.secondary)
Label(format(profilable.created), systemImage: systemImage)
.foregroundStyle(color)
.font(.footnote)
}

var color: Color {
if profilable.createdRecently {
palette.colorfulAccent(3)
} else if profilable.isCakeDay {
palette.colorfulAccent(1)
} else {
palette.secondary
}
}

var systemImage: String {
if profilable.createdRecently {
Icons.newAccountFlair
} else if profilable.isCakeDay {
Icons.cakeDayFill
} else {
Icons.cakeDay
}
}

func format(_ date: Date) -> String {
let relTime = date.getRelativeTime(date: Date.now, unitsStyle: .abbreviated)
var relTime = date.getRelativeTime(date: Date.now, unitsStyle: .abbreviated)
if profilable.isCakeDay {
relTime = String(localized: "\(relTime) today!")
}
return "\(date.dateString), \(relTime)"
}
}
3 changes: 3 additions & 0 deletions Mlem/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
},
"%@ rules..." : {

},
"%@ today!" : {

},
"%lld Crossposts..." : {
"localizations" : {
Expand Down
Loading