This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Load all instances, but shuffle in JS

  • Loading branch information...
Gargron committed Nov 6, 2017
1 parent a0f323e commit 79ddeb204cd1dbea717654ea73177d4c8f5298b5
Showing with 39 additions and 7 deletions.
  1. +3 −1 src/WizardRow.js
  2. +23 −3 src/actions.js
  3. +13 −3 src/scss/Wizard.scss
View
@@ -38,7 +38,9 @@ const WizardRow = ({ instance, intl }) => {
return (
<a href={`https://${instance.name}/about`} target='_blank' rel='noopener' className={classNames('wizard-row', { offline: !instance.up })}>
<div className='wizard-row__thumbnail'>
<div style={{ backgroundImage: `url(${instance.thumbnail})` }} />
<div>
<img src={instance.thumbnail} alt='' />
</div>
</div>
<div className='wizard-row__details'>
View
@@ -7,15 +7,35 @@ export const SEARCH_VALUE_CHANGE = 'SEARCH_VALUE_CHANGE';
export const LOCALE_CHANGE = 'LOCALE_CHANGE';
export const INSTANCES_LOCALE_CHANGE = 'INSTANCES_LOCALE_CHANGE';
const shuffle = array => {
let currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
};
export function fetchInstances() {
return (dispatch, getState) => {
if (getState().instances.length > 0) {
return;
}
axios('https://instances.social/api/1.0/instances/list?count=1000', {
headers: {'Authorization': `Bearer ${INSTANCES_API_TOKEN}`},
}).then(response => dispatch(fetchInstancesSuccess(response.data.instances)));
const headers = { 'Authorization': `Bearer ${INSTANCES_API_TOKEN}` };
const params = { count: 0, include_down: false, include_closed: false, sort_by: 'users', sort_order: 'desc' };
axios.get('https://instances.social/api/1.0/instances/list', { headers, params }).then(res => {
let { instances } = res.data;
shuffle(instances);
dispatch(fetchInstancesSuccess(instances));
});
};
};
View
@@ -91,11 +91,21 @@
& > div {
margin: 0 10px;
margin-right: 0;
background-color: $darkest;
background-size: cover;
background-position: center;
overflow: hidden;
border-radius: 4px;
width: 100%;
position: relative;
background: $darkest;
img {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
}
}

0 comments on commit 79ddeb2

Please sign in to comment.