diff --git a/frontend/package.json b/frontend/package.json
index 290e937..98876d6 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -9,7 +9,6 @@
"react-icons": "^3.7.0",
"react-redux": "^7.1.0",
"react-redux-loading": "^1.0.1",
- "react-router-dom": "^5.0.1",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0",
"fluence": "^0.3.9"
diff --git a/frontend/src/actions/messages.js b/frontend/src/actions/messages.js
index ab3fda5..a22c200 100644
--- a/frontend/src/actions/messages.js
+++ b/frontend/src/actions/messages.js
@@ -1,6 +1,4 @@
-import { saveMessage } from "../utils/api";
-
-//importing loading bar to show when we submit a tweet
+import {getMessages, saveMessage} from "../utils/api";
import { showLoading, hideLoading } from "react-redux-loading";
export const ADD_MESSAGE = "ADD_MESSAGE";
@@ -13,9 +11,31 @@ function addMessage(message) {
};
}
-//args: message text and the message that the newTweet is replying to, if any
+export function fetchPosts(counter) {
+ return dispatch => {
+
+ return getMessages().then((messages) => {
+ dispatch(receiveMessages(messages, counter));
+ dispatch(hideLoading());
+ });
+ };
+}
+
+export function handleInitialData() {
+ return dispatch => {
+ //before retrieving info, show loading bar
+ dispatch(showLoading());
+
+ return getMessages().then((messages) => {
+ dispatch(receiveMessages(messages, 0));
+
+ //after everything has loaded, hide loading bar
+ dispatch(hideLoading());
+ });
+ };
+}
+
export function handleAddMessage(text, name) {
- //using getState to get the current state of our store
return (dispatch) => {
dispatch(showLoading());
return saveMessage({
@@ -28,9 +48,10 @@ export function handleAddMessage(text, name) {
}
//action creator
-export function receiveMessages(messages) {
+export function receiveMessages(messages, counter) {
return {
type: RECEIVE_MESSAGES,
+ counter,
messages
};
}
diff --git a/frontend/src/actions/shared.js b/frontend/src/actions/shared.js
deleted file mode 100644
index 47b3503..0000000
--- a/frontend/src/actions/shared.js
+++ /dev/null
@@ -1,21 +0,0 @@
-import { getMessages } from "../utils/api";
-
-//importing action creators
-import { receiveMessages } from "./messages";
-
-//importing action creators of loading bar
-import { showLoading, hideLoading } from "react-redux-loading";
-
-export function handleInitialData() {
- return dispatch => {
- //before retrieving info, show loading bar
- dispatch(showLoading());
-
- return getMessages().then((messages) => {
- dispatch(receiveMessages(messages));
-
- //after everything has loaded, hide loading bar
- dispatch(hideLoading());
- });
- };
-}
diff --git a/frontend/src/components/App.js b/frontend/src/components/App.js
index 4de2b95..1fc1713 100644
--- a/frontend/src/components/App.js
+++ b/frontend/src/components/App.js
@@ -1,42 +1,30 @@
-import React, { Component, Fragment } from "react";
-import { BrowserRouter as Router, Route } from "react-router-dom";
-import { connect } from "react-redux";
-import { handleInitialData } from "../actions/shared";
+import React, {Component, Fragment} from "react";
+import {BrowserRouter as Router} from "react-router-dom";
+import {connect} from "react-redux";
import LoadingBar from "react-redux-loading"; //importing the loading bar given by react-redux-loading
-
import Dashboard from "./Dashboard";
import NewMessage from "./NewMessage";
class App extends Component {
- componentDidMount() {
- this.props.dispatch(handleInitialData());
- }
- render() {
- return (
-
{text}