From e6fec50cd079454e2c5154a4963ba09e02720070 Mon Sep 17 00:00:00 2001 From: Brysen Ackx Date: Thu, 27 Jul 2017 10:38:16 +0200 Subject: [PATCH 1/9] randomize homepage snippers & stories --- src/helpers/{RoomIdGenerator.js => RandomHelpers.js} | 11 +++++++++++ src/redux/actions.js | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) rename src/helpers/{RoomIdGenerator.js => RandomHelpers.js} (62%) diff --git a/src/helpers/RoomIdGenerator.js b/src/helpers/RandomHelpers.js similarity index 62% rename from src/helpers/RoomIdGenerator.js rename to src/helpers/RandomHelpers.js index bdebf0e..f6a8886 100644 --- a/src/helpers/RoomIdGenerator.js +++ b/src/helpers/RandomHelpers.js @@ -13,3 +13,14 @@ export const RoomIdGenerator = { return text; } }; + +export const shuffle = arr => { + let j, x, i; + for (i = arr.length; i; i--) { + j = Math.floor(Math.random() * i); + x = arr[i - 1]; + arr[i - 1] = arr[j]; + arr[j] = x; + } + return arr; +}; diff --git a/src/redux/actions.js b/src/redux/actions.js index a8de617..0d23b98 100644 --- a/src/redux/actions.js +++ b/src/redux/actions.js @@ -5,6 +5,7 @@ import { } from '../helpers/firebase'; import { push } from 'connected-react-router'; import moment from 'moment'; +import { shuffle } from '../helpers/RandomHelpers'; export const actionTypes = { listenToFirebaseAuth: 'LISTEN_FIREBASE_AUTH', @@ -103,7 +104,9 @@ export const fetchRandomStories = () => { .ref('/stories') .once('value') .then(snapshot => { - dispatch(fetchRandomStoriesFulfilled(snapshot.val())); + let randomStories = shuffle(snapshot.val()); + + dispatch(fetchRandomStoriesFulfilled(randomStories.splice(0, 3))); }) .catch(err => { dispatch(fetchRandomStoriesRejected(err)); @@ -776,7 +779,9 @@ export const fetchRandomSnippers = () => { firebaseDatabase.ref(`/creations`).once('value').then(snippers => { const val = snippers.val(); const keys = Object.keys(val); - dispatch(fetchRandomSnippersFulfilled(keys.map(id => val[id]))); + let randomSnippers = shuffle(keys.map(key => val[key])); + // keys.map(id => val[id]) + dispatch(fetchRandomSnippersFulfilled(randomSnippers.splice(0, 4))); }); }; }; From 51fc07b277821bdbf697b2e314de72b41a1a8ca1 Mon Sep 17 00:00:00 2001 From: Brysen Ackx Date: Thu, 27 Jul 2017 11:23:17 +0200 Subject: [PATCH 2/9] hotfixes --- src/components/creations1/Creations1.js | 8 +++++++- src/components/nav/Navlink.scss | 4 ++++ src/containers/views/Room/Room.scss | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/creations1/Creations1.js b/src/components/creations1/Creations1.js index ff1d429..719199e 100644 --- a/src/components/creations1/Creations1.js +++ b/src/components/creations1/Creations1.js @@ -10,7 +10,13 @@ const Creations1 = ({ snipper }) => { onClick={e => history.push(`/snippers/${snipper.id}`)} > {snipper.fileType === 'video' - ?