Skip to content

Commit 70e5c9a

Browse files
committed
UUID + favorite support
1 parent deff08d commit 70e5c9a

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

BrickHack-Mobile/Controllers/ScheduleTableViewController.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ class ScheduleTableViewController: UITableViewController {
217217
// Update model
218218
// (We handle this condition!)
219219
let indexPath = IndexPath(row: favButton.row!, section: favButton.section!)
220-
print("\nUser did something to \(timelineEvents[convertIndex(fromIndexPath: indexPath)].event.title)")
220+
let selectedEvent = timelineEvents[convertIndex(fromIndexPath: indexPath)]
221+
selectedEvent.isFavorite = !selectedEvent.isFavorite
222+
print("user toggled \(selectedEvent.event.title)")
221223

222224
// @TODO: Handle updating favorite with server
223225
// @TODO: Handle notifying users on their favorited events
@@ -343,12 +345,24 @@ class ScheduleTableViewController: UITableViewController {
343345
ScheduleParser.retrieveEvents {
344346

345347
// On completion, update our copy of events
348+
// First, get a list of current events
349+
let favoriteEvents = self.timelineEvents.filter({ $0.isFavorite })
350+
print("Favorites: \(favoriteEvents)")
351+
346352
// (Rewrite instead of merge because merge logic is hard)
347353
self.timelineEvents.removeAll()
354+
348355
print("\nCleared timeline events.\n")
349356
for event in ScheduleParser.events {
350-
// @TODO: Fix color?
351-
self.timelineEvents.append(TimelineEvent(allColor: self.frontColor, event: event))
357+
let newEvent = TimelineEvent(allColor: self.frontColor, event: event)
358+
359+
// Add favorite tag back if previously favorited
360+
if favoriteEvents.filter({ $0.event.uuid == newEvent.event.uuid }).first != nil {
361+
print("found favorite \(newEvent)")
362+
newEvent.isFavorite = true
363+
}
364+
365+
self.timelineEvents.append(newEvent)
352366
}
353367

354368
completion()

BrickHack-Mobile/Models/ScheduleParser.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,25 @@ struct Event: CustomDebugStringConvertible {
3535
var title: String
3636
var location: String
3737
var description: String
38+
var uuid: String
3839

39-
init(day: Int, section: Int, time: Date, title: String, location: String, description: String) {
40+
init(day: Int, section: Int, time: Date, title: String, location: String, description: String, uuid: String) {
4041
self.day = day
4142
self.section = section
4243
self.time = time
4344
self.title = title
4445
self.location = location
4546
self.description = description
47+
self.uuid = uuid
4648
}
4749

4850
init() {
49-
self.init(day: 0, section: 0, time: Date(), title: "", location: "", description: "")
51+
self.init(day: 0, section: 0, time: Date(), title: "", location: "", description: "", uuid: "")
5052
}
5153

5254
// Using "debugDescription" instead of "description" because of name conflict with my "description" property.
5355
var debugDescription: String {
54-
return "\(day), \(section), \(timeString), \(title), \(location), \(self.description)"
56+
return "\(day), \(section), \(timeString), \(title), \(location), \(self.description), \(self.uuid)"
5557
}
5658
}
5759

@@ -247,10 +249,10 @@ class ScheduleParser {
247249
case 1: currentEvent.time = stringToDate(cellText) ?? Date()
248250
case 2: currentEvent.title = cellText
249251
case 3: currentEvent.location = cellText
250-
case 4:
251-
currentEvent.description = cellText
252+
case 4: currentEvent.description = cellText
253+
case 5: currentEvent.uuid = cellText
252254

253-
// Once we reach the fourth case, we know we're at the end of the data for a cell.
255+
// Once we reach the fifth case, we know we're at the end of the data for a cell.
254256
// This means that now we can reset the event!
255257
self.events.append(currentEvent)
256258
currentEvent = Event()
@@ -267,7 +269,6 @@ class ScheduleParser {
267269
// Otherwise, keep them in the same section.
268270
}
269271
}
270-
271272
default: break
272273
}
273274

0 commit comments

Comments
 (0)