Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IT2810 H20
Team Ad Hoc
4-t-h
Commits
58d35bf8
Commit
58d35bf8
authored
Nov 13, 2020
by
Thor-Herman
Browse files
Add comments and remove unused code for reducers
#15
parent
a45f7405
Changes
8
Hide whitespace changes
Inline
Side-by-side
prosjekt-4/reducers/filterReducer.ts
View file @
58d35bf8
import
{
combineReducers
}
from
"
redux
"
;
import
{
CHANGE_FILTER
,
CLEAR_FILTER
,
FilterAction
,
FilterState
}
from
"
../types/filter
"
;
import
{
CHANGE_ORDERING
,
CLEAR_ORDERING
,
OrderingAction
,
OrderingState
}
from
"
../types/ordering
"
;
import
{
CHANGE_FILTER
,
FilterAction
,
FilterState
}
from
"
../types/filter
"
;
import
{
CHANGE_ORDERING
,
OrderingAction
,
OrderingState
}
from
"
../types/ordering
"
;
const
initialFilterState
=
{
genres
:
{
...
...
@@ -11,28 +11,25 @@ const initialFilterState = {
Musical
:
false
,
Drama
:
false
,
},
year
:
{
to
:
""
,
from
:
""
}
year
:
{
to
:
""
,
from
:
""
}
// TODO: Remove
}
// Stores which genres are currently checked
const
filter
=
(
state
:
FilterState
=
initialFilterState
,
action
:
FilterAction
):
FilterState
=>
{
switch
(
action
.
type
)
{
case
CHANGE_FILTER
:
return
{...
action
.
payload
}
case
CLEAR_FILTER
:
return
{...
initialFilterState
};
default
:
return
state
;
}
};
// Stores what the ordering term is and if it is ascending or descending
const
ordering
=
(
state
:
OrderingState
=
{
key
:
"
title
"
,
order
:
"
asc
"
},
action
:
OrderingAction
):
OrderingState
=>
{
switch
(
action
.
type
)
{
case
CHANGE_ORDERING
:
return
{...
state
,
...
action
.
payload
};
case
CLEAR_ORDERING
:
return
{
key
:
""
,
order
:
"
asc
"
};
default
:
return
state
;
}
...
...
prosjekt-4/reducers/index.ts
View file @
58d35bf8
...
...
@@ -3,6 +3,7 @@ import movies from './movieReducer';
import
filtering
from
'
./filterReducer
'
;
import
page
from
'
./pageReducer
'
;
// Combines the different states into one root reducer
const
rootReducer
=
combineReducers
(
{
movies
,
filtering
,
page
}
);
...
...
prosjekt-4/reducers/movieReducer.ts
View file @
58d35bf8
...
...
@@ -9,6 +9,7 @@ type byIdState = {
type
allIdsState
=
Array
<
Movie
>
;
// An object containing each Movie object, where their Id is the key
const
byId
=
(
state
:
byIdState
=
{},
action
:
MovieActionTypes
)
=>
{
switch
(
action
.
type
)
{
case
ADD_MOVIE
:
...
...
@@ -22,6 +23,7 @@ const byId = (state: byIdState = {}, action: MovieActionTypes) => {
}
};
// An array containing all the currently stored Ids of movies
const
allIds
=
(
state
:
allIdsState
=
[],
action
:
MovieActionTypes
)
=>
{
switch
(
action
.
type
)
{
case
ADD_MOVIE
:
...
...
@@ -36,6 +38,7 @@ const allIds = (state: allIdsState = [], action: MovieActionTypes) => {
}
};
// Stores the current search term
const
searchTerm
=
(
state
=
""
,
action
:
MovieActionTypes
)
=>
{
switch
(
action
.
type
){
case
SEARCH_TITLES
:
...
...
prosjekt-4/reducers/pageReducer.ts
View file @
58d35bf8
import
{
CHANGE_PAGE
,
PAGE_SIZE
,
ChangePageAction
,
PageState
,
UPDATE_TOTAL_PAGES
,
PageActions
}
from
"
../types/page
"
;
import
{
CHANGE_PAGE
,
PageState
,
UPDATE_TOTAL_PAGES
,
PageActions
}
from
"
../types/page
"
;
const
initialPageState
=
{
total
:
1
,
...
...
prosjekt-4/selectors/movieSelector.ts
View file @
58d35bf8
...
...
@@ -5,6 +5,8 @@ import { Movie } from "../types/movies";
const
selectMoviesById
=
(
state
:
RootState
):
Record
<
number
,
Movie
>
=>
state
.
movies
.
byId
;
const
selectMoviesAllIds
=
(
state
:
RootState
):
Array
<
number
>
=>
state
.
movies
.
allIds
;
// Selects movies using the allIds ordering, which is the correct ordering received from backend
// byId is unordered since it is an object
export
const
selectMoviesByAllIdsOrdering
=
createSelector
(
selectMoviesById
,
selectMoviesAllIds
,
...
...
prosjekt-4/store/index.ts
View file @
58d35bf8
import
{
compose
,
createStore
,
applyMiddleware
}
from
'
redux
'
;
import
{
createStore
,
applyMiddleware
}
from
'
redux
'
;
import
reducers
from
'
../reducers
'
;
import
thunk
from
'
redux-thunk
'
;
import
{
composeWithDevTools
}
from
'
redux-devtools-extension
'
;
...
...
prosjekt-4/types/filter.ts
View file @
58d35bf8
...
...
@@ -12,7 +12,6 @@ export type FilterFormData = {
// Action types
export
const
CHANGE_FILTER
=
"
CHANGE_FILTER
"
;
export
const
CLEAR_FILTER
=
"
CLEAR_FILTER
"
;
// Redux action
export
type
FilterAction
=
{
type
:
string
,
payload
:
FilterState
};
...
...
prosjekt-4/types/ordering.ts
View file @
58d35bf8
export
const
CHANGE_ORDERING
=
"
CHANGE_ORDERING
"
;
export
const
CLEAR_ORDERING
=
"
CLEAR_ORDERING
"
;
export
type
OrderingOptions
=
""
|
"
title
"
|
"
length
"
|
"
year
"
...
...
Thor-Herman Van Eggelen
@theggele
mentioned in commit
a61dfa07
·
Nov 13, 2020
mentioned in commit
a61dfa07
mentioned in commit a61dfa07b591e4c8b918892e24239fafe26875fe
Toggle commit list
Write
Preview
Supports
Markdown
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