mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-06-12 17:34:25 +02:00
feat: add edit time display on memo card
This commit is contained in:
@@ -47,7 +47,7 @@ extension Placeholder {
|
||||
}()
|
||||
|
||||
static let memoEmpty: Info = {
|
||||
let icon: String = "wand.and.stars"
|
||||
let icon: String = "note.text"
|
||||
let title: String = "No Memos"
|
||||
let description: String = "Create a new memo to jot your thoughts or notes down."
|
||||
return Placeholder.Info(title: title, description: description, icon: icon)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Date++.swift
|
||||
// Memola
|
||||
//
|
||||
// Created by Dscyre Scotti on 6/27/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Date {
|
||||
func getTimeDifference(to date: Date) -> String {
|
||||
let calendar = Calendar.current
|
||||
|
||||
let components = calendar.dateComponents([.minute, .hour, .day, .weekOfYear, .month, .year], from: self, to: date)
|
||||
|
||||
if let years = components.year, years > 0 {
|
||||
return "\(years) year\(years > 1 ? "s" : "") ago"
|
||||
} else if let months = components.month, months > 0 {
|
||||
return "\(months) month\(months > 1 ? "s" : "") ago"
|
||||
} else if let weeks = components.weekOfYear, weeks > 0 {
|
||||
return "\(weeks) week\(weeks > 1 ? "s" : "") ago"
|
||||
} else if let days = components.day, days > 0 {
|
||||
return "\(days) day\(days > 1 ? "s" : "") ago"
|
||||
} else if let hours = components.hour, hours > 0 {
|
||||
return "\(hours) hour\(hours > 1 ? "s" : "") ago"
|
||||
} else if let minutes = components.minute, minutes > 0 {
|
||||
return "\(minutes) minute\(minutes > 1 ? "s" : "") ago"
|
||||
} else {
|
||||
return "just now"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,14 @@ struct MemosView: View {
|
||||
|
||||
@State var memo: MemoObject?
|
||||
@State var query: String = ""
|
||||
@State var currentDate: Date = .now
|
||||
|
||||
@AppStorage("memola.memo-objects.sort") var sort: Sort = .recent
|
||||
@AppStorage("memola.memo-objects.filter") var filter: Filter = .none
|
||||
|
||||
let cellWidth: CGFloat = 250
|
||||
let cellHeight: CGFloat = 150
|
||||
let timer = Timer.publish(every: 60, on: .main, in: .common).autoconnect()
|
||||
|
||||
init() {
|
||||
let standard = UserDefaults.standard
|
||||
@@ -92,6 +94,9 @@ struct MemosView: View {
|
||||
.onChange(of: filter) { oldValue, newValue in
|
||||
updatePredicate()
|
||||
}
|
||||
.onReceive(timer) { date in
|
||||
currentDate = date
|
||||
}
|
||||
.onAppear {
|
||||
memoObjects.sortDescriptors = sort.memoSortDescriptors
|
||||
updatePredicate()
|
||||
@@ -123,9 +128,15 @@ struct MemosView: View {
|
||||
Rectangle()
|
||||
.frame(height: cellHeight)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||
Text(memoObject.title)
|
||||
.font(.headline)
|
||||
.fontWeight(.semibold)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(memoObject.title)
|
||||
.font(.headline)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
Text("Edited \(memoObject.updatedAt.getTimeDifference(to: currentDate))")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
openMemo(for: memoObject)
|
||||
|
||||
Reference in New Issue
Block a user