rows created and orderedby createdAt TS

This commit is contained in:
shams mosowi
2019-09-12 17:07:23 +10:00
parent 1e89ab196b
commit 63eec2dc9b

View File

@@ -1,7 +1,9 @@
import { db } from "../firebase";
import { useEffect, useReducer } from "react";
import equals from "ramda/es/equals";
import { Cell } from "./useCell";
import firebase from "firebase/app";
const CAP = 500;
const tableReducer = (prevState: any, newProps: any) => {
@@ -28,6 +30,7 @@ const tableIntialState = {
prevLimit: 0,
limit: 20,
loading: true,
sort: { field: "createdAt", direction: "asc" },
cap: CAP
};
@@ -144,7 +147,9 @@ const useTable = (intialOverrides: any) => {
.update({ [cell.fieldName]: cell.value });
};
const addRow = () => {
db.collection(tableState.path).add({});
db.collection(tableState.path).add({
createdAt: firebase.firestore.FieldValue.serverTimestamp()
});
};
const tableActions = { deleteRow, setTable, updateCell, addRow };
return [tableState, tableActions];