Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Enes Tasbasi
whats-open-web
Commits
e410e4e7
Commit
e410e4e7
authored
Jan 27, 2018
by
Mattias J Duffy
Browse files
Sort by open
parent
1254d190
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/actions/action-types.js
View file @
e410e4e7
...
...
@@ -7,4 +7,4 @@ export const SET_CAMPUS_REGION = 'SET_CAMPUS_REGION';
export
const
ADD_FAVORITE_FACILITY
=
'
ADD_FAVORITE_FACILITY
'
;
export
const
REMOVE_FAVORITE_FACILITY
=
'
REMOVE_FAVORITE_FACILITY
'
;
export
const
SET_ALL_FAVORITES
=
'
SET_ALL_FAVORITES
'
;
export
const
SORT_BY_FAVORITES
=
'
SORT_BY_FAVORITES
'
;
\ No newline at end of file
export
const
SORT_FACILITY_CARDS
=
'
SORT_FACILITY_CARDS
'
;
\ No newline at end of file
src/actions/api.js
View file @
e410e4e7
import
{
GET_FACILITIES
,
SET_FACILITIES
,
SORT_
BY_FAVORITES
}
from
'
./action-types
'
;
import
{
GET_FACILITIES
,
SET_FACILITIES
,
SORT_
FACILITY_CARDS
}
from
'
./action-types
'
;
const
API_GET_FACILITIES
=
'
https://api.srct.gmu.edu/whatsopen/v2/facilities/
'
;
// SHOP MASON ONLY
...
...
@@ -37,6 +37,7 @@ export const setFacilities = (facilities) => {
};
};
export
const
sortByFavorites
=
()
=>
({
type
:
SORT_BY_FAVORITES
});
\ No newline at end of file
export
const
sortFacilityCards
=
()
=>
({
type
:
SORT_FACILITY_CARDS
});
src/actions/ui.js
View file @
e410e4e7
...
...
@@ -37,3 +37,4 @@ export const setAllFavorites = (favorites) => ({
type
:
SET_ALL_FAVORITES
,
favorites
});
src/containers/Layout.js
View file @
e410e4e7
...
...
@@ -3,7 +3,7 @@ import {connect} from 'react-redux';
// import {setAllFavorites} from '../actions/ui';
import
AppBar
from
'
../components/AppBar
'
;
import
Sidebar
from
'
../components/Sidebar
'
;
import
{
getFacilities
,
setFacilities
,
sort
ByFavorite
s
}
from
'
../actions/api
'
;
import
{
getFacilities
,
setFacilities
,
sort
FacilityCard
s
}
from
'
../actions/api
'
;
import
{
setSidebar
,
setSelectedFacility
,
setAllFavorites
}
from
'
../actions/ui
'
;
import
CardContainer
from
'
../components/CardContainer
'
;
...
...
@@ -28,8 +28,7 @@ class Layout extends React.Component {
const
favorites
=
JSON
.
parse
(
localStorage
.
getItem
(
'
favorites
'
));
this
.
props
.
setAllFavorites
(
favorites
);
}
this
.
props
.
sortByFavorites
();
this
.
props
.
sortFacilityCards
();
}
catch
(
e
)
{
console
.
warn
(
'
you should enable cookies so we can remember what places you favorite
'
);
}
...
...
@@ -74,7 +73,7 @@ export default connect(mapStateToProps, {
getFacilities
,
setFacilities
,
setAllFavorites
,
sort
ByFavorite
s
,
sort
FacilityCard
s
,
setSidebar
,
setSelectedFacility
setSelectedFacility
,
})(
Layout
);
src/reducers/api.js
View file @
e410e4e7
import
{
GET_FACILITIES
,
SET_FACILITIES
,
SORT_
BY_FAVORITES
}
from
'
../actions/action-types
'
;
import
{
GET_FACILITIES
,
SET_FACILITIES
,
SORT_
FACILITY_CARDS
}
from
'
../actions/action-types
'
;
import
cloneDeep
from
'
lodash/cloneDeep
'
;
import
facilityUtils
from
'
../utils/facilityUtils
'
;
const
defaultState
=
{
isLoading
:
false
,
data
:
[]
};
export
const
facilities
=
(
state
=
defaultState
,
action
,
ui
)
=>
{
const
sortFunc
=
(
a
,
b
)
=>
{
const
facilitySort
=
(
a
,
b
)
=>
{
const
favoriteCheck
=
ui
.
favorites
.
includes
(
b
.
slug
)
-
ui
.
favorites
.
includes
(
a
.
slug
);
if
(
favoriteCheck
!==
0
)
{
return
ui
.
favorites
.
includes
(
b
.
slug
)
-
ui
.
favorites
.
includes
(
a
.
slug
);
return
favoriteCheck
;
}
const
openCheck
=
facilityUtils
.
isFacilityOpen
(
b
)
-
facilityUtils
.
isFacilityOpen
(
a
);
if
(
openCheck
!==
0
)
{
return
openCheck
;
}
if
(
a
.
slug
<
b
.
slug
)
{
...
...
@@ -22,9 +27,11 @@ export const facilities = (state = defaultState, action, ui) => {
return
1
;
}
return
0
;
};
const
newData
=
cloneDeep
(
state
.
data
);
switch
(
action
.
type
)
{
case
GET_FACILITIES
:
return
Object
.
assign
({},
state
,
{
...
...
@@ -32,13 +39,12 @@ export const facilities = (state = defaultState, action, ui) => {
});
case
SET_FACILITIES
:
return
Object
.
assign
({},
state
,
{
data
:
action
.
facilities
.
sort
(
sortFunc
),
data
:
action
.
facilities
.
sort
(
facilitySort
),
isLoading
:
false
});
case
SORT_BY_FAVORITES
:
const
newData
=
cloneDeep
(
state
.
data
);
case
SORT_FACILITY_CARDS
:
return
Object
.
assign
({},
state
,
{
data
:
newData
.
sort
(
sortFunc
)
data
:
newData
.
sort
(
facilitySort
)
});
default
:
return
state
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment