-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from dpakach/typescript
Move to typescript
- Loading branch information
Showing
32 changed files
with
2,886 additions
and
1,668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
parser: "@typescript-eslint/parser", // Specifies the ESLint parser | ||
parserOptions: { | ||
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features | ||
sourceType: "module", // Allows for the use of imports | ||
ecmaFeatures: { | ||
jsx: true // Allows for the parsing of JSX | ||
} | ||
}, | ||
settings: { | ||
react: { | ||
version: "detect" // Tells eslint-plugin-react to automatically detect the version of React to use | ||
} | ||
}, | ||
extends: [ | ||
"plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react | ||
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from @typescript-eslint/eslint-plugin | ||
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier | ||
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. | ||
], | ||
rules: { | ||
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs | ||
// e.g. "@typescript-eslint/explicit-function-return-type": "off", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
semi: true, | ||
trailingComma: "all", | ||
singleQuote: true, | ||
printWidth: 120, | ||
tabWidth: 2 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as React from 'react'; | ||
import { useState } from 'react'; | ||
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'; | ||
import Posts from './Posts'; | ||
import Login from './Login'; | ||
import Signup from './Signup'; | ||
import ProfilePage from './ProfilePage'; | ||
import { post } from './helpers/request'; | ||
import SinglePost from './SinglePost'; | ||
import Docs from './Docs'; | ||
|
||
import './styles/main.scss'; | ||
import { Tokens } from './types/types'; | ||
|
||
export default function App() { | ||
const tokensString = window.localStorage.getItem('tokens'); | ||
|
||
const [tokens, setTokens]: [Tokens, (Tokens: Tokens) => void] = useState<Tokens>(JSON.parse(tokensString) as Tokens); | ||
const [loggedIn, setLoggedIn] = useState(tokensString != null); | ||
const [message, setMessage]: [string, (messages: string) => void] = useState(''); | ||
|
||
function handleLogout() { | ||
window.localStorage.removeItem('tokens'); | ||
setLoggedIn(false); | ||
return post('/auth/logout', { headers: { token: tokens.token } }) | ||
.then((res) => res.json()) | ||
.then( | ||
() => { | ||
setTokens({} as Tokens); | ||
setLoggedIn(false); | ||
setMessage('Logged out successfully'); | ||
}, | ||
(error) => { | ||
setMessage('Error: ' + error.message); | ||
}, | ||
); | ||
} | ||
|
||
if (window.location.pathname.startsWith('/docs')) { | ||
return <Docs />; | ||
} | ||
|
||
return ( | ||
<Router> | ||
<div className="main"> | ||
<div className="container"> | ||
<h1 className="header">Zwitter</h1> | ||
{message && <p> {message} </p>} | ||
{loggedIn && ( | ||
<p> | ||
Logged in as <b>@{tokens.user.username}</b> | ||
</p> | ||
)} | ||
<div> | ||
<Link to="/">Home </Link> | ||
{loggedIn ? ( | ||
<> | ||
<Link to="/profile">Profile </Link> | ||
<Link to="#" onClick={handleLogout}> | ||
{' '} | ||
Logout{' '} | ||
</Link> | ||
</> | ||
) : ( | ||
<> | ||
<Link to="/login">Login </Link> | ||
<Link to="/signup">Signup </Link> | ||
</> | ||
)} | ||
|
||
<Switch> | ||
<Route | ||
exact | ||
path="/post/:id" | ||
render={(props) => <SinglePost {...props} loggedIn={loggedIn} tokens={tokens} />} | ||
/> | ||
<Route exact path="/login"> | ||
<Login loggedIn={loggedIn} setTokens={setTokens} setLoggedIn={setLoggedIn} /> | ||
</Route> | ||
<Route exact path="/signup"> | ||
<Signup loggedIn={loggedIn} setLoggedIn={setLoggedIn} /> | ||
</Route> | ||
<Route exact path="/profile"> | ||
<ProfilePage loggedIn={loggedIn} tokens={tokens} self={true} /> | ||
</Route> | ||
<Route exact path="/profile/:user"> | ||
<ProfilePage loggedIn={loggedIn} tokens={tokens} /> | ||
</Route> | ||
<Route exact path="/" render={(props) => <Posts {...props} loggedIn={loggedIn} tokens={tokens} />} /> | ||
</Switch> | ||
</div> | ||
</div> | ||
</div> | ||
</Router> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react'; | ||
import { useState, useEffect } from 'react'; | ||
import { RedocStandalone } from 'redoc'; | ||
import { baseUrl } from './const'; | ||
|
||
function Docs() { | ||
const [service, setService]: [string, (service: string) => void] = useState('auth'); | ||
|
||
function handleChange(e: React.ChangeEvent<HTMLSelectElement>) { | ||
setService(e.target.value); | ||
} | ||
|
||
return ( | ||
<div> | ||
<select value={service} onChange={handleChange}> | ||
<option value="auth">Auth Service</option> | ||
<option value="posts">Posts Service</option> | ||
<option value="users">Users Service</option> | ||
</select> | ||
<RedocStandalone specUrl={`${baseUrl}/${service}/swagger.json`} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default Docs; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.