init
This commit is contained in:
commit
af4f4e3441
1
.env.example
Normal file
1
.env.example
Normal file
@ -0,0 +1 @@
|
||||
REACT_APP_API_SERVER="http://localhost:3001"
|
1
.eslintcache
Normal file
1
.eslintcache
Normal file
File diff suppressed because one or more lines are too long
25
.gitignore
vendored
Normal file
25
.gitignore
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
.env
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"css.validate": false
|
||||
}
|
70
README.md
Normal file
70
README.md
Normal file
@ -0,0 +1,70 @@
|
||||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
11
craco.config.js
Normal file
11
craco.config.js
Normal file
@ -0,0 +1,11 @@
|
||||
// craco.config.js
|
||||
module.exports = {
|
||||
style: {
|
||||
postcss: {
|
||||
plugins: [
|
||||
require('tailwindcss'),
|
||||
require('autoprefixer'),
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
17177
package-lock.json
generated
Normal file
17177
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
50
package.json
Normal file
50
package.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "klient",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@craco/craco": "^6.1.1",
|
||||
"@material-ui/core": "^4.11.3",
|
||||
"@tailwindcss/forms": "^0.2.1",
|
||||
"@testing-library/jest-dom": "^5.11.9",
|
||||
"@testing-library/react": "^11.2.3",
|
||||
"@testing-library/user-event": "^12.6.2",
|
||||
"axios": "^0.21.1",
|
||||
"framer-motion": "^3.6.7",
|
||||
"react": "^17.0.1",
|
||||
"react-cropper": "^2.1.7",
|
||||
"react-dom": "^17.0.1",
|
||||
"react-scripts": "4.0.1",
|
||||
"web-vitals": "^0.2.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "craco start",
|
||||
"build": "craco build",
|
||||
"test": "craco test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss7-compat": "^2.0.3",
|
||||
"autoprefixer": "^9.8.6",
|
||||
"postcss": "^7.0.35",
|
||||
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.3"
|
||||
}
|
||||
}
|
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
43
public/index.html
Normal file
43
public/index.html
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<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/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
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>Foto edytor</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>
|
BIN
public/logo192.png
Normal file
BIN
public/logo192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
public/logo512.png
Normal file
BIN
public/logo512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
25
public/manifest.json
Normal file
25
public/manifest.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
3
public/robots.txt
Normal file
3
public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
38
src/App.js
Normal file
38
src/App.js
Normal file
@ -0,0 +1,38 @@
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import Layout from './Layout';
|
||||
import { getUser } from './apiClient';
|
||||
import { store } from './store';
|
||||
|
||||
function App() {
|
||||
const { dispatch } = useContext(store);
|
||||
useEffect(() => {
|
||||
const userPromise = getUser();
|
||||
userPromise.then((res, err) => {
|
||||
dispatch({
|
||||
type: 'USER_LOADED',
|
||||
});
|
||||
if (res.data !== '') {
|
||||
dispatch({
|
||||
type: 'SET_USER',
|
||||
payload: {
|
||||
uuid: res.data.uuid,
|
||||
username: res.data.username,
|
||||
loading: false,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
if (window.localStorage.getItem('collection')) {
|
||||
dispatch({
|
||||
type: 'SET_CURRENT_COLLECTION',
|
||||
payload: window.localStorage.getItem('collection'),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
return <Layout />;
|
||||
}
|
||||
|
||||
export default App;
|
131
src/Auth/LoginModal.js
Normal file
131
src/Auth/LoginModal.js
Normal file
@ -0,0 +1,131 @@
|
||||
import React, { useState, useContext } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { store } from '../store';
|
||||
import { login, claimCollection } from '../apiClient';
|
||||
|
||||
function LoginModal() {
|
||||
const [isSending, setIsSending] = useState(false);
|
||||
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [loginError, setLoginError] = useState(false);
|
||||
|
||||
const { state, dispatch } = useContext(store);
|
||||
|
||||
const closeModal = () => {
|
||||
if (isSending) return;
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
};
|
||||
|
||||
const sendLoginRequest = async () => {
|
||||
if (isSending) return;
|
||||
|
||||
setIsSending(true);
|
||||
|
||||
try {
|
||||
const user = await login(username, password);
|
||||
dispatch({
|
||||
type: 'SET_USER',
|
||||
payload: { uuid: user.uuid, username: user.username },
|
||||
});
|
||||
if (window.localStorage.getItem('collection')) {
|
||||
await claimCollection(window.localStorage.getItem('collection'));
|
||||
window.localStorage.removeItem('collection');
|
||||
}
|
||||
} catch (e) {
|
||||
setLoginError(true);
|
||||
setIsSending(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoginError(false);
|
||||
setIsSending(false);
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
};
|
||||
|
||||
const isVisible = state.modal === 'LOGIN';
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{isVisible && (
|
||||
<motion.div
|
||||
animate={{ opacity: 1 }}
|
||||
initial={{ opacity: 0 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className="flex fixed w-full h-full bg-black bg-opacity-40 top-0 left-0"
|
||||
onClick={closeModal}
|
||||
>
|
||||
<div
|
||||
className="flex flex-col flex-nowrap w-96 h-96 m-auto bg-white rounded-t-lg shadow-lg"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<div className="shadow py-4 px-2 flex">
|
||||
<span className="text-xl text-gray-900">Logowanie</span>
|
||||
<span className="ml-auto px-4 flex">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="text-gray-400 m-auto cursor-pointer hover:text-gray-500 duration-200"
|
||||
onClick={closeModal}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M6 18L18 6M6 6l12 12"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div className="py-4 px-2">
|
||||
<label className="block">
|
||||
<span className="text-gray-700">Nazwa użytkownika</span>
|
||||
<input
|
||||
type="text"
|
||||
name="login"
|
||||
className="mt-1 block w-full"
|
||||
placeholder=""
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="block pt-4">
|
||||
<span className="text-gray-700">Hasło</span>
|
||||
<input
|
||||
type="password"
|
||||
name="password"
|
||||
className="mt-1 block w-full"
|
||||
placeholder=""
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{loginError && (
|
||||
<div className="text-center text-red-500 py-2">
|
||||
Błędny login lub hasło
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-auto border-t py-3 px-2">
|
||||
<button
|
||||
disabled={isSending}
|
||||
className="flex mx-auto outline-none focus:outline-none items-center justify-center px-12 py-3 border border-transparent text-base font-medium rounded-md text-white bg-green-600 hover:bg-green-700 duration-200"
|
||||
onClick={sendLoginRequest}
|
||||
>
|
||||
Zaloguj się
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
|
||||
export default LoginModal;
|
162
src/Auth/RegisterModal.js
Normal file
162
src/Auth/RegisterModal.js
Normal file
@ -0,0 +1,162 @@
|
||||
import React, { useState, useContext } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { store } from '../store';
|
||||
import { register, claimCollection } from '../apiClient';
|
||||
|
||||
function RegisterModal() {
|
||||
const [isSending, setIsSending] = useState(false);
|
||||
|
||||
const [username, setUsername] = useState('');
|
||||
const [error, setError] = useState(null);
|
||||
const [password, setPassword] = useState('');
|
||||
const [password2, setPassword2] = useState('');
|
||||
|
||||
const { state, dispatch } = useContext(store);
|
||||
|
||||
const closeModal = () => {
|
||||
if (isSending) return;
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
};
|
||||
|
||||
const sendLoginRequest = async () => {
|
||||
if (isSending) return;
|
||||
|
||||
if (username === '') {
|
||||
setError('Nazwa nie może być pusta');
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length < 5) {
|
||||
setError('Hasło jest zbyt krótkie');
|
||||
return;
|
||||
}
|
||||
|
||||
if (password !== password2) {
|
||||
setError('Hasła się różnią');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSending(true);
|
||||
|
||||
try {
|
||||
const user = await register(username, password);
|
||||
dispatch({
|
||||
type: 'SET_USER',
|
||||
payload: { uuid: user.uuid, username: user.username },
|
||||
});
|
||||
if (window.localStorage.getItem('collection')) {
|
||||
await claimCollection(window.localStorage.getItem('collection'));
|
||||
window.localStorage.removeItem('collection');
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.response && e.response.data === 'User exists') {
|
||||
setError('Użytkownik o podanej nazwie już istnieje');
|
||||
setIsSending(false);
|
||||
return;
|
||||
}
|
||||
setError('Wystąpił błąd');
|
||||
setIsSending(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setError(null);
|
||||
setIsSending(false);
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
};
|
||||
|
||||
const isVisible = state.modal === 'REGISTER';
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{isVisible && (
|
||||
<motion.div
|
||||
animate={{ opacity: 1 }}
|
||||
initial={{ opacity: 0 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className="flex fixed w-full h-full bg-black bg-opacity-40 top-0 left-0"
|
||||
onClick={closeModal}
|
||||
>
|
||||
<div
|
||||
className="flex flex-col flex-nowrap w-96 h-96 m-auto bg-white rounded-t-lg shadow-lg"
|
||||
style={{ height: 30 + 'rem' }}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<div className="shadow py-4 px-2 flex">
|
||||
<span className="text-xl text-gray-900">Rejestracja</span>
|
||||
<span className="ml-auto px-4 flex">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="text-gray-400 m-auto cursor-pointer hover:text-gray-500 duration-200"
|
||||
onClick={closeModal}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M6 18L18 6M6 6l12 12"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div className="py-4 px-2">
|
||||
<label className="block">
|
||||
<span className="text-gray-700">Nazwa użytkownika</span>
|
||||
<input
|
||||
type="text"
|
||||
name="login"
|
||||
className="mt-1 block w-full"
|
||||
placeholder=""
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="block pt-4">
|
||||
<span className="text-gray-700">Hasło</span>
|
||||
<input
|
||||
type="password"
|
||||
name="password"
|
||||
className="mt-1 block w-full"
|
||||
placeholder=""
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
<span className="text-gray-500 text-sm">Minimum 5 znaków</span>
|
||||
</label>
|
||||
<label className="block pt-4">
|
||||
<span className="text-gray-700">Powtórz hasło</span>
|
||||
<input
|
||||
type="password"
|
||||
className="mt-1 block w-full"
|
||||
placeholder=""
|
||||
value={password2}
|
||||
onChange={(e) => setPassword2(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{error && (
|
||||
<div className="text-center text-red-500 py-2">{error}</div>
|
||||
)}
|
||||
<div className="mt-auto border-t py-3 px-2">
|
||||
<button
|
||||
disabled={isSending}
|
||||
className="flex mx-auto outline-none focus:outline-none items-center justify-center px-12 py-3 border border-transparent text-base font-medium rounded-md text-white bg-green-600 hover:bg-green-700 duration-200"
|
||||
onClick={sendLoginRequest}
|
||||
>
|
||||
Zarejestruj się
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
|
||||
export default RegisterModal;
|
170
src/Auth/SettingsModal.js
Normal file
170
src/Auth/SettingsModal.js
Normal file
@ -0,0 +1,170 @@
|
||||
import React, { useState, useContext } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { store } from '../store';
|
||||
import { changePassword, deleteAccount } from '../apiClient';
|
||||
|
||||
function SettingsModal() {
|
||||
const [isSending, setIsSending] = useState(false);
|
||||
|
||||
const [password, setPassword] = useState('');
|
||||
const [password2, setPassword2] = useState('');
|
||||
|
||||
const [passwordError, setPasswordError] = useState(false);
|
||||
|
||||
const { state, dispatch } = useContext(store);
|
||||
|
||||
const closeModal = () => {
|
||||
if (isSending) return;
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
};
|
||||
|
||||
const sendPasswordRequest = async () => {
|
||||
if (isSending) return;
|
||||
|
||||
if (password.length < 5) {
|
||||
setPasswordError('Hasło jest zbyt krótkie');
|
||||
return;
|
||||
}
|
||||
|
||||
if (password !== password2) {
|
||||
setPasswordError('Hasła się różnią');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSending(true);
|
||||
|
||||
try {
|
||||
await changePassword(password);
|
||||
} catch (e) {
|
||||
setPasswordError(true);
|
||||
setIsSending(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setPasswordError(false);
|
||||
setIsSending(false);
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
};
|
||||
|
||||
const sendDeleteRequest = async () => {
|
||||
if (isSending) return;
|
||||
|
||||
const confirm = window.confirm("Potwierdź usunięcie konta");
|
||||
|
||||
if (!confirm) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSending(true);
|
||||
|
||||
try {
|
||||
await deleteAccount();
|
||||
} catch (e) {
|
||||
setPasswordError(true);
|
||||
setIsSending(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setPasswordError(false);
|
||||
setIsSending(false);
|
||||
dispatch({
|
||||
type: 'SET_USER',
|
||||
payload: { uuid: null, username: null },
|
||||
});
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
};
|
||||
|
||||
const isVisible = state.modal === 'SETTINGS' && state.user.uuid !== null;
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{isVisible && (
|
||||
<motion.div
|
||||
animate={{ opacity: 1 }}
|
||||
initial={{ opacity: 0 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className="flex fixed w-full h-full bg-black bg-opacity-40 top-0 left-0"
|
||||
onClick={closeModal}
|
||||
>
|
||||
<div
|
||||
className="flex flex-col flex-nowrapw-96 w-96 m-auto bg-white rounded-t-lg shadow-lg"
|
||||
style={{ height: `30rem` }}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<div className="shadow py-4 px-2 flex">
|
||||
<span className="text-xl text-gray-900">Ustawienia</span>
|
||||
<span className="ml-auto px-4 flex">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="text-gray-400 m-auto cursor-pointer hover:text-gray-500 duration-200"
|
||||
onClick={closeModal}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M6 18L18 6M6 6l12 12"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div className="py-4 px-2">
|
||||
<label className="block pt-4">
|
||||
<span className="text-gray-700">Zmień hasło</span>
|
||||
<input
|
||||
type="password"
|
||||
name="password"
|
||||
className="mt-1 block w-full"
|
||||
placeholder=""
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
<span className="text-gray-500 text-sm">Minimum 5 znaków</span>
|
||||
</label>
|
||||
<label className="block pt-4">
|
||||
<span className="text-gray-700">Powtórz hasło</span>
|
||||
<input
|
||||
type="password"
|
||||
className="mt-1 block w-full"
|
||||
placeholder=""
|
||||
value={password2}
|
||||
onChange={(e) => setPassword2(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{passwordError && (
|
||||
<div className="text-center text-red-500 py-2">
|
||||
{passwordError}
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-auto border-t py-3 px-2">
|
||||
<button
|
||||
disabled={isSending}
|
||||
className="flex mx-auto outline-none focus:outline-none items-center justify-center px-12 py-3 border border-transparent text-base font-medium rounded-md text-white bg-green-600 hover:bg-green-700 duration-200"
|
||||
onClick={sendPasswordRequest}
|
||||
>
|
||||
Zmień hasło
|
||||
</button>
|
||||
<button
|
||||
disabled={isSending}
|
||||
className="flex mt-5 mx-auto outline-none focus:outline-none items-center justify-center px-12 py-3 border border-transparent text-base font-medium rounded-md text-white bg-red-700 hover:bg-red-800 duration-200"
|
||||
onClick={sendDeleteRequest}
|
||||
>
|
||||
Usuń konto
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
|
||||
export default SettingsModal;
|
66
src/CollectionApp/AddPhotoButton.js
Normal file
66
src/CollectionApp/AddPhotoButton.js
Normal file
@ -0,0 +1,66 @@
|
||||
import React, { useContext, useEffect, useRef, useState } from 'react';
|
||||
import { uploadFile } from '../apiClient';
|
||||
import { store } from '../store';
|
||||
|
||||
function AddPhotoButton() {
|
||||
const { state, dispatch } = useContext(store);
|
||||
const [filesToUpload, setFilesToUpload] = useState([]);
|
||||
let ref = useRef(null);
|
||||
const onClick = () => {
|
||||
ref.current.click();
|
||||
};
|
||||
const onFiles = async () => {
|
||||
setFilesToUpload((filesToUpload) => [
|
||||
...filesToUpload,
|
||||
...ref.current.files,
|
||||
]);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const uploadFiles = async () => {
|
||||
if (filesToUpload.length > 0 && state.currentCollection) {
|
||||
const photo = await uploadFile(
|
||||
state.currentCollection,
|
||||
filesToUpload[0]
|
||||
);
|
||||
dispatch({ type: 'ADD_PHOTO', payload: photo });
|
||||
setFilesToUpload((filesToUpload) => [...filesToUpload.slice(1)]);
|
||||
}
|
||||
};
|
||||
uploadFiles();
|
||||
}, [filesToUpload, state.currentCollection, dispatch]);
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className="flex outline-none focus:outline-none items-center justify-center px-4 py-2 border border-transparent text-base font-medium rounded-md text-white bg-green-600 hover:bg-green-700 duration-200"
|
||||
>
|
||||
Prześlij zdjęcia
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="h-6 ml-2"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"
|
||||
/>
|
||||
</svg>
|
||||
<input
|
||||
type="file"
|
||||
id="input"
|
||||
multiple
|
||||
className="hidden"
|
||||
ref={ref}
|
||||
onChange={onFiles}
|
||||
accept="image/jpeg"
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default AddPhotoButton;
|
37
src/CollectionApp/CollectionApp.js
Normal file
37
src/CollectionApp/CollectionApp.js
Normal file
@ -0,0 +1,37 @@
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import AddPhotoButton from './AddPhotoButton';
|
||||
import DeleteCollectionButton from './DeleteCollectionButton';
|
||||
import { store } from '../store';
|
||||
import { getPhotos } from '../apiClient';
|
||||
import Photo from './Photo';
|
||||
import EditPhotoModal from "./EditPhotoModal";
|
||||
|
||||
function Collections(props) {
|
||||
const { state, dispatch } = useContext(store);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
const photos = await getPhotos(state.currentCollection);
|
||||
dispatch({ type: 'SET_PHOTOS', payload: photos });
|
||||
};
|
||||
fetchData();
|
||||
}, [state.currentCollection, dispatch]);
|
||||
|
||||
const photos = state.currentPhotos.map((photo) => {
|
||||
return <Photo photo={photo} key={photo.uuid} />;
|
||||
});
|
||||
return (
|
||||
<div>
|
||||
<div className="flex border-b pb-4">
|
||||
<AddPhotoButton />
|
||||
<DeleteCollectionButton />
|
||||
</div>
|
||||
<div className="grid grid-flow-row grid-cols-2 gap-4 gap-y-12 mt-4">
|
||||
{photos}
|
||||
</div>
|
||||
<EditPhotoModal />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Collections;
|
47
src/CollectionApp/DeleteCollectionButton.js
Normal file
47
src/CollectionApp/DeleteCollectionButton.js
Normal file
@ -0,0 +1,47 @@
|
||||
import React, { useContext } from 'react';
|
||||
|
||||
import { deleteCollection } from '../apiClient';
|
||||
import { store } from '../store';
|
||||
|
||||
function DeleteCollectionButton() {
|
||||
const { state, dispatch } = useContext(store);
|
||||
|
||||
const removeCollection = async (e) => {
|
||||
e.preventDefault();
|
||||
const confirm = window.confirm('Potwierdź usunięcie kolekcji');
|
||||
if (confirm) {
|
||||
await deleteCollection(state.currentCollection);
|
||||
dispatch({ type: 'SET_PHOTOS', payload: [] });
|
||||
dispatch({ type: 'SET_CURRENT_COLLECTION', payload: null });
|
||||
dispatch({ type: 'DELETE_COLLECTION', payload: state.currentCollection });
|
||||
if (window.localStorage.getItem('collection')) {
|
||||
window.localStorage.removeItem('collection');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={removeCollection}
|
||||
className="flex ml-auto outline-none focus:outline-none items-center justify-center px-4 py-2 border border-transparent text-base font-medium rounded-md text-white bg-red-700 hover:bg-red-800 duration-200"
|
||||
>
|
||||
Usuń kolekcję
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="h-6 ml-2"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default DeleteCollectionButton;
|
38
src/CollectionApp/DeletePhotoButton.js
Normal file
38
src/CollectionApp/DeletePhotoButton.js
Normal file
@ -0,0 +1,38 @@
|
||||
import React, { useContext } from 'react';
|
||||
|
||||
import { deletePhoto } from '../apiClient';
|
||||
import { store } from '../store';
|
||||
|
||||
function DeletePhotoButton(props) {
|
||||
const { state, dispatch } = useContext(store);
|
||||
|
||||
const removePhoto = async (e) => {
|
||||
e.preventDefault();
|
||||
await deletePhoto(state.currentCollection, props.uuid);
|
||||
dispatch({ type: 'DELETE_PHOTO', payload: props.uuid });
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={removePhoto}
|
||||
className="flex ml-auto outline-none focus:outline-none items-center justify-center px-1 py-1 border border-transparent text-base font-medium rounded-md text-white bg-red-700 hover:bg-red-800 duration-200"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="h-6"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default DeletePhotoButton;
|
35
src/CollectionApp/DownloadPhotoButton.js
Normal file
35
src/CollectionApp/DownloadPhotoButton.js
Normal file
@ -0,0 +1,35 @@
|
||||
import React, { useContext } from 'react';
|
||||
|
||||
import { store } from '../store';
|
||||
import { API_SERVER } from '../config';
|
||||
|
||||
function DownloadPhotoButton(props) {
|
||||
const { state } = useContext(store);
|
||||
|
||||
const downloadUrl = `${API_SERVER}/photo/${state.currentCollection}/${props.photo.uuid}/full`;
|
||||
|
||||
return (
|
||||
<a
|
||||
href={downloadUrl}
|
||||
className="flex ml-auto outline-none focus:outline-none items-center justify-center px-12 py-2 border border-transparent text-base font-medium rounded-md text-white bg-green-600 hover:bg-green-700 duration-200"
|
||||
>
|
||||
<span>Pobierz</span>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="h-6 ml-2"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
export default DownloadPhotoButton;
|
36
src/CollectionApp/EditPhotoButton.js
Normal file
36
src/CollectionApp/EditPhotoButton.js
Normal file
@ -0,0 +1,36 @@
|
||||
import React, { useContext } from 'react';
|
||||
|
||||
import { store } from '../store';
|
||||
|
||||
function EditPhotoButton(props) {
|
||||
const { dispatch } = useContext(store);
|
||||
const showEditModal = () => {
|
||||
dispatch({ type: 'SET_MODAL', payload: 'EDIT-PHOTO' });
|
||||
dispatch({ type: 'SET_CURRENT_PHOTO', payload: props.photo });
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={showEditModal}
|
||||
className="flex outline-none focus:outline-none items-center justify-center px-12 py-2 border border-transparent text-base font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 duration-200"
|
||||
>
|
||||
<span>Edytuj</span>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="h-6 ml-2"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default EditPhotoButton;
|
272
src/CollectionApp/EditPhotoModal.js
Normal file
272
src/CollectionApp/EditPhotoModal.js
Normal file
@ -0,0 +1,272 @@
|
||||
import React, { useContext, useState } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { store } from '../store';
|
||||
import PhotoRenderer from './PhotoRenderer';
|
||||
import { API_SERVER } from '../config';
|
||||
import Slider from '@material-ui/core/Slider';
|
||||
import PhotoCropper from './PhotoCropper';
|
||||
import { savePhoto } from '../apiClient';
|
||||
|
||||
function EditPhotoModal() {
|
||||
const { state, dispatch } = useContext(store);
|
||||
const [cropping, setCropping] = useState(false);
|
||||
const [crop, setCrop] = useState(undefined);
|
||||
|
||||
const closeModal = () => {
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
dispatch({ type: 'SET_CURRENT_PHOTO', payload: null });
|
||||
setCropping(false);
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
dispatch({
|
||||
type: 'SET_CURRENT_PHOTO_CORRECTION',
|
||||
payload: {
|
||||
brightness: state.currentPhotoBackup.brightness,
|
||||
contrast: state.currentPhotoBackup.contrast,
|
||||
color: state.currentPhotoBackup.color,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: 'SET_CURRENT_PHOTO_CROP',
|
||||
payload: {
|
||||
cropX: state.currentPhotoBackup.cropX,
|
||||
cropY: state.currentPhotoBackup.cropY,
|
||||
cropWidth: state.currentPhotoBackup.cropWidth,
|
||||
cropHeight: state.currentPhotoBackup.cropHeight,
|
||||
},
|
||||
});
|
||||
closeModal();
|
||||
};
|
||||
|
||||
const photo = state.currentPhoto;
|
||||
|
||||
const isVisible = state.modal === 'EDIT-PHOTO' && photo !== null;
|
||||
|
||||
const imageUrl = `${API_SERVER}/photo/${state.currentCollection}/${photo?.uuid}`;
|
||||
|
||||
const save = async () => {
|
||||
await savePhoto(state.currentCollection, photo?.uuid, photo);
|
||||
closeModal();
|
||||
};
|
||||
|
||||
const brightnessChange = (e, t) => {
|
||||
dispatch({
|
||||
type: 'SET_CURRENT_PHOTO_CORRECTION',
|
||||
payload: {
|
||||
brightness: t,
|
||||
contrast: photo.contrast,
|
||||
color: photo.color,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const contrastChange = (e, t) => {
|
||||
dispatch({
|
||||
type: 'SET_CURRENT_PHOTO_CORRECTION',
|
||||
payload: {
|
||||
brightness: photo.brightness,
|
||||
contrast: t,
|
||||
color: photo.color,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const colorChange = (e, t) => {
|
||||
dispatch({
|
||||
type: 'SET_CURRENT_PHOTO_CORRECTION',
|
||||
payload: {
|
||||
brightness: photo.brightness,
|
||||
contrast: photo.contrast,
|
||||
color: t,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const startCropping = () => {
|
||||
setCropping(true);
|
||||
};
|
||||
|
||||
const stopCropping = () => {
|
||||
setCropping(false);
|
||||
};
|
||||
|
||||
const saveCropping = () => {
|
||||
dispatch({
|
||||
type: 'SET_CURRENT_PHOTO_CROP',
|
||||
payload: crop,
|
||||
});
|
||||
setCropping(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{isVisible && (
|
||||
<motion.div
|
||||
animate={{ opacity: 1 }}
|
||||
initial={{ opacity: 0 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className="flex fixed w-full h-full bg-black bg-opacity-40 top-0 left-0"
|
||||
onClick={cancel}
|
||||
>
|
||||
<div
|
||||
className="flex flex-col flex-nowrap m-auto bg-white rounded-t-lg shadow-lg p-4"
|
||||
style={{
|
||||
width: '80%',
|
||||
height: '80%',
|
||||
}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<span className="ml-auto px-4 flex">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="text-gray-400 m-auto cursor-pointer hover:text-gray-500 duration-200"
|
||||
onClick={cancel}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M6 18L18 6M6 6l12 12"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
<div className="flex flex-row flex-nowrap flex-1">
|
||||
<div className="flex flex-col">
|
||||
<div className="flex my-auto">
|
||||
{!cropping && (
|
||||
<PhotoRenderer
|
||||
imgUrl={imageUrl}
|
||||
width={photo.thumbnailWidth}
|
||||
height={photo.thumbnailHeight}
|
||||
photo={photo}
|
||||
/>
|
||||
)}
|
||||
{cropping && (
|
||||
<PhotoCropper
|
||||
onCrop={setCrop}
|
||||
photo={photo}
|
||||
enabled={cropping}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="pb-8 mt-auto">
|
||||
{!cropping && (
|
||||
<button
|
||||
onClick={startCropping}
|
||||
className="flex outline-none focus:outline-none items-center justify-center px-12 py-2 border text-base font-medium rounded-md text-black bg-white hover:bg-gray-100 duration-200"
|
||||
>
|
||||
<span>Kadruj</span>
|
||||
</button>
|
||||
)}
|
||||
{cropping && (
|
||||
<div className="flex flex-row flex-nowrap">
|
||||
<button
|
||||
onClick={stopCropping}
|
||||
className="flex outline-none focus:outline-none items-center justify-center px-12 py-2 border text-base font-medium rounded-md text-black bg-white hover:bg-gray-100 duration-200"
|
||||
>
|
||||
<span>Anuluj kadrowanie</span>
|
||||
</button>
|
||||
<button
|
||||
onClick={saveCropping}
|
||||
className="flex ml-auto outline-none focus:outline-none items-center justify-center px-12 py-2 border text-base font-medium rounded-md text-black bg-white hover:bg-gray-100 duration-200"
|
||||
>
|
||||
<span>Zapisz kadrowanie</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="ml-auto flex flex-col flex-1 mt-4">
|
||||
<h2 className="text-center font-medium text-3xl text-gray-700">
|
||||
Opcje
|
||||
</h2>
|
||||
<div className="p-8 flex flex-col flex-1">
|
||||
<div className="my-auto">
|
||||
<div className="my-8">
|
||||
<span className="text-lg font-medium text-gray-700">
|
||||
Jasność
|
||||
</span>
|
||||
<Slider
|
||||
value={photo.brightness}
|
||||
step={1}
|
||||
min={-100}
|
||||
max={100}
|
||||
valueLabelDisplay="auto"
|
||||
onChange={brightnessChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="my-8">
|
||||
<span className="text-lg font-medium text-gray-700">
|
||||
Kontrast
|
||||
</span>
|
||||
<Slider
|
||||
value={photo.contrast}
|
||||
step={0.02}
|
||||
min={0}
|
||||
max={3}
|
||||
valueLabelDisplay="auto"
|
||||
onChange={contrastChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="my-8">
|
||||
<span className="text-lg font-medium text-gray-700">
|
||||
Nasycenie
|
||||
</span>
|
||||
<Slider
|
||||
value={photo.color}
|
||||
step={0.05}
|
||||
min={0}
|
||||
max={5}
|
||||
valueLabelDisplay="auto"
|
||||
onChange={colorChange}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-auto flex flex-row">
|
||||
<button
|
||||
onClick={cancel}
|
||||
className="flex outline-none focus:outline-none items-center justify-center px-12 py-2 border text-base font-medium rounded-md text-black bg-white hover:bg-gray-100 duration-200"
|
||||
>
|
||||
<span>Anuluj</span>
|
||||
</button>
|
||||
<button
|
||||
disabled={cropping}
|
||||
onClick={save}
|
||||
className="flex ml-auto outline-none focus:outline-none items-center justify-center px-12 py-2 border border-transparent text-base font-medium rounded-md text-white bg-green-600 hover:bg-green-700 duration-200"
|
||||
>
|
||||
<span>Zapisz</span>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="h-6 ml-2"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
|
||||
export default EditPhotoModal;
|
42
src/CollectionApp/Photo.js
Normal file
42
src/CollectionApp/Photo.js
Normal file
@ -0,0 +1,42 @@
|
||||
import React, { useContext } from 'react';
|
||||
import { store } from '../store';
|
||||
import { API_SERVER } from '../config';
|
||||
import PhotoRenderer from './PhotoRenderer';
|
||||
import DeletePhotoButton from './DeletePhotoButton';
|
||||
import EditPhotoButton from './EditPhotoButton';
|
||||
import DownloadPhotoButton from './DownloadPhotoButton';
|
||||
|
||||
function Photo(props) {
|
||||
const { state } = useContext(store);
|
||||
|
||||
const imageUrl = `${API_SERVER}/photo/${state.currentCollection}/${props.photo.uuid}`;
|
||||
|
||||
const name = props.photo.name.split('.jpg')[0];
|
||||
|
||||
return (
|
||||
<div className="flex flex-nowrap flex-col border rounded-t-lg bg-gray-50">
|
||||
<div className="">
|
||||
<DeletePhotoButton className="p-1" uuid={props.photo.uuid} />
|
||||
</div>
|
||||
<div className="p-4">
|
||||
<div className="mb-4">
|
||||
<PhotoRenderer
|
||||
imgUrl={imageUrl}
|
||||
photo={props.photo}
|
||||
width={props.photo.thumbnailWidth}
|
||||
height={props.photo.thumbnailHeight}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-base font-medium text-gray-700 block text-center">
|
||||
{name}
|
||||
</span>
|
||||
<div className="mt-6 flex flex-row flex-nowrap">
|
||||
<EditPhotoButton photo={props.photo} />{' '}
|
||||
<DownloadPhotoButton photo={props.photo} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Photo;
|
73
src/CollectionApp/PhotoCropper.js
Normal file
73
src/CollectionApp/PhotoCropper.js
Normal file
@ -0,0 +1,73 @@
|
||||
import React, { useContext, useRef } from 'react';
|
||||
import { store } from '../store';
|
||||
import { API_SERVER } from '../config';
|
||||
|
||||
import Cropper from 'react-cropper';
|
||||
import 'cropperjs/dist/cropper.css';
|
||||
|
||||
const IMAGE_SIZE = 500;
|
||||
|
||||
function PhotoCropper(props) {
|
||||
const { state } = useContext(store);
|
||||
|
||||
const cropperRef = useRef(null);
|
||||
|
||||
const onCrop = () => {
|
||||
if (!props.enabled) {
|
||||
return;
|
||||
}
|
||||
const imageElement = cropperRef.current;
|
||||
const cropper = imageElement.cropper;
|
||||
const crop = cropper.getCropBoxData();
|
||||
const scaledCrop = {
|
||||
cropX: Math.floor(crop.left * scale),
|
||||
cropY: Math.floor(crop.top * scale),
|
||||
cropWidth: Math.floor(crop.width * scale),
|
||||
cropHeight: Math.floor(crop.height * scale),
|
||||
};
|
||||
props.onCrop(scaledCrop);
|
||||
};
|
||||
|
||||
const photo = props.photo;
|
||||
|
||||
const imageUrl = `${API_SERVER}/photo/${state.currentCollection}/${photo.uuid}`;
|
||||
|
||||
const scale = photo.width / photo.thumbnailWidth;
|
||||
|
||||
const scaledX = Math.floor(photo.cropX / scale);
|
||||
const scaledY = Math.floor(photo.cropY / scale);
|
||||
const scaledWidth = Math.floor(photo.cropWidth / scale);
|
||||
const scaledHeight = Math.floor(photo.cropHeight / scale);
|
||||
|
||||
if (!props.enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
width: IMAGE_SIZE,
|
||||
height: IMAGE_SIZE,
|
||||
}}
|
||||
className="shadow flex"
|
||||
>
|
||||
<Cropper
|
||||
src={imageUrl}
|
||||
crop={onCrop}
|
||||
ref={cropperRef}
|
||||
className="m-auto"
|
||||
movable={false}
|
||||
ready={() => {
|
||||
cropperRef.current.cropper.setCropBoxData({
|
||||
left: scaledX,
|
||||
top: scaledY,
|
||||
width: scaledWidth,
|
||||
height: scaledHeight,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PhotoCropper;
|
181
src/CollectionApp/PhotoRenderer.js
Normal file
181
src/CollectionApp/PhotoRenderer.js
Normal file
@ -0,0 +1,181 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
|
||||
const IMAGE_SIZE = 500;
|
||||
|
||||
const fitInRGB = (val) => {
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
}
|
||||
if (val < 0) {
|
||||
return 0;
|
||||
}
|
||||
return val;
|
||||
};
|
||||
|
||||
function PhotoRenderer(props) {
|
||||
const canvas = useRef(null);
|
||||
const [width, setWidth] = useState(0);
|
||||
const [height, setHeight] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const applyCorrections = (ctx, width, height) => {
|
||||
applyBrightness(ctx, width, height);
|
||||
applyContrast(ctx, width, height);
|
||||
applyColor(ctx, width, height);
|
||||
};
|
||||
|
||||
const applyBrightness = (ctx, width, height) => {
|
||||
const brightness = props.photo.brightness;
|
||||
|
||||
const imageData = ctx.getImageData(0, 0, width, height);
|
||||
const data = imageData.data;
|
||||
for (var i = 0; i < data.length; i += 4) {
|
||||
data[i] = fitInRGB(data[i] + brightness);
|
||||
data[i + 1] = fitInRGB(data[i + 1] + brightness);
|
||||
data[i + 2] = fitInRGB(data[i + 2] + brightness);
|
||||
}
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
};
|
||||
|
||||
const applyContrast = (ctx, width, height) => {
|
||||
const contrast = props.photo.contrast;
|
||||
const intercept = 255 * (-contrast / 2 + 0.5);
|
||||
|
||||
const imageData = ctx.getImageData(0, 0, width, height);
|
||||
const data = imageData.data;
|
||||
for (var i = 0; i < data.length; i += 4) {
|
||||
data[i] = fitInRGB(data[i] * contrast + intercept);
|
||||
data[i + 1] = fitInRGB(data[i + 1] * contrast + intercept);
|
||||
data[i + 2] = fitInRGB(data[i + 2] * contrast + intercept);
|
||||
}
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
};
|
||||
|
||||
const applyColor = (ctx, width, height) => {
|
||||
const s = props.photo.color;
|
||||
|
||||
const imageData = ctx.getImageData(0, 0, width, height);
|
||||
const data = imageData.data;
|
||||
for (var i = 0; i < data.length; i += 4) {
|
||||
const r = data[i];
|
||||
const g = data[i + 1];
|
||||
const b = data[i + 2];
|
||||
const newR =
|
||||
r * (0.213 + 0.787 * s) +
|
||||
g * (0.715 - 0.715 * s) +
|
||||
b * (0.072 - 0.072 * s);
|
||||
const newG =
|
||||
r * (0.213 - 0.213 * s) +
|
||||
g * (0.715 + 0.285 * s) +
|
||||
b * (0.072 - 0.072 * s);
|
||||
const newB =
|
||||
r * (0.213 - 0.213 * s) +
|
||||
g * (0.715 - 0.715 * s) +
|
||||
b * (0.072 + 0.928 * s);
|
||||
data[i] = fitInRGB(newR);
|
||||
data[i + 1] = fitInRGB(newG);
|
||||
data[i + 2] = fitInRGB(newB);
|
||||
}
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
};
|
||||
|
||||
const img = new Image();
|
||||
img.crossOrigin = 'Anonymous';
|
||||
|
||||
img.addEventListener(
|
||||
'load',
|
||||
() => {
|
||||
if (!canvas.current) {
|
||||
return;
|
||||
}
|
||||
const ctx = canvas.current.getContext('2d');
|
||||
|
||||
const cropDetails = {};
|
||||
|
||||
if (props.crop) {
|
||||
cropDetails.cropX = props.crop.cropX;
|
||||
cropDetails.cropY = props.crop.cropY;
|
||||
cropDetails.cropWidth = props.crop.cropWidth;
|
||||
cropDetails.cropHeight = props.crop.cropHeight;
|
||||
} else {
|
||||
cropDetails.cropX = props.photo.cropX;
|
||||
cropDetails.cropY = props.photo.cropY;
|
||||
cropDetails.cropWidth = props.photo.cropWidth;
|
||||
cropDetails.cropHeight = props.photo.cropHeight;
|
||||
}
|
||||
|
||||
const scale = props.photo.width / props.photo.thumbnailWidth;
|
||||
|
||||
let croppedScale = 0;
|
||||
|
||||
if (cropDetails.cropWidth > cropDetails.cropHeight) {
|
||||
croppedScale = IMAGE_SIZE / (cropDetails.cropWidth / scale);
|
||||
} else {
|
||||
croppedScale = IMAGE_SIZE / (cropDetails.cropHeight / scale);
|
||||
}
|
||||
|
||||
const scaledCroppedWidth = Math.floor(
|
||||
(cropDetails.cropWidth / scale) * croppedScale
|
||||
);
|
||||
const scaledCroppedHeight = Math.floor(
|
||||
(cropDetails.cropHeight / scale) * croppedScale
|
||||
);
|
||||
|
||||
setWidth(scaledCroppedWidth);
|
||||
setHeight(scaledCroppedHeight);
|
||||
|
||||
const scaledCroppedX = Math.floor(
|
||||
(cropDetails.cropX / scale) * croppedScale
|
||||
);
|
||||
const scaledCroppedY = Math.floor(
|
||||
(cropDetails.cropY / scale) * croppedScale
|
||||
);
|
||||
|
||||
const x = -scaledCroppedX;
|
||||
const y = -scaledCroppedY;
|
||||
const width = props.photo.thumbnailWidth * croppedScale;
|
||||
const height = props.photo.thumbnailHeight * croppedScale;
|
||||
|
||||
ctx.clearRect(0, 0, IMAGE_SIZE, IMAGE_SIZE);
|
||||
ctx.drawImage(img, x, y, width, height);
|
||||
if (!scaledCroppedWidth || !scaledCroppedHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
applyCorrections(ctx, width, height);
|
||||
},
|
||||
false
|
||||
);
|
||||
img.src = props.imgUrl;
|
||||
}, [
|
||||
props.photo.color,
|
||||
props.photo.brightness,
|
||||
props.photo.contrast,
|
||||
props.crop,
|
||||
props.imgUrl,
|
||||
props.photo.width,
|
||||
props.photo.thumbnailWidth,
|
||||
props.photo.thumbnailHeight,
|
||||
props.photo.cropX,
|
||||
props.photo.cropY,
|
||||
props.photo.cropWidth,
|
||||
props.photo.cropHeight,
|
||||
]);
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{ width: `${500}px`, height: `${500}px` }}
|
||||
className="flex shadow overflow-hidden m-auto"
|
||||
>
|
||||
<canvas
|
||||
className="m-auto"
|
||||
ref={canvas}
|
||||
width={width}
|
||||
height={height}
|
||||
style={{ width: `${width}px`, height: `${height}px` }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PhotoRenderer;
|
42
src/Collections/Collection.js
Normal file
42
src/Collections/Collection.js
Normal file
@ -0,0 +1,42 @@
|
||||
import React, { useContext } from 'react';
|
||||
|
||||
import { store } from '../store';
|
||||
|
||||
function Collection(props) {
|
||||
const { dispatch } = useContext(store);
|
||||
|
||||
const setCurrentCollection = async (e) => {
|
||||
e.preventDefault();
|
||||
dispatch({ type: 'SET_CURRENT_COLLECTION', payload: props.uuid });
|
||||
};
|
||||
return (
|
||||
<div className="flex mx-auto h-60 w-60 relative">
|
||||
<div
|
||||
onClick={setCurrentCollection}
|
||||
className="flex mx-auto h-60 w-60 rounded-lg cursor-pointer border bg-white hover:bg-green-600 text-green-600 hover:text-white duration-500 overflow-hidden p-2"
|
||||
>
|
||||
<div className="flex flex-nowrap flex-col m-auto">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="h-24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
|
||||
/>
|
||||
</svg>
|
||||
<span className="text-xl font-medium mx-auto mt-1 break-all text-center">
|
||||
{props.name}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Collection;
|
123
src/Collections/CollectionNameModal.js
Normal file
123
src/Collections/CollectionNameModal.js
Normal file
@ -0,0 +1,123 @@
|
||||
import React, { useState, useContext } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { store } from '../store';
|
||||
import { newCollection } from '../apiClient';
|
||||
|
||||
function CollectionNameModal() {
|
||||
const [isSending, setIsSending] = useState(false);
|
||||
|
||||
const [name, setName] = useState('');
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const { state, dispatch } = useContext(store);
|
||||
|
||||
const closeModal = () => {
|
||||
if (isSending) return;
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
};
|
||||
|
||||
const sendCollectionRequest = async () => {
|
||||
if (isSending) return;
|
||||
|
||||
if (!name.length) {
|
||||
setError('Nazwa nie może być pusta');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSending(true);
|
||||
|
||||
try {
|
||||
const collection = await newCollection(name);
|
||||
|
||||
dispatch({ type: 'ADD_COLLECTION', payload: collection });
|
||||
|
||||
dispatch({ type: 'SET_CURRENT_COLLECTION', payload: collection.uuid });
|
||||
if (state.user.uuid === null) {
|
||||
window.localStorage.setItem('collection', collection.uuid);
|
||||
}
|
||||
} catch (e) {
|
||||
setError('Wystąpił błąd');
|
||||
setIsSending(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setError(null);
|
||||
setIsSending(false);
|
||||
dispatch({ type: 'SET_MODAL', payload: '' });
|
||||
};
|
||||
|
||||
const isVisible = state.modal === 'COLLECTION_NAME';
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{isVisible && (
|
||||
<motion.div
|
||||
animate={{ opacity: 1 }}
|
||||
initial={{ opacity: 0 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className="flex fixed w-full h-full bg-black bg-opacity-40 top-0 left-0"
|
||||
onClick={closeModal}
|
||||
>
|
||||
<div
|
||||
className="flex flex-col flex-nowrap w-96 h-72 m-auto bg-white rounded-t-lg shadow-lg"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<div className="shadow py-4 px-2 flex">
|
||||
<span className="text-xl text-gray-900">
|
||||
Nazwij nową kolekcję
|
||||
</span>
|
||||
<span className="ml-auto px-4 flex">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="text-gray-400 m-auto cursor-pointer hover:text-gray-500 duration-200"
|
||||
onClick={closeModal}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M6 18L18 6M6 6l12 12"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div className="py-4 px-2">
|
||||
<label className="block">
|
||||
<span className="text-gray-700">Nazwa</span>
|
||||
<input
|
||||
type="text"
|
||||
name="login"
|
||||
className="mt-1 block w-full"
|
||||
placeholder=""
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{error && (
|
||||
<div className="text-center text-red-500 py-2">{error}</div>
|
||||
)}
|
||||
<div className="mt-auto border-t py-3 px-2">
|
||||
<button
|
||||
disabled={isSending}
|
||||
className="flex mx-auto outline-none focus:outline-none items-center justify-center px-12 py-3 border border-transparent text-base font-medium rounded-md text-white bg-green-600 hover:bg-green-700 duration-200"
|
||||
onClick={sendCollectionRequest}
|
||||
>
|
||||
Utwórz
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
|
||||
export default CollectionNameModal;
|
36
src/Collections/Collections.js
Normal file
36
src/Collections/Collections.js
Normal file
@ -0,0 +1,36 @@
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import { getCollections } from '../apiClient';
|
||||
import { store } from '../store';
|
||||
import Collection from './Collection';
|
||||
import NewCollectionButton from './NewCollectionButton';
|
||||
|
||||
function Collections() {
|
||||
const { state, dispatch } = useContext(store);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
let collections = [];
|
||||
collections = await getCollections();
|
||||
dispatch({ type: 'SET_COLLECTIONS', payload: collections });
|
||||
};
|
||||
if (state.user.uuid !== null) {
|
||||
fetchData();
|
||||
}
|
||||
}, [state.user.uuid, dispatch]);
|
||||
|
||||
let collections = [<NewCollectionButton key="new" />];
|
||||
|
||||
let newCollections = state.collections.map((col) => {
|
||||
return <Collection uuid={col.uuid} name={col.name} key={col.uuid} />;
|
||||
});
|
||||
|
||||
collections = [...collections, newCollections];
|
||||
|
||||
return (
|
||||
<div className="grid grid-flow-row grid-cols-3 grid-rows-3 gap-4 gap-y-12">
|
||||
{collections}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Collections;
|
38
src/Collections/NewCollectionButton.js
Normal file
38
src/Collections/NewCollectionButton.js
Normal file
@ -0,0 +1,38 @@
|
||||
import React, { useContext } from 'react';
|
||||
import { store } from '../store';
|
||||
|
||||
function NewCollectionButton() {
|
||||
const { dispatch } = useContext(store);
|
||||
const showCollectionNameModal = () => {
|
||||
dispatch({ type: 'SET_MODAL', payload: 'COLLECTION_NAME' });
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className="flex mx-auto h-60 w-60 rounded-lg cursor-pointer bg-green-600 hover:bg-white text-white hover:text-green-600 duration-500"
|
||||
onClick={showCollectionNameModal}
|
||||
>
|
||||
<div className="flex flex-nowrap flex-col m-auto">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
className="h-24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
|
||||
/>
|
||||
</svg>
|
||||
<span className="text-xl font-medium mx-auto mt-1">
|
||||
Stwórz nową kolekcję
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default NewCollectionButton;
|
39
src/Header/AuthButtons.js
Normal file
39
src/Header/AuthButtons.js
Normal file
@ -0,0 +1,39 @@
|
||||
import React, { useContext } from 'react';
|
||||
|
||||
import { store } from '../store';
|
||||
|
||||
function AuthButtons() {
|
||||
const { state, dispatch } = useContext(store);
|
||||
const showLoginModal = () => {
|
||||
dispatch({ type: 'SET_MODAL', payload: 'LOGIN' });
|
||||
};
|
||||
|
||||
const showRegisterModal = () => {
|
||||
dispatch({ type: 'SET_MODAL', payload: 'REGISTER' });
|
||||
};
|
||||
|
||||
const isVisible = state.user.uuid === null && state.user.loading === false;
|
||||
|
||||
if (!isVisible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="ml-auto flex flex-nowrap">
|
||||
<button
|
||||
className="flex mr-4 outline-none focus:outline-none items-center justify-center px-2 py-1 border border-transparent text-base font-medium rounded-md text-white bg-green-600 hover:bg-green-700 duration-200"
|
||||
onClick={showLoginModal}
|
||||
>
|
||||
Zaloguj się
|
||||
</button>
|
||||
<button
|
||||
className="text-base font-medium text-gray-700 hover:text-gray-900 duration-200"
|
||||
onClick={showRegisterModal}
|
||||
>
|
||||
Zarejestruj się
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default AuthButtons;
|
22
src/Header/Header.js
Normal file
22
src/Header/Header.js
Normal file
@ -0,0 +1,22 @@
|
||||
import React, { useContext } from 'react';
|
||||
import UserButtons from "./UserButtons";
|
||||
import AuthButtons from "./AuthButtons";
|
||||
import { store } from '../store';
|
||||
|
||||
function Header() {
|
||||
const { state } = useContext(store);
|
||||
|
||||
const text = state.view.name || "Foto edytor";
|
||||
|
||||
return (
|
||||
<header className="bg-white shadow-md">
|
||||
<div className="flex max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
|
||||
<h1 className="text-3xl font-bold text-gray-900">{text}</h1>
|
||||
<UserButtons />
|
||||
<AuthButtons />
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
export default Header;
|
69
src/Header/UserButtons.js
Normal file
69
src/Header/UserButtons.js
Normal file
@ -0,0 +1,69 @@
|
||||
import React, { useContext } from 'react';
|
||||
import { logout } from '../apiClient';
|
||||
import { store } from '../store';
|
||||
|
||||
function UserButtons() {
|
||||
const { state, dispatch } = useContext(store);
|
||||
|
||||
const logoutUser = async () => {
|
||||
await logout();
|
||||
dispatch({ type: 'SET_PHOTOS', payload: [] });
|
||||
dispatch({ type: 'SET_CURRENT_COLLECTION', payload: null });
|
||||
dispatch({
|
||||
type: 'SET_COLLECTIONS',
|
||||
payload: [],
|
||||
});
|
||||
dispatch({
|
||||
type: 'SET_USER',
|
||||
payload: { uuid: null, username: null },
|
||||
});
|
||||
};
|
||||
|
||||
const showSettingsModal = () => {
|
||||
dispatch({ type: 'SET_MODAL', payload: 'SETTINGS' });
|
||||
};
|
||||
|
||||
const setCurrentCollection = async (e) => {
|
||||
e.preventDefault();
|
||||
dispatch({ type: 'SET_PHOTOS', payload: [] });
|
||||
dispatch({ type: 'SET_CURRENT_COLLECTION', payload: null });
|
||||
};
|
||||
|
||||
const currentCollection = state.currentCollection;
|
||||
|
||||
const isVisible = state.user.uuid !== null;
|
||||
|
||||
if (!isVisible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="ml-auto flex items-center">
|
||||
<span className="text-base mr-4 font-medium text-gray-700">
|
||||
Witaj, {state.user.username}
|
||||
</span>
|
||||
{currentCollection && (
|
||||
<button
|
||||
onClick={setCurrentCollection}
|
||||
className="text-base mr-4 font-medium text-green-700 hover:text-green-900 duration-200"
|
||||
>
|
||||
Moje kolekcje
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
className="text-base mr-4 font-medium text-gray-700 hover:text-gray-900 duration-200"
|
||||
onClick={showSettingsModal}
|
||||
>
|
||||
Ustawienia
|
||||
</button>
|
||||
<button
|
||||
className="text-base font-medium text-gray-700 hover:text-gray-900 duration-200"
|
||||
onClick={logoutUser}
|
||||
>
|
||||
Wyloguj się
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserButtons;
|
31
src/Layout.js
Normal file
31
src/Layout.js
Normal file
@ -0,0 +1,31 @@
|
||||
import React, { useContext } from 'react';
|
||||
import LoginModal from './Auth/LoginModal';
|
||||
import RegisterModal from './Auth/RegisterModal';
|
||||
import CollectionNameModal from './Collections/CollectionNameModal';
|
||||
import SettingsModal from './Auth/SettingsModal';
|
||||
import Header from './Header/Header';
|
||||
import Collections from './Collections/Collections';
|
||||
import CollectionApp from './CollectionApp/CollectionApp';
|
||||
import { store } from './store';
|
||||
|
||||
function Layout() {
|
||||
const { state } = useContext(store);
|
||||
const currentCollection = state.currentCollection;
|
||||
return (
|
||||
<div>
|
||||
<Header />
|
||||
<main>
|
||||
<div className="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
|
||||
{!currentCollection && <Collections />}
|
||||
{currentCollection && <CollectionApp uuid={currentCollection} />}
|
||||
</div>
|
||||
</main>
|
||||
<LoginModal />
|
||||
<RegisterModal />
|
||||
<SettingsModal />
|
||||
<CollectionNameModal />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Layout;
|
123
src/apiClient.js
Normal file
123
src/apiClient.js
Normal file
@ -0,0 +1,123 @@
|
||||
import axios from 'axios';
|
||||
import { API_SERVER } from './config';
|
||||
|
||||
export const getUser = async () => {
|
||||
const user = await axios.get(`${API_SERVER}/user`, { withCredentials: true });
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
export const getCollections = async () => {
|
||||
const colections = await axios.get(`${API_SERVER}/collection`, {
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
return colections.data;
|
||||
};
|
||||
|
||||
export const getPhotos = async (uuid) => {
|
||||
const colections = await axios.get(`${API_SERVER}/collection/${uuid}/photo`, {
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
return colections.data;
|
||||
};
|
||||
|
||||
export const login = async (username, password) => {
|
||||
const user = await axios.post(
|
||||
`${API_SERVER}/auth/login`,
|
||||
{
|
||||
username,
|
||||
password,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
);
|
||||
|
||||
return user.data;
|
||||
};
|
||||
|
||||
export const logout = async () => {
|
||||
await axios.get(`${API_SERVER}/auth/logout`, {
|
||||
withCredentials: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const changePassword = async (password) => {
|
||||
await axios.post(
|
||||
`${API_SERVER}/auth/password`,
|
||||
{
|
||||
password,
|
||||
},
|
||||
{
|
||||
withCredentials: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const register = async (username, password) => {
|
||||
const user = await axios.post(
|
||||
`${API_SERVER}/auth/register`,
|
||||
{
|
||||
username,
|
||||
password,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
);
|
||||
|
||||
return user.data;
|
||||
};
|
||||
|
||||
export const deleteAccount = async () => {
|
||||
await axios.get(
|
||||
`${API_SERVER}/auth/delete`,
|
||||
|
||||
{ withCredentials: true }
|
||||
);
|
||||
};
|
||||
|
||||
export const newCollection = async (name) => {
|
||||
const collection = await axios.post(
|
||||
`${API_SERVER}/collection/new`,
|
||||
{ name },
|
||||
{ withCredentials: true }
|
||||
);
|
||||
return collection.data;
|
||||
};
|
||||
|
||||
export const deleteCollection = async (uuid) => {
|
||||
await axios.delete(`${API_SERVER}/collection/${uuid}`, {
|
||||
withCredentials: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const deletePhoto = async (uuid, photoUuid) => {
|
||||
await axios.delete(`${API_SERVER}/collection/${uuid}/photo/${photoUuid}`, {
|
||||
withCredentials: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const savePhoto = async (uuid, photoUuid, photo) => {
|
||||
await axios.put(`${API_SERVER}/collection/${uuid}/photo/${photoUuid}`, photo, {
|
||||
withCredentials: true,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const claimCollection = async (uuid) => {
|
||||
axios.get(`${API_SERVER}/collection/${uuid}/claim`, {
|
||||
withCredentials: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const uploadFile = async (uuid, file) => {
|
||||
let fd = new FormData();
|
||||
fd.append('file', file);
|
||||
const request = await axios.post(`${API_SERVER}/collection/${uuid}/photo`, fd, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
return request.data
|
||||
};
|
1
src/config.js
Normal file
1
src/config.js
Normal file
@ -0,0 +1 @@
|
||||
export const API_SERVER = process.env.REACT_APP_API_SERVER || "http://localhost:3001";
|
3
src/index.css
Normal file
3
src/index.css
Normal file
@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
14
src/index.js
Normal file
14
src/index.js
Normal file
@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import { StateProvider } from './store';
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<StateProvider>
|
||||
<App />
|
||||
</StateProvider>
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
);
|
94
src/store.js
Normal file
94
src/store.js
Normal file
@ -0,0 +1,94 @@
|
||||
import React, { createContext, useReducer } from 'react';
|
||||
|
||||
const initialState = {
|
||||
user: { uuid: null, username: null, loading: true },
|
||||
modal: '',
|
||||
view: { name: '' },
|
||||
collections: [],
|
||||
currentCollection: null,
|
||||
currentPhotos: [],
|
||||
currentPhoto: null,
|
||||
currentPhotoBackup: null,
|
||||
};
|
||||
const store = createContext(initialState);
|
||||
const { Provider } = store;
|
||||
|
||||
const StateProvider = ({ children }) => {
|
||||
const [state, dispatch] = useReducer((state, action) => {
|
||||
const newState = { ...state };
|
||||
switch (action.type) {
|
||||
case 'SET_VIEW_NAME':
|
||||
newState.view.name = action.payload;
|
||||
return newState;
|
||||
case 'SET_MODAL':
|
||||
newState.modal = action.payload;
|
||||
return newState;
|
||||
case 'SET_USER':
|
||||
newState.user = action.payload;
|
||||
newState.user.loading = false;
|
||||
return newState;
|
||||
case 'USER_LOADED':
|
||||
newState.user.loading = false;
|
||||
return newState;
|
||||
case 'SET_COLLECTIONS':
|
||||
newState.collections = action.payload;
|
||||
return newState;
|
||||
case 'ADD_COLLECTION':
|
||||
newState.collections = [action.payload, ...newState.collections];
|
||||
return newState;
|
||||
case 'DELETE_COLLECTION':
|
||||
newState.collections = newState.collections.filter((collection) => {
|
||||
return collection.uuid !== action.payload;
|
||||
});
|
||||
return newState;
|
||||
case 'SET_CURRENT_COLLECTION':
|
||||
newState.currentCollection = action.payload;
|
||||
return newState;
|
||||
case 'SET_PHOTOS':
|
||||
newState.currentPhotos = action.payload;
|
||||
return newState;
|
||||
case 'ADD_PHOTO':
|
||||
newState.currentPhotos = [...newState.currentPhotos, action.payload];
|
||||
return newState;
|
||||
case 'DELETE_PHOTO':
|
||||
newState.currentPhotos = newState.currentPhotos.filter((photo) => {
|
||||
return photo.uuid !== action.payload;
|
||||
});
|
||||
return newState;
|
||||
case 'SET_CURRENT_PHOTO':
|
||||
newState.currentPhoto = action.payload;
|
||||
if (action.payload != null) {
|
||||
newState.currentPhotoBackup = {
|
||||
brightness: action.payload.brightness,
|
||||
contrast: action.payload.contrast,
|
||||
color: action.payload.color,
|
||||
cropX: action.payload.cropX,
|
||||
cropY: action.payload.cropY,
|
||||
cropWidth: action.payload.cropWidth,
|
||||
cropHeight: action.payload.cropHeight,
|
||||
};
|
||||
} else {
|
||||
newState.currentPhotoBackup = null;
|
||||
}
|
||||
|
||||
return newState;
|
||||
case 'SET_CURRENT_PHOTO_CORRECTION':
|
||||
newState.currentPhoto.brightness = action.payload.brightness;
|
||||
newState.currentPhoto.contrast = action.payload.contrast;
|
||||
newState.currentPhoto.color = action.payload.color;
|
||||
return newState;
|
||||
case 'SET_CURRENT_PHOTO_CROP':
|
||||
newState.currentPhoto.cropX = action.payload.cropX;
|
||||
newState.currentPhoto.cropY = action.payload.cropY;
|
||||
newState.currentPhoto.cropWidth = action.payload.cropWidth;
|
||||
newState.currentPhoto.cropHeight = action.payload.cropHeight;
|
||||
return newState;
|
||||
default:
|
||||
throw new Error();
|
||||
}
|
||||
}, initialState);
|
||||
|
||||
return <Provider value={{ state, dispatch }}>{children}</Provider>;
|
||||
};
|
||||
|
||||
export { store, StateProvider };
|
11
tailwind.config.js
Normal file
11
tailwind.config.js
Normal file
@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
|
||||
darkMode: false, // or 'media' or 'class'
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
variants: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [require('@tailwindcss/forms')],
|
||||
};
|
Loading…
Reference in New Issue
Block a user