Commit 0d3c92a2 authored by Mikkel Marstein's avatar Mikkel Marstein
Browse files

Merge branch 'komponent-for-display-av-søkeresultater' into 'master'

Api call til backend #5

See merge request !6
parents f86d9aa3 8e7be65e
......@@ -6,6 +6,7 @@
"flags": [],
"linkedModules": [],
"topLevelPatterns": [
"@types/axios@^0.14.0",
"bootstrap@5.1.1",
"react-bootstrap@^2.0.0-rc.0"
],
......@@ -22,6 +23,7 @@
"@restart/hooks@^0.3.26": "https://registry.yarnpkg.com/@restart/hooks/-/hooks-0.3.27.tgz#91f356d66d4699a8cd8b3d008402708b6a9dc505",
"@restart/hooks@^0.4.0": "https://registry.yarnpkg.com/@restart/hooks/-/hooks-0.4.1.tgz#716b1fd7a67650a6d4ed441b5d704b4f73ca2612",
"@restart/ui@^0.2.3": "https://registry.yarnpkg.com/@restart/ui/-/ui-0.2.3.tgz#8b68aa2ca07af799a65b288cc3c6039915c46a4c",
"@types/axios@^0.14.0": "https://registry.yarnpkg.com/@types/axios/-/axios-0.14.0.tgz#ec2300fbe7d7dddd7eb9d3abf87999964cafce46",
"@types/invariant@^2.2.33": "https://registry.yarnpkg.com/@types/invariant/-/invariant-2.2.35.tgz#cd3ebf581a6557452735688d8daba6cf0bd5a3be",
"@types/prop-types@*": "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11",
"@types/prop-types@^15.7.3": "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11",
......@@ -31,6 +33,7 @@
"@types/react@>=16.9.11": "https://registry.yarnpkg.com/@types/react/-/react-17.0.30.tgz#2f8e6f5ab6415c091cc5e571942ee9064b17609e",
"@types/scheduler@*": "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39",
"@types/warning@^3.0.0": "https://registry.yarnpkg.com/@types/warning/-/warning-3.0.0.tgz#0d2501268ad8f9962b740d387c4654f5f8e23e52",
"axios@*": "https://registry.yarnpkg.com/axios/-/axios-0.24.0.tgz#804e6fa1e4b9c5288501dd9dff56a7a0940d20d6",
"bootstrap@5.1.1": "https://registry.yarnpkg.com/bootstrap/-/bootstrap-5.1.1.tgz#9d6eed81e08feaccedf3adaca51fe4b73a2871df",
"classnames@^2.3.1": "https://registry.yarnpkg.com/classnames/-/classnames-2.3.1.tgz#dfcfa3891e306ec1dad105d0e88f4417b8535e8e",
"csstype@^3.0.2": "https://registry.yarnpkg.com/csstype/-/csstype-3.0.9.tgz#6410af31b26bd0520933d02cbc64fce9ce3fbf0b",
......@@ -38,6 +41,7 @@
"dom-helpers@^5.0.1": "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-5.2.1.tgz#d9400536b2bf8225ad98fe052e029451ac40e902",
"dom-helpers@^5.2.0": "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-5.2.1.tgz#d9400536b2bf8225ad98fe052e029451ac40e902",
"dom-helpers@^5.2.1": "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-5.2.1.tgz#d9400536b2bf8225ad98fe052e029451ac40e902",
"follow-redirects@^1.14.4": "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379",
"invariant@^2.2.4": "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6",
"js-tokens@^3.0.0 || ^4.0.0": "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499",
"loose-envify@^1.0.0": "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf",
......
......@@ -8,6 +8,11 @@ const graphqlHTTP = require('express-graphql').graphqlHTTP;
const app = express();
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(
'/graphql',
graphqlHTTP({
......@@ -21,7 +26,7 @@ const uri = 'mongodb://bruker1:gruppe28@it2810-28.idi.ntnu.no:27017/it2810?authS
const options = { useNewUrlParser: true, useUnifiedTopology: true };
mongoose.connect(uri, options)
.then(() => app.listen(3000, console.log("Server is active")))
.then(() => app.listen(3001, console.log("Server is active")))
.catch((error) => {
throw error
});
......
This diff is collapsed.
......@@ -3,6 +3,7 @@ import { Header } from './header/Header';
import "./Layout.css"
import { Searchbar } from './searchbar/searchbar';
import { Filter } from './searchbar/Filter';
import { getData } from '../utils/APIUtil';
interface IProps {
title: string
......@@ -11,6 +12,7 @@ const Layout: React.FC<IProps> = ({
title,
children
}) => {
getData()
return (
<div className="Layout">
<React.Fragment >
......
......@@ -24,11 +24,15 @@ export const CountryCard: FunctionComponent<IProps> = ({
<Card.Body>
<Card.Title>{country.name}</Card.Title>
<Card.Text>
{"ppl: " + country.population}
{country.continent}
</Card.Text>
{active && <>
<Card.Text>Area: {country.area}</Card.Text>
<Card.Text>Name: {country.name}</Card.Text>
<Card.Text>Capital: {country.capital}</Card.Text>
<Card.Text>Currecy: {country.currency}</Card.Text>
<Card.Text>Languages:
{country.languages.map((language => " " + language))}
</Card.Text>
</>
}
......
......@@ -4,6 +4,7 @@ import { Country } from '../../interfaces/Country';
import './SearchbarStore.tsx'
import { searchbarStore } from './SearchbarStore';
import { Search } from '@navikt/ds-icons';
import { getData } from '../../utils/APIUtil';
interface IProps {
items?: string[]
......@@ -22,7 +23,10 @@ export class Searchbar extends React.Component<IProps, IState> {
};
}
onSearch() {
searchbarStore.dispatch({ type: 'setState', NewCountry: dummyData });
getData().then((data) => {
searchbarStore.dispatch({ type: 'setState', NewCountry: data });
})
}
render() {
return (
......@@ -36,16 +40,4 @@ export class Searchbar extends React.Component<IProps, IState> {
{this.state.active && <div>Jeg er active</div>}
</div>)
}
}
const dummyData: Country[] = [
{ name: "Norway", population: 20, area: 10 },
{ name: "Sweden", population: 25, area: 11 },
{ name: "Iceland", population: 5, area: 3 },
{ name: "England", population: 60, area: 14 },
{ name: "Sri Lanka", population: 55, area: 8 },
{ name: "USA", population: 120, area: 60 },
{ name: "Poland", population: 35, area: 14 },
{ name: "Japan", population: 110, area: 40 },
{ name: "Denmark", population: 26, area: 9 },
{ name: "Finland", population: 22, area: 12 },
]
}
\ No newline at end of file
export interface Country{
native: string,
continent: string,
capital: string,
currency: string,
languages: string[]
name: string,
population: number,
area: number
}
\ No newline at end of file
import React from 'react';
import axios, {AxiosResponse} from 'axios';
import { Country } from '../interfaces/Country';
export function getData(): Promise<Country[]> {
return axios.get('http://localhost:3001/graphql?query={country{name, native, continent, capital, currency, languages}}')
.then((response: AxiosResponse) => {
console.log(response.data);
console.log(response.data.data.country[0]);
return response.data.data.country as Country[]
});
}
\ No newline at end of file
......@@ -56,6 +56,13 @@
uncontrollable "^7.2.1"
warning "^4.0.3"
"@types/axios@^0.14.0":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@types/axios/-/axios-0.14.0.tgz#ec2300fbe7d7dddd7eb9d3abf87999964cafce46"
integrity sha1-7CMA++fX3d1+udOr+HmZlkyvzkY=
dependencies:
axios "*"
"@types/invariant@^2.2.33":
version "2.2.35"
resolved "https://registry.yarnpkg.com/@types/invariant/-/invariant-2.2.35.tgz#cd3ebf581a6557452735688d8daba6cf0bd5a3be"
......@@ -92,6 +99,13 @@
resolved "https://registry.yarnpkg.com/@types/warning/-/warning-3.0.0.tgz#0d2501268ad8f9962b740d387c4654f5f8e23e52"
integrity sha1-DSUBJorY+ZYrdA04fEZU9fjiPlI=
axios@*:
version "0.24.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.24.0.tgz#804e6fa1e4b9c5288501dd9dff56a7a0940d20d6"
integrity sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==
dependencies:
follow-redirects "^1.14.4"
bootstrap@5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-5.1.1.tgz#9d6eed81e08feaccedf3adaca51fe4b73a2871df"
......@@ -120,6 +134,11 @@ dom-helpers@^5.0.1, dom-helpers@^5.2.0, dom-helpers@^5.2.1:
"@babel/runtime" "^7.8.7"
csstype "^3.0.2"
follow-redirects@^1.14.4:
version "1.14.4"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379"
integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==
invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment