aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/actions
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-01-29 16:31:05 +0100
committerGitHub <noreply@github.com>2018-01-29 16:31:05 +0100
commit694580bc532239a32c2fbf61d7f09e793fd1cb11 (patch)
treeacd21e2654d6c5e70dc41c675972794ce95b4062 /src/client/react/actions
parentf18692872cdc28d29917247ef4f8ef7553a8b023 (diff)
parent9a9edd1865d619caada787231c8bb34be25af3af (diff)
Merge pull request #15 from nloomans/react
Move project over to react
Diffstat (limited to 'src/client/react/actions')
-rw-r--r--src/client/react/actions/search.js19
-rw-r--r--src/client/react/actions/view.js31
2 files changed, 50 insertions, 0 deletions
diff --git a/src/client/react/actions/search.js b/src/client/react/actions/search.js
new file mode 100644
index 0000000..22daeca
--- /dev/null
+++ b/src/client/react/actions/search.js
@@ -0,0 +1,19 @@
+export const setUser = user => ({
+ type: 'SEARCH/SET_USER',
+ user,
+});
+
+export const inputChange = searchText => ({
+ type: 'SEARCH/INPUT_CHANGE',
+ searchText,
+});
+
+/**
+ * Change the selected result.
+ * @param {+1/-1} relativeChange usually +1 or -1, the change relative to the
+ * current result.
+ */
+export const changeSelectedResult = relativeChange => ({
+ type: 'SEARCH/CHANGE_SELECTED_RESULT',
+ relativeChange,
+});
diff --git a/src/client/react/actions/view.js b/src/client/react/actions/view.js
new file mode 100644
index 0000000..79ec143
--- /dev/null
+++ b/src/client/react/actions/view.js
@@ -0,0 +1,31 @@
+// eslint-disable-next-line import/prefer-default-export
+export const fetchSchedule = (user, week) => (dispatch) => {
+ dispatch({
+ type: 'VIEW/FETCH_SCHEDULE_REQUEST',
+ user,
+ week,
+ });
+
+ fetch(`/get/${user}?week=${week}`).then(
+ // success
+ (r) => {
+ r.text().then((htmlStr) => {
+ dispatch({
+ type: 'VIEW/FETCH_SCHEDULE_SUCCESS',
+ user,
+ week,
+ htmlStr,
+ });
+ });
+ },
+
+ // error
+ () => {
+ dispatch({
+ type: 'VIEW/FETCH_SCHEDULE_FAILURE',
+ week,
+ user,
+ });
+ },
+ );
+};