mirror of
				https://gitlab.com/questable/questable-web-ui
				synced 2025-11-04 12:30:06 +01:00 
			
		
		
		
	Break into files
This commit is contained in:
		
							
								
								
									
										20
									
								
								src/components/login.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/components/login.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					import React, { useState } from "react";
 | 
				
			||||||
 | 
					import PropTypes from "prop-types";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default (player) => {
 | 
				
			||||||
 | 
						function Login(props) {
 | 
				
			||||||
 | 
							const [input, setInput] = useState("");
 | 
				
			||||||
 | 
							return (
 | 
				
			||||||
 | 
								<div className="login">
 | 
				
			||||||
 | 
									<input type="text" placeholder="Token ID" value={input}
 | 
				
			||||||
 | 
										onChange={evt => setInput(evt.target.value)} />
 | 
				
			||||||
 | 
									<button onClick={() => player.auth(input).then(x => props.setLoggedIn(x))}>Submit</button>
 | 
				
			||||||
 | 
								</div>
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Login.propTypes = {
 | 
				
			||||||
 | 
							setLoggedIn: PropTypes.func,
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
						return Login;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										7
									
								
								src/components/mainapp.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/components/mainapp.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					import React from "react";
 | 
				
			||||||
 | 
					export default () => function MainApp() {
 | 
				
			||||||
 | 
						return (
 | 
				
			||||||
 | 
							<div className="main">
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										43
									
								
								src/index.js
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								src/index.js
									
									
									
									
									
								
							@@ -1,49 +1,20 @@
 | 
				
			|||||||
import React, { useState } from "react";
 | 
					import React, { useState } from "react";
 | 
				
			||||||
import ReactDOM from "react-dom";
 | 
					import ReactDOM from "react-dom";
 | 
				
			||||||
import PropTypes from "prop-types";
 | 
					 | 
				
			||||||
import "./index.css";
 | 
					import "./index.css";
 | 
				
			||||||
import { config } from "./config";
 | 
					import { config } from "./config";
 | 
				
			||||||
import axios from "axios";
 | 
					import axios from "axios";
 | 
				
			||||||
 | 
					import login from "./components/login";
 | 
				
			||||||
 | 
					import mainapp from "./components/mainapp";
 | 
				
			||||||
 | 
					import models from "./models";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function auth(token) {
 | 
					const { player } = models(config, axios);
 | 
				
			||||||
	return axios.get(`${config.apiUrl}/auth?token=${encodeURIComponent(token)}`)
 | 
					 | 
				
			||||||
		.then((res) => res.data.success);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function Login(props) {
 | 
					const Login = login(player);
 | 
				
			||||||
	const [input, setInput] = useState("");
 | 
					const MainApp = mainapp();
 | 
				
			||||||
	return (
 | 
					 | 
				
			||||||
		<div className="login">
 | 
					 | 
				
			||||||
			<input type="text" placeholder="Token ID" value={input}
 | 
					 | 
				
			||||||
				onChange={evt => setInput(evt.target.value)} />
 | 
					 | 
				
			||||||
			<button onClick={() => auth(input).then(x => props.setLoggedIn(x))}>Submit</button>
 | 
					 | 
				
			||||||
		</div>
 | 
					 | 
				
			||||||
	);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Login.propTypes = {
 | 
					 | 
				
			||||||
	setLoggedIn: PropTypes.func,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function MainApp() {
 | 
					 | 
				
			||||||
	return (
 | 
					 | 
				
			||||||
		<div className="main">
 | 
					 | 
				
			||||||
		</div>
 | 
					 | 
				
			||||||
	);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function App(){
 | 
					function App(){
 | 
				
			||||||
	const [loggedIn, setLoggedIn] = useState(false);
 | 
						const [loggedIn, setLoggedIn] = useState(false);
 | 
				
			||||||
	if (loggedIn){
 | 
						return loggedIn ? <MainApp /> : <Login setLoggedIn={setLoggedIn} />;
 | 
				
			||||||
		return (
 | 
					 | 
				
			||||||
			<MainApp />
 | 
					 | 
				
			||||||
		);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	else {
 | 
					 | 
				
			||||||
		return (
 | 
					 | 
				
			||||||
			<Login setLoggedIn={setLoggedIn} />
 | 
					 | 
				
			||||||
		);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ReactDOM.render(<App />, document.getElementById("root"));
 | 
					ReactDOM.render(<App />, document.getElementById("root"));
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								src/models/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/models/index.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					import player from "./player";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default (config, axios) => { return {
 | 
				
			||||||
 | 
						player: player(config, axios),
 | 
				
			||||||
 | 
					};};
 | 
				
			||||||
							
								
								
									
										6
									
								
								src/models/player.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/models/player.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					export default (config, axios) => {return {
 | 
				
			||||||
 | 
						auth: (token) => {
 | 
				
			||||||
 | 
							return axios.get(`${config.apiUrl}/auth?token=${encodeURIComponent(token)}`)
 | 
				
			||||||
 | 
								.then((res) => res.data.success);
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					};};
 | 
				
			||||||
		Reference in New Issue
	
	Block a user