diff --git a/frontend/src/Documents/Overview.tsx b/frontend/src/Documents/Overview.tsx
index 4caa49d..6cbf0ce 100644
--- a/frontend/src/Documents/Overview.tsx
+++ b/frontend/src/Documents/Overview.tsx
@@ -12,7 +12,6 @@ import { IAppState } from "~redux/reducers";
import { DocsList } from "./DocsList";
export interface IOverviewComponentProps {
- recent: IDocumentJSON[] | null;
all: IDocumentJSON[] | null;
fetching: boolean;
spinner: boolean;
@@ -36,11 +35,14 @@ export class OverviewComponent extends React.PureComponent<
public render() {
if (this.props.all) {
+ const recent = [...this.props.all];
+ recent.sort((a, b) => b.editedAt - a.editedAt);
+ const recentCut = recent.splice(0, 4);
return (
Recent
-
+
@@ -57,7 +59,6 @@ export class OverviewComponent extends React.PureComponent<
function mapStateToProps(state: IAppState) {
return {
- recent: state.docs.recent,
all: state.docs.all,
fetching: state.docs.fetching,
spinner: state.docs.spinner,
diff --git a/frontend/src/redux/docs/actions.ts b/frontend/src/redux/docs/actions.ts
index cb0c1f9..a8f5261 100644
--- a/frontend/src/redux/docs/actions.ts
+++ b/frontend/src/redux/docs/actions.ts
@@ -26,7 +26,6 @@ export interface IDocsFetchFailAction extends Action {
export interface IDocsFetchSuccessAction extends Action {
type: DocsTypes.DOCS_FETCH_SUCCESS;
payload: {
- recent: IDocumentJSON[];
all: IDocumentJSON[];
};
}
@@ -44,10 +43,9 @@ export function fetchDocsFail(error: string): IDocsFetchFailAction {
}
export function fetchDocsSuccess(
- recent: IDocumentJSON[],
all: IDocumentJSON[],
): IDocsFetchSuccessAction {
- return { type: DocsTypes.DOCS_FETCH_SUCCESS, payload: { recent, all } };
+ return { type: DocsTypes.DOCS_FETCH_SUCCESS, payload: { all } };
}
export type DocsAction =
diff --git a/frontend/src/redux/docs/reducer.ts b/frontend/src/redux/docs/reducer.ts
index 0cc71fd..132fa48 100644
--- a/frontend/src/redux/docs/reducer.ts
+++ b/frontend/src/redux/docs/reducer.ts
@@ -4,7 +4,6 @@ import { IDocumentJSON } from "~../../src/entity/Document";
import { DocsAction, DocsTypes } from "./actions";
export interface IDocsState {
- recent: IDocumentJSON[] | null;
all: IDocumentJSON[] | null;
fetching: boolean;
error: string | null;
@@ -12,7 +11,6 @@ export interface IDocsState {
}
const defaultDocsState: IDocsState = {
- recent: null,
all: null,
fetching: false,
error: null,
diff --git a/frontend/src/redux/docs/sagas.ts b/frontend/src/redux/docs/sagas.ts
index b27e383..c516d69 100644
--- a/frontend/src/redux/docs/sagas.ts
+++ b/frontend/src/redux/docs/sagas.ts
@@ -8,7 +8,7 @@ import {
race,
takeLatest,
} from "redux-saga/effects";
-import { fetchAllDocs, fetchRecentDocs } from "~redux/api/docs";
+import { fetchAllDocs } from "~redux/api/docs";
import {
DocsTypes,
@@ -28,7 +28,7 @@ function* docsFetchStart(action: IDocsFetchStartAction) {
const spinner = yield fork(startSpinner);
const { response, timeout } = yield race({
- response: all([call(fetchRecentDocs), call(fetchAllDocs)]),
+ response: call(fetchAllDocs),
timeout: call(delay, 10000),
});
@@ -40,12 +40,11 @@ function* docsFetchStart(action: IDocsFetchStartAction) {
}
if (response) {
- if (response[0].data == null || response[1].data == null) {
- yield put(fetchDocsFail(response[0].error));
+ if (response.data == null) {
+ yield put(fetchDocsFail(response.error));
} else {
- const recentDocs = response[0].data;
- const allDocs = response[1].data;
- yield put(fetchDocsSuccess(recentDocs, allDocs));
+ const allDocs = response.data;
+ yield put(fetchDocsSuccess(allDocs));
}
}
} catch (e) {
diff --git a/src/routes/docs.ts b/src/routes/docs.ts
index 556fc77..f3a7393 100644
--- a/src/routes/docs.ts
+++ b/src/routes/docs.ts
@@ -94,24 +94,6 @@ docsRouter.get("/docs/list", async ctx => {
};
});
-docsRouter.get("/docs/list/recent", async ctx => {
- if (!ctx.state.user) {
- ctx.throw(401);
- }
-
- const { user } = ctx.state;
-
- const documents = await Document.find({
- where: { user: user.id },
- order: { editedAt: "DESC" },
- });
-
- ctx.body = {
- error: false,
- data: documents.map(document => document.toJSON(user.id)),
- };
-});
-
docsRouter.get("/docs/byID/:id", async ctx => {
if (!ctx.state.user) {
ctx.throw(401);
diff --git a/tests/integration/docs.test.ts b/tests/integration/docs.test.ts
index 28150a6..20ef4e7 100644
--- a/tests/integration/docs.test.ts
+++ b/tests/integration/docs.test.ts
@@ -93,38 +93,6 @@ describe("docs", () => {
expect(documents).to.deep.equal(userDocs);
});
- it("should list recent docs", async () => {
- const doc1 = new Document(seed.user1, "doc1", "");
- doc1.editedAt = new Date(doc1.editedAt.getTime() + 10000);
- await doc1.save();
- const doc2 = new Document(seed.user1, "doc2", "");
- doc2.editedAt = new Date(doc2.editedAt.getTime() + 20000);
- await doc2.save();
- const doc3 = new Document(seed.user1, "doc3", "");
- doc3.editedAt = new Date(doc3.editedAt.getTime() + 30000);
- await doc3.save();
-
- const response = await request(callback)
- .get("/docs/list/recent")
- .set({
- Authorization: `Bearer ${seed.user1.toJWT()}`,
- })
- .expect(200);
-
- expect(response.body.error).to.be.false;
-
- const documents = response.body.data as IDocumentJSON[];
-
- const userDocs = [
- doc3.toJSON(seed.user1.id),
- doc2.toJSON(seed.user1.id),
- doc1.toJSON(seed.user1.id),
- seed.doc1.toJSON(seed.user1.id),
- ];
-
- expect(documents).to.deep.equal(userDocs);
- });
-
it("should get a document", async () => {
const response = await request(callback)
.get(`/docs/byID/${seed.doc1.id}`)