#6 Start from scratch with redaktionsapp

pull/16/head
Christoph Lienhard 2 years ago
parent 584e21d5c1
commit 47988c1e43
Signed by: christoph.lienhard
GPG Key ID: 6B98870DDC270884
  1. 3
      .gitignore
  2. 15
      redaktions-app/.graphqlconfig
  3. 15
      redaktions-app/README.md
  4. 7870
      redaktions-app/package-lock.json
  5. 24
      redaktions-app/package.json
  6. 2
      redaktions-app/public/index.html
  7. 7
      redaktions-app/src/App.css
  8. 10
      redaktions-app/src/App.test.tsx
  9. 55
      redaktions-app/src/App.tsx
  10. 123
      redaktions-app/src/components/CreateQuestionModal/CreateQuestionModal.tsx
  11. 39
      redaktions-app/src/components/CustomAppBar/CustomAppBar.tsx
  12. 63
      redaktions-app/src/components/ExistingQuestions/ExistingQuestions.tsx
  13. 54
      redaktions-app/src/components/Overview/Overview.tsx
  14. 9
      redaktions-app/src/index.tsx
  15. 7
      redaktions-app/src/logo.svg
  16. 18
      redaktions-app/src/serviceWorker.ts
  17. 5
      redaktions-app/src/setupTests.ts
  18. 27
      redaktions-app/tsconfig.json

3
.gitignore vendored

@ -24,3 +24,6 @@ build
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# GraphQl plugin related
postgraphile-schema.graphql

@ -0,0 +1,15 @@
{
"name": "Postgraphile Schema",
"schemaPath": "postgraphile-schema.graphql",
"extensions": {
"endpoints": {
"Remote SWAPI GraphQL Endpoint": {
"url": "http://localhost:5433/graphql",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": true
}
}
}
}

@ -1,3 +1,18 @@
# Redaktions App
The "Redaktions App" or editor's app is the main gateway for editors and candidates to alter the database,
e.g. adding new questions (editors) and answering them (candidates).
## Development
The app is written in typescript and react and uses apollo to query the backend and as a local store.
### Setup
* Install `npm`
* In this directory run `npm ci` to install all dependencies according to the package.json and package-lock.json.
*
## Available Scripts
In the project directory, you can run:

File diff suppressed because it is too large Load Diff

@ -3,16 +3,17 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"typescript": "^3.6.2",
"@material-ui/core": "^4.4.0",
"@material-ui/icons": "^4.2.1",
"@types/jest": "24.0.18",
"@types/node": "12.7.3",
"@types/react": "16.9.2",
"@types/react-dom": "16.9.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-scripts": "^3.3.1"
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"@types/jest": "^24.9.1",
"@types/node": "^12.12.54",
"@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3",
"typescript": "^3.7.5"
},
"scripts": {
"start": "react-scripts start",
@ -34,6 +35,5 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://graphql:5000"
}
}

@ -10,7 +10,7 @@
content="App zum Erstellen von Fragen für den Candymat"
/>
<link rel="apple-touch-icon" href="logo192.png" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/

@ -3,11 +3,16 @@
}
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;

@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { render } from '@testing-library/react';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
test('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

@ -1,39 +1,26 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { createStyles, WithStyles } from '@material-ui/core';
import { withStyles } from '@material-ui/styles';
import { CustomAppBar } from 'components/CustomAppBar/CustomAppBar';
import { Overview } from 'components/Overview/Overview';
export const dataApi = 'http://localhost:5000/graphql'
const styles = createStyles({
root: {
flexGrow: 1,
},
content: {
flexGrow: 1,
height: '100vh',
maxWidth: 1000,
marginLeft: 'auto',
marginRight: 'auto',
},
})
interface AppProps extends WithStyles<typeof styles> { }
class ProtoApp extends React.PureComponent<AppProps> {
public render() {
return (
<div className={this.props.classes.root}>
<CustomAppBar />
<main className={this.props.classes.content}>
<Overview />
</main>
</div>
);
}
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export const App = withStyles(styles)(ProtoApp);
export default App;

@ -1,123 +0,0 @@
import React from 'react';
import { createStyles, WithStyles } from '@material-ui/core/styles';
import Modal from '@material-ui/core/Modal';
import { TextField, Button } from '@material-ui/core';
import { withStyles } from '@material-ui/styles';
import { dataApi } from 'App';
const styles = createStyles({
paper: {
margin: 'auto',
width: 400,
backgroundColor: 'white',
border: '2px solid #000',
padding: 8,
},
textField: {
width: '100%',
},
buttonBar: {
display: 'flex',
flexDirection: 'row',
},
button: {
margin: 2,
},
})
interface OwnState {
frageText: string,
kategorieText: string,
}
interface OwnProps {
open?: boolean,
handleClose(): void,
}
interface CreateQuestionModalProps extends OwnProps, WithStyles<typeof styles> { }
class ProtoCreateQuestionModal extends React.PureComponent<CreateQuestionModalProps, OwnState> {
public constructor(props: CreateQuestionModalProps) {
super(props)
this.state = {
frageText: '',
kategorieText: '',
}
}
public render() {
return (
<Modal
aria-labelledby="simple-modal-title"
aria-describedby="simple-modal-description"
open={this.props.open ? true : false}
onClose={this.props.handleClose}
>
<div className={this.props.classes.paper}>
<h2 id="simple-modal-title">Neue Frage erstellen</h2>
<TextField
id="frage-text"
label="Frage"
multiline
rows="4"
className={this.props.classes.textField}
margin="normal"
variant="outlined"
value={this.state.frageText}
onChange={(e) => this.setState({ frageText: e.target.value })}
/>
<TextField
id="kategorie-name"
label="Kategorie"
className={this.props.classes.textField}
margin="normal"
variant="outlined"
value={this.state.kategorieText}
onChange={(e) => this.setState({ kategorieText: e.target.value })}
/>
<div className={this.props.classes.buttonBar}>
<Button
className={this.props.classes.button}
variant='contained'
color='primary'
onClick={this.createFrage}
>
Erstellen
</Button>
<Button
className={this.props.classes.button}
variant='contained'
color='primary'
onClick={this.props.handleClose}
>
Abbrechen
</Button>
</div>
</div>
</Modal>
);
};
private readonly createFrage = () => {
fetch(`${dataApi}/fragen`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
})
.then(res => {
if (res.status === 200) {
this.props.handleClose();
alert("Frage wurde erfolgreich erstellt");
} else {
alert(`Es ist etwas schief gelaufen. Response: ${res.text}`);
}
})
.catch(err => alert(`Es ist etwas schief gelaufen. Fehler: ${err}`))
};
}
export const CreateQuestionModal = withStyles(styles)(ProtoCreateQuestionModal)

@ -1,39 +0,0 @@
import React from 'react';
import AppBar from '@material-ui/core/AppBar';
import { Toolbar, IconButton, Typography, createStyles, WithStyles } from '@material-ui/core';
import MenuIcon from '@material-ui/icons/Menu';
import AccountCircle from '@material-ui/icons/AccountCircle';
import { withStyles } from '@material-ui/styles';
const styles = createStyles({
menuButton: {
marginRight: 16,
},
title: {
flexGrow: 1,
},
})
interface AppBarProps extends WithStyles<typeof styles> { }
class ProtoCustomAppBar extends React.PureComponent<AppBarProps> {
public render() {
return (
<AppBar>
<Toolbar>
<IconButton edge="start" className={this.props.classes.menuButton} color="inherit" aria-label="menu">
<MenuIcon />
</IconButton>
<Typography variant="h6" className={this.props.classes.title}>
Candymat Redaktion
</Typography>
<IconButton edge="start" className={this.props.classes.menuButton} color="inherit" aria-label="user">
<AccountCircle />
</IconButton>
</Toolbar>
</AppBar>
);
}
}
export const CustomAppBar = withStyles(styles)(ProtoCustomAppBar);

@ -1,63 +0,0 @@
import { WithStyles, createStyles, withStyles } from "@material-ui/core";
import React from "react";
import { dataApi } from "App";
const styles = createStyles({
root: {
padding: '20px 0'
},
questionBar: {
margin: '6px 0',
padding: 7,
border: 'solid black 1px',
width: '100%',
}
})
interface Question {
id: number,
text: string,
kategorie: string,
}
interface StateProps {
existingQuestions: Array<Question>,
}
interface ExistingQuestionsProps extends WithStyles<typeof styles> { }
class ProtoExistingQuestions extends React.PureComponent<ExistingQuestionsProps, StateProps> {
public constructor(props: ExistingQuestionsProps) {
super(props)
this.state = {
existingQuestions: [],
}
}
componentDidMount() {
fetch(`${dataApi}/fragen`, {method: 'GET'})
.then(res => res.json())
.then(json => this.setState({ existingQuestions: json }))
}
public render() {
const questions = this.state.existingQuestions;
return (
<div className={this.props.classes.root}>
{questions.length > 0 ? this.getQuestions() : <span>Es wurden noch keine Fragen erstellt.</span>}
</div>
)
}
private readonly getQuestions = () => this.state.existingQuestions.map(question => (
<div key={question.id} className={this.props.classes.questionBar}>
<span>{question.text}</span>
</div>
))
}
export const ExistingQuestions = withStyles(styles)(ProtoExistingQuestions)

@ -1,54 +0,0 @@
import { WithStyles, createStyles, Paper, Typography, Button, withStyles } from "@material-ui/core";
import React from "react";
import { ExistingQuestions } from "components/ExistingQuestions/ExistingQuestions";
import { CreateQuestionModal } from "components/CreateQuestionModal/CreateQuestionModal";
const styles = createStyles({
mainPaper: {
height: '100%',
margin: '100px 50px 30px',
backgroundColor: 'white',
padding: '50px 30px 30px',
},
})
interface OverviewProps extends WithStyles<typeof styles> { }
interface OwnState {
modalOpen: boolean,
}
class ProtoOverview extends React.PureComponent<OverviewProps, OwnState> {
public constructor(props: OverviewProps) {
super(props)
this.state = {
modalOpen: false,
}
}
public render() {
return (
<Paper className={this.props.classes.mainPaper}>
<Typography component="h1" variant="h4" align="center">
Existierende Fragen
</Typography>
<ExistingQuestions />
<Button variant='contained' color='primary' onClick={this.createFrage}>
Neue Frage erstellen
</Button>
<CreateQuestionModal open={this.state.modalOpen} handleClose={this.onModalClose}/>
</Paper>
)
};
private readonly createFrage = () => {
this.setState({modalOpen: true})
}
private readonly onModalClose = () => {
this.setState({modalOpen: false})
}
}
export const Overview = withStyles(styles)(ProtoOverview)

@ -1,10 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import { App } from 'App';
ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
<g fill="#61DAFB">
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
<circle cx="420.9" cy="296.5" r="45.7"/>
<path d="M520.5 78.1z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

@ -14,7 +14,7 @@ const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
@ -29,7 +29,7 @@ export function register(config?: Config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(
(process as { env: { [key: string]: string } }).env.PUBLIC_URL,
process.env.PUBLIC_URL,
window.location.href
);
if (publicUrl.origin !== window.location.origin) {
@ -108,7 +108,9 @@ function registerValidSW(swUrl: string, config?: Config) {
function checkValidServiceWorker(swUrl: string, config?: Config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
fetch(swUrl, {
headers: { 'Service-Worker': 'script' }
})
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
@ -136,8 +138,12 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
navigator.serviceWorker.ready
.then(registration => {
registration.unregister();
})
.catch(error => {
console.error(error.message);
});
}
}

@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';

@ -1,29 +1,24 @@
{
"compilerOptions": {
"module": "esnext",
"target": "es5",
"lib": [
"es6",
"dom"
"dom",
"dom.iterable",
"esnext"
],
"jsx": "preserve",
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noEmit": true,
"experimentalDecorators": true,
"baseUrl": "src",
"allowSyntheticDefaultImports": true,
"noErrorTruncation": true,
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"exclude": [
"**/build/"
],
"include": [
"src"
]

Loading…
Cancel
Save