-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from joeldesante/dev
Improve timeline and code quality
- Loading branch information
Showing
10 changed files
with
284 additions
and
167 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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
// | ||
// Entries.swift | ||
// moodmoji | ||
// | ||
// Created by Joel DeSante on 1/29/23. | ||
// | ||
|
||
import Foundation | ||
|
||
class Timeline: ObservableObject { | ||
|
||
private let logModel: LogModel; | ||
@Published var logs: [Log]; | ||
|
||
init() { | ||
self.logModel = LogFileSystem(); | ||
self.logs = []; | ||
self.loadLogs(); | ||
} | ||
|
||
func createLog(log: Log) { | ||
logModel.save(log: log); | ||
logs.append(log); | ||
self.logs = self.sortLogsByDate(logs: self.logs); | ||
} | ||
|
||
func loadLogs() { | ||
self.logs = self.sortLogsByDate(logs: self.logModel.loadAllLogs()); | ||
} | ||
|
||
func getLogsAsText() -> String { | ||
var text = ""; | ||
for log in logs { | ||
text.append("\(log.getString())---\n\n") | ||
} | ||
return text; | ||
} | ||
|
||
private func sortLogsByDate(logs: [Log]) -> [Log] { | ||
let sortedEntries = logs.sorted { | ||
$0.date > $1.date | ||
} | ||
|
||
return sortedEntries; | ||
} | ||
} |
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,27 @@ | ||
// | ||
// Log.swift | ||
// moodmoji | ||
// | ||
// Created by Joel DeSante on 2/3/23. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Log: Identifiable { | ||
let id: UUID; | ||
let emotions: String; | ||
let notes: String; | ||
let date: Date; | ||
|
||
init(id: UUID, emotions: String, notes: String, date: Date) { | ||
self.id = id | ||
self.emotions = emotions | ||
self.notes = notes | ||
self.date = date | ||
} | ||
|
||
func getString() -> String { | ||
let output = "\(self.date.formatted())\n\(self.emotions)\n\(self.notes)\n"; | ||
return output; | ||
} | ||
} |
Oops, something went wrong.