diff --git a/net/web/src/session/account/profile/Profile.jsx b/net/web/src/session/account/profile/Profile.jsx index e82cc72d..f91d1511 100644 --- a/net/web/src/session/account/profile/Profile.jsx +++ b/net/web/src/session/account/profile/Profile.jsx @@ -1,12 +1,11 @@ -import { useRef } from 'react'; -import { Space, Modal, Button } from 'antd'; -import { ProfileWrapper, EditFooter } from './Profile.styled'; +import { useRef, useCallback } from 'react'; +import { Space, Modal, Input, Button } from 'antd'; +import { ProfileWrapper, ProfileDetailsWrapper, ProfileImageWrapper, EditFooter } from './Profile.styled'; import { useProfile } from './useProfile.hook'; -import { ProfileImage } from './profileImage/ProfileImage'; -import { ProfileDetails } from './profileDetails/ProfileDetails'; import { Logo } from 'logo/Logo'; import { AccountAccess } from './accountAccess/AccountAccess'; import { LogoutOutlined, RightOutlined, EditOutlined, BookOutlined, EnvironmentOutlined } from '@ant-design/icons'; +import Cropper from 'react-easy-crop'; export function Profile({ closeProfile }) { @@ -65,7 +64,7 @@ export function Profile({ closeProfile }) { selected(e)} style={{display: 'none'}}/>
- +
@@ -80,6 +79,11 @@ export function Profile({ closeProfile }) {
); + const onCropComplete = useCallback((area, crop) => { + actions.setEditImageCrop(crop.width, crop.height, crop.x, crop.y) + // eslint-disable-next-line + }, []); + return ( { modalContext } @@ -152,11 +156,31 @@ export function Profile({ closeProfile }) { )} - + + + + + - + + +
+ actions.setEditName(e.target.value)} + defaultValue={state.editName} autocapitalize="word" /> +
+
+ actions.setEditLocation(e.target.value)} + defaultValue={state.editLocation} autocapitalize="word" /> +
+
+ actions.setEditDescription(e.target.value)} + spellCheck="false" defaultValue={state.editDescription} autoSize={{ minRows: 2, maxRows: 6 }} /> +
+
+
); diff --git a/net/web/src/session/account/profile/Profile.styled.js b/net/web/src/session/account/profile/Profile.styled.js index 2a4d80a6..f5da50ea 100644 --- a/net/web/src/session/account/profile/Profile.styled.js +++ b/net/web/src/session/account/profile/Profile.styled.js @@ -204,4 +204,24 @@ export const EditFooter = styled.div` flex-grow: 1; } ` +export const ProfileDetailsWrapper = styled.div` + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + + .info { + width: 100%; + padding: 8px; + } +`; + +export const ProfileImageWrapper = styled.div` + position: relative; + height: 256px; + width: 100%; + display: flex; + align-items: center; + justify-content: center; +`; diff --git a/net/web/src/session/account/profile/profileDetails/ProfileDetails.jsx b/net/web/src/session/account/profile/profileDetails/ProfileDetails.jsx deleted file mode 100644 index 31aaa69d..00000000 --- a/net/web/src/session/account/profile/profileDetails/ProfileDetails.jsx +++ /dev/null @@ -1,22 +0,0 @@ -import { Input } from 'antd'; -import { ProfileDetailsWrapper } from './ProfileDetails.styled'; - -export function ProfileDetails({ state, actions }) { - return ( - -
- actions.setEditName(e.target.value)} - defaultValue={state.editName} autocapitalize="word" /> -
-
- actions.setEditLocation(e.target.value)} - defaultValue={state.editLocation} autocapitalize="word" /> -
-
- actions.setEditDescription(e.target.value)} - spellCheck="false" defaultValue={state.editDescription} autoSize={{ minRows: 2, maxRows: 6 }} /> -
-
- ); -} - diff --git a/net/web/src/session/account/profile/profileDetails/ProfileDetails.styled.js b/net/web/src/session/account/profile/profileDetails/ProfileDetails.styled.js deleted file mode 100644 index dae855df..00000000 --- a/net/web/src/session/account/profile/profileDetails/ProfileDetails.styled.js +++ /dev/null @@ -1,14 +0,0 @@ -import styled from 'styled-components'; - -export const ProfileDetailsWrapper = styled.div` - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - - .info { - width: 100%; - padding: 8px; - } -`; - diff --git a/net/web/src/session/account/profile/profileImage/ProfileImage.jsx b/net/web/src/session/account/profile/profileImage/ProfileImage.jsx deleted file mode 100644 index e7188ae6..00000000 --- a/net/web/src/session/account/profile/profileImage/ProfileImage.jsx +++ /dev/null @@ -1,22 +0,0 @@ -import { useState, useCallback } from 'react'; -import Cropper from 'react-easy-crop' -import { ProfileImageWrapper } from './ProfileImage.styled'; - -export function ProfileImage({ state, actions }) { - - const [crop, setCrop] = useState({ x: 0, y: 0 }) - const [zoom, setZoom] = useState(1) - - const onCropComplete = useCallback((area, crop) => { - actions.setEditImageCrop(crop.width, crop.height, crop.x, crop.y) - // eslint-disable-next-line - }, []); - - return ( - - - - ) -} - diff --git a/net/web/src/session/account/profile/profileImage/ProfileImage.styled.js b/net/web/src/session/account/profile/profileImage/ProfileImage.styled.js deleted file mode 100644 index e59cfce1..00000000 --- a/net/web/src/session/account/profile/profileImage/ProfileImage.styled.js +++ /dev/null @@ -1,11 +0,0 @@ -import styled from 'styled-components'; - -export const ProfileImageWrapper = styled.div` - position: relative; - height: 256px; - width: 100%; - display: flex; - align-items: center; - justify-content: center; -`; - diff --git a/net/web/src/session/account/profile/useProfile.hook.js b/net/web/src/session/account/profile/useProfile.hook.js index bf031166..f95d8626 100644 --- a/net/web/src/session/account/profile/useProfile.hook.js +++ b/net/web/src/session/account/profile/useProfile.hook.js @@ -7,9 +7,6 @@ import avatar from 'images/avatar.png'; export function useProfile() { const [state, setState] = useState({ - init: false, - editProfileImage: false, - editProfileDetails: false, handle: null, name: null, location: null, @@ -18,10 +15,14 @@ export function useProfile() { editName: null, editLocation: null, editDescription: null, - crop: { w: 0, h: 0, x: 0, y: 0 }, + editProfileImage: false, + editProfileDetails: false, + clip: { w: 0, h: 0, x: 0, y: 0 }, + + crop: { x: 0, y: 0}, + zoom: 1, + busy: false, - searchable: null, - checked: true, }); const IMAGE_DIM = 256; @@ -35,17 +36,17 @@ export function useProfile() { useEffect(() => { if (profile.state.identity.guid) { - const { node, name, handle, location, description, image } = profile.state.identity; + const { node, name, handle, location, description, image, imageUrl } = profile.state.identity; let url = !image ? null : profile.state.imageUrl; let editImage = !image ? avatar : url; - updateState({ init: true, name, location, description, node, handle, url, + updateState({ name, location, description, node, handle, url, editName: name, editLocation: location, editDescription: description, editHandle: handle, editImage }); } - }, [profile]); + }, [profile.state]); useEffect(() => { updateState({ display: viewport.state.display }); - }, [viewport]); + }, [viewport.state]); const actions = { logout: app.actions.logout, @@ -65,7 +66,7 @@ export function useProfile() { updateState({ editProfileDetails: false }); }, setEditImageCrop: (w, h, x, y) => { - updateState({ crop: { w, h, x, y }}); + updateState({ clip: { w, h, x, y }}); }, setEditName: (editName) => { updateState({ editName }); @@ -76,6 +77,12 @@ export function useProfile() { setEditDescription: (editDescription) => { updateState({ editDescription }); }, + setCrop: (crop) => { + updateState({ crop }); + }, + setZoom: (zoom) => { + updateState({ zoom }); + }, setProfileImage: async () => { if(!state.busy) { updateState({ busy: true }); @@ -89,7 +96,7 @@ export function useProfile() { canvas.width = IMAGE_DIM; canvas.height = IMAGE_DIM; context.imageSmoothingQuality = "medium"; - context.drawImage(img, state.crop.x, state.crop.y, state.crop.w, state.crop.h, + context.drawImage(img, state.clip.x, state.clip.y, state.clip.w, state.clip.h, 0, 0, IMAGE_DIM, IMAGE_DIM); resolve(canvas.toDataURL()); }