Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Project4
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
IT2810-H19
T
Teams
Team 8
Project4
Commits
6e195ee8
Commit
6e195ee8
authored
Nov 12, 2019
by
Halvor Horge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4
We can now display information from the backend in the front end
parent
f07f031e
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
345 additions
and
80 deletions
+345
-80
p4/.expo/packager-info.json
p4/.expo/packager-info.json
+4
-4
p4/.expo/settings.json
p4/.expo/settings.json
+1
-1
p4/App.js
p4/App.js
+8
-1
p4/package-lock.json
p4/package-lock.json
+205
-2
p4/package.json
p4/package.json
+4
-0
p4/src/components/Content.js
p4/src/components/Content.js
+107
-72
p4/src/components/Elements.js
p4/src/components/Elements.js
+16
-0
No files found.
p4/.expo/packager-info.json
View file @
6e195ee8
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
"devToolsPort"
:
19002
,
"devToolsPort"
:
19002
,
"expoServerPort"
:
19000
,
"expoServerPort"
:
19000
,
"packagerPort"
:
19001
,
"packagerPort"
:
19001
,
"packagerPid"
:
22
12
,
"packagerPid"
:
110
12
,
"expoServerNgrokUrl"
:
"https://
5v-9za.anonymous
.p4.exp.direct"
,
"expoServerNgrokUrl"
:
"https://
8h-zc8.hhorge
.p4.exp.direct"
,
"packagerNgrokUrl"
:
"https://packager.
5v-9za.anonymous
.p4.exp.direct"
,
"packagerNgrokUrl"
:
"https://packager.
8h-zc8.hhorge
.p4.exp.direct"
,
"ngrokPid"
:
1260
"ngrokPid"
:
8404
}
}
p4/.expo/settings.json
View file @
6e195ee8
...
@@ -3,6 +3,6 @@
...
@@ -3,6 +3,6 @@
"lanType"
:
"ip"
,
"lanType"
:
"ip"
,
"dev"
:
true
,
"dev"
:
true
,
"minify"
:
false
,
"minify"
:
false
,
"urlRandomness"
:
"
5v-9za
"
,
"urlRandomness"
:
"
8h-zc8
"
,
"https"
:
false
"https"
:
false
}
}
p4/App.js
View file @
6e195ee8
...
@@ -5,7 +5,12 @@ import Top from './src/components/Top'
...
@@ -5,7 +5,12 @@ import Top from './src/components/Top'
import
{
createStore
}
from
"
redux
"
;
import
{
createStore
}
from
"
redux
"
;
import
allReducer
from
"
./src/reducers
"
;
import
allReducer
from
"
./src/reducers
"
;
import
{
Provider
}
from
"
react-redux
"
;
import
{
Provider
}
from
"
react-redux
"
;
import
ApolloClient
from
'
apollo-boost
'
;
import
{
ApolloProvider
}
from
'
@apollo/react-hooks
'
const
client
=
new
ApolloClient
({
uri
:
'
http://it2810-26.idi.ntnu.no:4000
'
})
const
store
=
createStore
(
const
store
=
createStore
(
allReducer
,
allReducer
,
...
@@ -22,9 +27,11 @@ export default class App extends Component {
...
@@ -22,9 +27,11 @@ export default class App extends Component {
return
(
return
(
<
View
>
<
View
>
{
/*<Text style={styles.instructions}>{instructions}</Text>*/
}
{
/*<Text style={styles.instructions}>{instructions}</Text>*/
}
<
Provider
store
=
{
store
}
>
<
Provider
store
=
{
store
}
>
<
ApolloProvider
client
=
{
client
}
>
<
Top
/>
<
Top
/>
<
Body
/>
<
Body
/>
<
/ApolloProvider
>
<
/Provider
>
<
/Provider
>
<
/View
>
<
/View
>
);
);
...
...
p4/package-lock.json
View file @
6e195ee8
This diff is collapsed.
Click to expand it.
p4/package.json
View file @
6e195ee8
...
@@ -8,7 +8,11 @@
...
@@ -8,7 +8,11 @@
"test"
:
"jest"
"test"
:
"jest"
},
},
"dependencies"
:
{
"dependencies"
:
{
"@apollo/react-hooks"
:
"^3.1.3"
,
"apollo-boost"
:
"^0.4.4"
,
"expo"
:
"^35.0.0"
,
"expo"
:
"^35.0.0"
,
"graphql"
:
"^14.5.8"
,
"graphql-tag"
:
"^2.10.1"
,
"react"
:
"16.8.3"
,
"react"
:
"16.8.3"
,
"react-dom"
:
"16.8.3"
,
"react-dom"
:
"16.8.3"
,
"react-native"
:
"0.59.10"
,
"react-native"
:
"0.59.10"
,
...
...
p4/src/components/Content.js
View file @
6e195ee8
import
React
from
'
react
'
;
import
React
from
"
react
"
;
import
{
Text
,
StyleSheet
,
ScrollView
,
Image
}
from
'
react-native
'
;
import
{
Text
,
StyleSheet
,
ScrollView
,
Image
,
View
}
from
"
react-native
"
;
import
Search
from
'
./Search
'
;
import
Search
from
"
./Search
"
;
import
{
ListItem
}
from
'
react-native-elements
'
;
import
{
ListItem
}
from
"
react-native-elements
"
;
import
{
useSelector
}
from
"
react-redux
"
;
import
{
useSelector
}
from
"
react-redux
"
;
import
{
useDispatch
}
from
"
react-redux
"
;
import
{
useDispatch
}
from
"
react-redux
"
;
import
{
details
,
nextPage
,
prevPage
}
from
"
../actions
"
;
import
{
details
,
nextPage
,
prevPage
}
from
"
../actions
"
;
import
Details
from
"
./Details
"
import
Details
from
"
./Details
"
;
import
{
isOverlayVisible
}
from
"
../actions
"
;
import
{
isOverlayVisible
}
from
"
../actions
"
;
import
{
gql
}
from
"
apollo-boost
"
;
import
{
useQuery
}
from
"
@apollo/react-hooks
"
;
import
Elements
from
"
./Elements
"
;
const
GET_PRODUCTS
=
gql
`
query Products(
$limit: Int
$sort: String
$search: String
$filters: FilterInputObject
) {
products(limit: $limit, sort: $sort, search: $search, filters: $filters) {
products {
name
price
img
id
alcohol
volume
type
}
}
}
`
;
const
Content
=
()
=>
{
const
Content
=
()
=>
{
const
dispatch
=
useDispatch
();
const
dispatch
=
useDispatch
();
const
stateAlbums
=
useSelector
(
state
=>
state
.
albums
);
const
stateAlbums
=
useSelector
(
state
=>
state
.
albums
);
const
stateSearch
=
useSelector
(
state
=>
state
.
search
);
const
stateSearch
=
useSelector
(
state
=>
state
.
search
);
const
stateGenre
=
useSelector
(
state
=>
state
.
filter
);
const
stateGenre
=
useSelector
(
state
=>
state
.
filter
);
function
filterAlbums
(
Albums
)
{
let
filteredAlbums
=
[];
for
(
let
a
in
Albums
)
{
if
(
Albums
[
a
][
"
Album
"
]
.
toLowerCase
()
.
indexOf
(
stateSearch
.
toLowerCase
())
!==
-
1
)
{
filteredAlbums
.
push
(
Albums
[
a
]);
}
else
if
(
Albums
[
a
][
"
Artist
"
]
.
toLowerCase
()
.
indexOf
(
stateSearch
.
toLowerCase
())
!==
-
1
)
{
filteredAlbums
.
push
(
Albums
[
a
]);
}
else
if
(
Albums
[
a
][
"
Year
"
]
.
toLowerCase
()
.
indexOf
(
stateSearch
.
toLowerCase
())
!==
-
1
)
{
filteredAlbums
.
push
(
Albums
[
a
]);
}
}
return
filteredAlbums
;
}
function
genreFilter
(
albums
)
{
const
{
loading
,
error
,
data
}
=
useQuery
(
GET_PRODUCTS
,
{
let
f
=
[];
variables
:
{
limit
:
10
,
search
:
stateSearch
,
sort
:
"
-price
"
,
filters
:{
filterType
:
"
Vodka
"
}}
for
(
let
a
in
albums
)
{
});
if
(
albums
[
a
][
"
Genre
"
]
===
stateGenre
||
stateGenre
===
""
)
{
if
(
loading
)
return
<
Text
>
Loading
...
<
/Text>
;
f
.
push
({
if
(
error
)
return
<
Text
>
{
error
}
<
/Text>
;
title
:
albums
[
a
][
"
Album
"
],
subtitle
:
albums
[
a
][
"
Artist
"
]
const
productElements
=
data
.
products
.
products
.
map
(
product
=>
(
});
<
View
key
=
{
product
.
id
}
style
=
{{
display
:
"
flex
"
}}
>
}
<
Elements
}
name
=
{
product
.
name
}
return
f
;
img
=
{
product
.
img
}
}
price
=
{
product
.
price
}
alcohol
=
{
product
.
alcohol
}
volume
=
{
product
.
volume
}
type
=
{
product
.
type
}
/
>
<
/View
>
));
function
setDetailState
(
album
)
{
function
filterAlbums
(
Albums
)
{
dispatch
(
details
(
album
));
let
filteredAlbums
=
[];
for
(
let
a
in
Albums
)
{
if
(
Albums
[
a
][
"
Album
"
].
toLowerCase
().
indexOf
(
stateSearch
.
toLowerCase
())
!==
-
1
)
{
filteredAlbums
.
push
(
Albums
[
a
]);
}
else
if
(
Albums
[
a
][
"
Artist
"
].
toLowerCase
().
indexOf
(
stateSearch
.
toLowerCase
())
!==
-
1
)
{
filteredAlbums
.
push
(
Albums
[
a
]);
}
else
if
(
Albums
[
a
][
"
Year
"
].
toLowerCase
().
indexOf
(
stateSearch
.
toLowerCase
())
!==
-
1
)
{
filteredAlbums
.
push
(
Albums
[
a
]);
}
}
}
return
filteredAlbums
;
}
function
setOverlayState
(){
function
genreFilter
(
albums
)
{
dispatch
(
isOverlayVisible
());
let
f
=
[];
for
(
let
a
in
albums
)
{
if
(
albums
[
a
][
"
Genre
"
]
===
stateGenre
||
stateGenre
===
""
)
{
f
.
push
({
title
:
albums
[
a
][
"
Album
"
],
subtitle
:
albums
[
a
][
"
Artist
"
]
});
}
}
}
return
f
;
}
return
(
function
setDetailState
(
album
)
{
<
ScrollView
>
dispatch
(
details
(
album
));
{
}
genreFilter
(
filterAlbums
(
stateAlbums
)).
map
((
l
,
i
)
=>
(
<
ListItem
key
=
{
i
}
title
=
{
l
.
title
}
subtitle
=
{
l
.
subtitle
}
bottomDivider
chevron
onPress
=
{()
=>
setOverlayState
()}
/
>
))
}
<
Details
/>
<
/ScrollView
>
);
}
export
default
Content
;
function
setOverlayState
()
{
dispatch
(
isOverlayVisible
());
}
return
(
<
ScrollView
>
{
productElements
}
{
genreFilter
(
filterAlbums
(
stateAlbums
)).
map
((
l
,
i
)
=>
(
<
ListItem
key
=
{
i
}
title
=
{
l
.
title
}
subtitle
=
{
l
.
subtitle
}
bottomDivider
chevron
onPress
=
{()
=>
setOverlayState
()}
/
>
))}
<
Details
/>
<
/ScrollView
>
);
};
export
default
Content
;
p4/src/components/Elements.js
0 → 100644
View file @
6e195ee8
import
React
from
'
react
'
import
{
Text
,
View
,
Image
}
from
'
react-native
'
export
default
function
Elements
({
name
,
img
,
price
,
alcohol
,
volume
,
type
})
{
return
(
<
View
style
=
{{
borderWidth
:
1
,
borderColor
:
'
black
'
,
margin
:
10
,
alignItems
:
'
center
'
}}
>
<
Image
style
=
{{
resizeMode
:
"
contain
"
,
height
:
200
,
width
:
100
,
justifyContent
:
'
center
'
}}
source
=
{{
uri
:
img
}}
/
>
<
Text
>
Name
:
{
name
}
<
/Text
>
<
Text
>
Price
:
{
price
},
-<
/Text
>
<
Text
>
Alcohol
:
{
alcohol
}
%
.
<
/Text
>
<
Text
>
Volume
:
{
volume
}
<
/Text
>
<
Text
>
Type
:
{
type
}
<
/Text
>
<
/View
>
)
}
\ No newline at end of file
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