From 1c9c0f786a0f25b5ccb507b7a2509edeef8a6a14 Mon Sep 17 00:00:00 2001 From: sgr-ksmt Date: Mon, 30 Sep 2019 00:27:20 +0900 Subject: [PATCH] add tasks listener query: sort `updateTime` `desc`. --- FireTodo/Firebase/Task.swift | 2 +- FireTodo/Redux/Tasks/TasksAction.swift | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/FireTodo/Firebase/Task.swift b/FireTodo/Firebase/Task.swift index 8485a8b..5b6c759 100644 --- a/FireTodo/Firebase/Task.swift +++ b/FireTodo/Firebase/Task.swift @@ -7,7 +7,7 @@ import FireSnapshot import SwiftUI extension Model { - struct Task: Codable, HasTimestamps, Equatable { + struct Task: HasTimestamps, Codable, Equatable{ var title: String = "" var desc: String = "" var completed: Bool = false diff --git a/FireTodo/Redux/Tasks/TasksAction.swift b/FireTodo/Redux/Tasks/TasksAction.swift index 5fb8832..fa95cfb 100644 --- a/FireTodo/Redux/Tasks/TasksAction.swift +++ b/FireTodo/Redux/Tasks/TasksAction.swift @@ -13,7 +13,9 @@ enum TasksAction: Action { static func subscribe(userID: String) -> AppThunkAction { AppThunkAction { dispatch, _ in - let listener = Snapshot.listen(Model.Path.tasks(userID: userID)) { result in + let listener = Snapshot.listen(Model.Path.tasks(userID: userID), queryBuilder: { + $0.order(by: "updateTime", descending: true).limit(to: 30) + }) { result in switch result { case let .success(tasks): dispatch(TasksAction.updateTasks(tasks: tasks))