Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something was done #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,471 changes: 2,427 additions & 44 deletions README.md

Large diffs are not rendered by default.

9,755 changes: 9,755 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"name": "react-coding-challenge",
"version": "1.0.0",
"description": "A package containing a simple dummy book API, which should be used in the challenge",
"name": "solution",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-scripts": "1.0.10",
"react-table": "^6.8.0",
"semantic-ui-css": "^2.3.1",
"semantic-ui-react": "^0.79.1"
},
"scripts": {
"start": "json-server --port 3010 --watch api.json"
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"keywords": ["react challenge", "tryouts", "react developer", "hiring"],
"author": "Adapt A/S",
"license": "ISC",
"devDependencies": {
"json-server": "0.10.1"
"react-edit-inline": "^1.0.8"
}
}
Binary file added public/favicon.ico
Binary file not shown.
52 changes: 52 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>

<link rel="stylesheet" type="text/css" href="styles.css">

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
28 changes: 28 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.App {
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}

.App-title {
font-size: 1.5em;
}

.App-intro {
font-size: large;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
58 changes: 58 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, { Component } from 'react';
import './App.css';
import DropdownSelection from './components/DropdownSelection';
import BooksList from './components/BooksList';
import InfoAboutBook from './components/InfoAboutBook';

class App extends Component {
constructor(props) {
super(props);
this.state = {
selectedSubject: undefined,
selectedBook: undefined,
}
}

changeSubject(value) {
this.setState({
selectedSubject: value,
});
}

booksListPart() {
const { selectedSubject } = this.state;
if (!selectedSubject) {
return <div></div>;
}
return <BooksList selectedSub={selectedSubject} setId={this.setId.bind(this)}/>;
}

infoAboutBookPart() {
const { selectedBook } = this.state;
if (!selectedBook) {
return <div></div>;
}
return <InfoAboutBook idValue={selectedBook}/>;

}

setId(id) {
this.setState({
selectedBook: id,
});
}

render() {
return (
<div>
<h1>Book App</h1>
<DropdownSelection changeSub={this.changeSubject.bind(this)}/>
{this.booksListPart()}
<br/>
{this.infoAboutBookPart()}
</div>
);
}
}

export default App;
9 changes: 9 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
138 changes: 138 additions & 0 deletions src/Table/TableColums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import React from 'react';
import InlineEdit from 'react-edit-inline';
import axios from 'axios';

const ColumnComponent = props => (
<div>
{props.children && React.cloneElement(props.children, props)}
</div>
);

export const columns = ({onTitleClick}) => ([
{
Header: 'Id',
accessor: 'id',
Cell: row => (
<div style={{"text-decoration": "underline"}}>
<ColumnComponent>
<i onClick={() => onTitleClick(row.value)}>{row.value}</i>
</ColumnComponent>
</div>
),
},
{
Header: 'Name',
accessor: 'name',

},
{
Header: 'Title',
accessor: 'title',

}
]);

function connectObject(obj) {
var str = '';
for (var key in obj) {
str += key + ': ' + obj[key] + '\n';
}
return str;
}

function NameIt(id, data) {
const title = data.message;
axios.patch(`http://localhost:3010/books/${id}`, {title});
}

var bookId;

function getId(value) {
bookId = value;
}

export const infoColumns = ({onTitleClick}) => ([
{
Header: 'Id',
accessor: 'id',
Cell: row => (
<ColumnComponent>
<i onChange={getId(row.value)} onClick={() => onTitleClick(row.value)}>{row.value}</i>
</ColumnComponent>
),
},
{
Header: 'Authors Name',
accessor: 'authors[0].name',
Cell: row => (
<ColumnComponent>
<i>{row.value}</i>
</ColumnComponent>
),
},
{
Header: 'Birth Year',
accessor: 'authors[0].birth_year',
Cell: row => (
<ColumnComponent>
<i>{row.value}</i>
</ColumnComponent>
),
},
{
Header: 'Death Year',
accessor: 'authors[0].death_year',
Cell: row => (
<ColumnComponent>
<i>{row.value}</i>
</ColumnComponent>
),
},
{
Header: 'Bookshelves',
accessor: 'bookshelves',
Cell: row => (
<ColumnComponent>
<i>{row.value.join(', ')}</i>
</ColumnComponent>
),
},
{
Header: 'Download count',
accessor: 'download_count',
},
{
Header: 'Formats',
accessor: 'formats',
Cell: row => (
<ColumnComponent>
<i>{connectObject(row.value)}</i>
</ColumnComponent>
),
},
{
Header: 'Media Type',
accessor: 'media_type',

},
{
Header: 'Subjects',
accessor: 'subjects',
Cell: row => (
<ColumnComponent>
<i>{row.value.join(', ')}</i>
</ColumnComponent>
),
},
{
Header: 'Title',
accessor: 'title',
Cell: row => (
<InlineEdit
text={row.value}
paramName={"message"}
change={NameIt.bind(row.value, bookId)}
/>
),
}
]);
Loading