From 5078538a4b63b4c89e6aa5da23e1db27da0750aa Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Sun, 22 Jan 2023 21:51:14 -0800 Subject: [PATCH] refactor profile & account components for webapp --- net/web/src/context/useAppContext.hook.js | 4 + net/web/src/session/Session.jsx | 2 +- net/web/src/session/account/Account.jsx | 16 +- .../session/{ => account}/profile/Profile.jsx | 139 ++++----- .../session/account/profile/Profile.styled.js | 207 +++++++++++++ .../profile}/accountAccess/AccountAccess.jsx | 0 .../accountAccess/AccountAccess.styled.js | 0 .../accountLogin/AccountLogin.jsx | 0 .../accountAccess/useAccountAccess.hook.js | 0 .../profile/profileDetails/ProfileDetails.jsx | 0 .../profileDetails/ProfileDetails.styled.js | 0 .../profile/profileImage/ProfileImage.jsx | 0 .../profileImage/ProfileImage.styled.js | 0 .../{ => account}/profile/useProfile.hook.js | 0 net/web/src/session/profile/Profile.styled.js | 282 ------------------ 15 files changed, 285 insertions(+), 365 deletions(-) rename net/web/src/session/{ => account}/profile/Profile.jsx (55%) create mode 100644 net/web/src/session/account/profile/Profile.styled.js rename net/web/src/session/{ => account/profile}/accountAccess/AccountAccess.jsx (100%) rename net/web/src/session/{ => account/profile}/accountAccess/AccountAccess.styled.js (100%) rename net/web/src/session/{ => account/profile}/accountAccess/accountLogin/AccountLogin.jsx (100%) rename net/web/src/session/{ => account/profile}/accountAccess/useAccountAccess.hook.js (100%) rename net/web/src/session/{ => account}/profile/profileDetails/ProfileDetails.jsx (100%) rename net/web/src/session/{ => account}/profile/profileDetails/ProfileDetails.styled.js (100%) rename net/web/src/session/{ => account}/profile/profileImage/ProfileImage.jsx (100%) rename net/web/src/session/{ => account}/profile/profileImage/ProfileImage.styled.js (100%) rename net/web/src/session/{ => account}/profile/useProfile.hook.js (100%) delete mode 100644 net/web/src/session/profile/Profile.styled.js diff --git a/net/web/src/context/useAppContext.hook.js b/net/web/src/context/useAppContext.hook.js index 17991f25..f446dbfe 100644 --- a/net/web/src/context/useAppContext.hook.js +++ b/net/web/src/context/useAppContext.hook.js @@ -37,6 +37,10 @@ export function useAppContext(websocket) { const channelContext = useContext(ChannelContext); const cardContext = useContext(CardContext); + useEffect(() => { + console.log(state.status); + }, [state.status]); + const setSession = (token) => { try { accountContext.actions.setToken(token); diff --git a/net/web/src/session/Session.jsx b/net/web/src/session/Session.jsx index 9afa79cd..4059671e 100644 --- a/net/web/src/session/Session.jsx +++ b/net/web/src/session/Session.jsx @@ -7,7 +7,7 @@ import { Identity } from './identity/Identity'; import { Channels } from './channels/Channels'; import { Cards } from './cards/Cards'; import { Contact } from './contact/Contact'; -import { Profile } from './profile/Profile'; +import { Profile } from './account/profile/Profile'; import { Listing } from './listing/Listing'; import { Account } from './account/Account'; import { Welcome } from './welcome/Welcome'; diff --git a/net/web/src/session/account/Account.jsx b/net/web/src/session/account/Account.jsx index d8d6e76e..7e1ecc88 100644 --- a/net/web/src/session/account/Account.jsx +++ b/net/web/src/session/account/Account.jsx @@ -1,24 +1,24 @@ import { AccountWrapper } from './Account.styled'; import { DoubleRightOutlined } from '@ant-design/icons'; import { SettingOutlined } from '@ant-design/icons'; -import { AccountAccess } from '../accountAccess/AccountAccess'; +import { AccountAccess } from './profile/accountAccess/AccountAccess'; export function Account({ closeAccount, openProfile }) { return ( -
-
Account
-
+
+
Account
+
-
+
-
- diff --git a/net/web/src/session/profile/Profile.jsx b/net/web/src/session/account/profile/Profile.jsx similarity index 55% rename from net/web/src/session/profile/Profile.jsx rename to net/web/src/session/account/profile/Profile.jsx index 6510a7d9..e82cc72d 100644 --- a/net/web/src/session/profile/Profile.jsx +++ b/net/web/src/session/account/profile/Profile.jsx @@ -1,15 +1,16 @@ import { useRef } from 'react'; -import { Modal, Button } from 'antd'; +import { Space, Modal, Button } from 'antd'; import { ProfileWrapper, 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 { AccountAccess } from './accountAccess/AccountAccess'; import { LogoutOutlined, RightOutlined, EditOutlined, BookOutlined, EnvironmentOutlined } from '@ant-design/icons'; export function Profile({ closeProfile }) { + const [ modal, modalContext ] = Modal.useModal(); const { state, actions } = useProfile(); const imageFile = useRef(null); @@ -28,7 +29,7 @@ export function Profile({ closeProfile }) { } catch(err) { console.log(err); - Modal.error({ + modal.error({ title: 'Failed to Save', content: 'Please try again.', }); @@ -42,7 +43,7 @@ export function Profile({ closeProfile }) { } catch(err) { console.log(err); - Modal.error({ + modal.error({ title: 'Failed to Save', content: 'Please try again.', }); @@ -50,7 +51,7 @@ export function Profile({ closeProfile }) { } const logout = () => { - Modal.confirm({ + modal.confirm({ title: 'Are you sure you want to logout?', icon: , onOk() { @@ -60,54 +61,11 @@ export function Profile({ closeProfile }) { }); } - const Image = ( - - ); - - const Details = ( -
-
- { state.name && ( -
{ state.name }
- )} - { !state.name && ( -
name
- )} -
- -
-
-
- - { state.location && ( -
{ state.location }
- )} - { !state.location && ( -
location
- )} -
-
- - { state.description && ( -
{ state.description }
- )} - { !state.description && ( -
description
- )} -
-
- ); - const editImageFooter = ( selected(e)} style={{display: 'none'}}/> -
- +
+
@@ -116,7 +74,7 @@ export function Profile({ closeProfile }) { const editDetailsFooter = ( -
+
@@ -124,36 +82,69 @@ export function Profile({ closeProfile }) { return ( - { state.init && state.display === 'xlarge' && ( - <> -
-
{ state.handle }
-
- + { modalContext } + { state.display === 'xlarge' && ( +
+
{ state.handle }
+
+ +
+
+ )} + { state.display !== 'xlarge' && ( +
+
{ state.handle }
+
Profile Settings
+
+ )} +
+
+ +
+ +
+
+
+
+ { state.name && ( +
{ state.name }
+ )} + { !state.name && ( +
name
+ )} +
+
- -
- { Image } - { Details } +
+ + { state.location && ( +
{ state.location }
+ )} + { !state.location && ( +
location
+ )}
- - )} +
+ + { state.description && ( +
{ state.description }
+ )} + { !state.description && ( +
description
+ )} +
+
+
{ state.init && state.display !== 'xlarge' && ( -
-
{ state.handle }
-
Profile Settings
-
- { Image } - { Details } -
-
Account Settings
-
+
+
Account Settings
+
{ state.display === 'small' && ( -
+
-
Logout
+
Logout
)}
diff --git a/net/web/src/session/account/profile/Profile.styled.js b/net/web/src/session/account/profile/Profile.styled.js new file mode 100644 index 00000000..2a4d80a6 --- /dev/null +++ b/net/web/src/session/account/profile/Profile.styled.js @@ -0,0 +1,207 @@ +import styled from 'styled-components'; +import Colors from 'constants/Colors'; + +export const ProfileWrapper = styled.div` + height: 100%; + width: 100%; + display: flex; + flex-direction: column; + background-color: ${Colors.profileForm}; + + .middleHeader { + margin-left: 16px; + margin-right: 16px; + height: 48px; + border-bottom: 1px solid ${Colors.profileDivider}; + display: flex; + flex-direction: row; + align-items: center; + flex-shrink: 0; + + .handle { + font-size: 20px; + font-weight: bold; + flex-grow: 1; + padding-left: 16px; + } + + .close { + font-size: 16px; + color: ${Colors.primary}; + cursor: pointer; + padding-right: 16px; + } + } + + .rightHeader { + width: 100%; + display: flex; + flex-direction: column; + align-items: center; + + .title { + font-size: 18px; + font-weight: bold; + } + } + + .section { + width: 100%; + color: ${Colors.grey}; + padding-top: 24px; + font-size: 12px; + display: flex; + widtH: 75%; + justify-content: center; + border-bottom: 1px solid ${Colors.divider}; + } + + .logo { + position: relative; + width: 20vw; + cursor: pointer; + margin-left: 32px; + margin-right: 32px; + + &:hover .edit { + opacity: 1; + } + + .edit { + position: absolute; + display: flex; + align-items: center; + justify-content: center; + border-top-left-radius: 4px; + border-bottom-right-radius: 4px; + width: 24px; + height: 24px; + bottom: 0; + right: 0; + color: ${Colors.link}; + background-color: ${Colors.white}; + opacity: 0.7; + } + } + + .midContent { + min-height: 0; + width: 100%; + overflow: auto; + display: flex; + flex-direction: row; + justify-content: center; + padding-top: 32px; + } + + .rightContent { + min-height: 0; + width: 100%; + overflow: auto; + display: flex; + flex-direction: column; + align-items: center; + border-radius: 4px; + padding: 8px; + } + + .details { + display: flex; + flex-direction: column; + + .notset { + font-style: italic; + color: ${Colors.grey}; + } + + .name { + display: flex; + flex-direction: row; + align-items: center; + cursor: pointer; + + &:hover .icon { + border: 1px solid ${Colors.grey}; + background-color: ${Colors.white}; + } + + .icon { + padding-left: 4px; + padding-right: 4px; + border: 1px solid ${Colors.profileForm}; + border-raidus: 4px; + } + + .data { + padding-right: 4px; + font-size: 24px; + font-weight: bold; + } + } + + .location { + display: flex; + flex-direction: row; + align-items: center; + padding-bottom: 8px; + + .data { + padding-left: 8px; + } + } + + .description { + display: flex; + flex-direction: row; + align-items: center; + padding-bottom: 8px; + + .data { + padding-left: 8px; + } + } + } + + .account { + display: flex; + flex-direction: column; + align-items: center; + } + + .controls { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + border-top: 1px solid ${Colors.divider}; + border-radius: 4px; + padding: 8px; + width: 75%; + } + + .logout { + display: flex; + flex-direction: row; + align-items: center; + cursor: pointer; + color: ${Colors.white}; + background-color: ${Colors.primary}; + margin-top: 8px; + padding: 8px; + border-radius: 4px; + + .label { + padding-left: 8px; + } + } +` +export const EditFooter = styled.div` + width: 100%; + display: flex; + + .select { + display: flex; + flex-grow: 1; + } +` + diff --git a/net/web/src/session/accountAccess/AccountAccess.jsx b/net/web/src/session/account/profile/accountAccess/AccountAccess.jsx similarity index 100% rename from net/web/src/session/accountAccess/AccountAccess.jsx rename to net/web/src/session/account/profile/accountAccess/AccountAccess.jsx diff --git a/net/web/src/session/accountAccess/AccountAccess.styled.js b/net/web/src/session/account/profile/accountAccess/AccountAccess.styled.js similarity index 100% rename from net/web/src/session/accountAccess/AccountAccess.styled.js rename to net/web/src/session/account/profile/accountAccess/AccountAccess.styled.js diff --git a/net/web/src/session/accountAccess/accountLogin/AccountLogin.jsx b/net/web/src/session/account/profile/accountAccess/accountLogin/AccountLogin.jsx similarity index 100% rename from net/web/src/session/accountAccess/accountLogin/AccountLogin.jsx rename to net/web/src/session/account/profile/accountAccess/accountLogin/AccountLogin.jsx diff --git a/net/web/src/session/accountAccess/useAccountAccess.hook.js b/net/web/src/session/account/profile/accountAccess/useAccountAccess.hook.js similarity index 100% rename from net/web/src/session/accountAccess/useAccountAccess.hook.js rename to net/web/src/session/account/profile/accountAccess/useAccountAccess.hook.js diff --git a/net/web/src/session/profile/profileDetails/ProfileDetails.jsx b/net/web/src/session/account/profile/profileDetails/ProfileDetails.jsx similarity index 100% rename from net/web/src/session/profile/profileDetails/ProfileDetails.jsx rename to net/web/src/session/account/profile/profileDetails/ProfileDetails.jsx diff --git a/net/web/src/session/profile/profileDetails/ProfileDetails.styled.js b/net/web/src/session/account/profile/profileDetails/ProfileDetails.styled.js similarity index 100% rename from net/web/src/session/profile/profileDetails/ProfileDetails.styled.js rename to net/web/src/session/account/profile/profileDetails/ProfileDetails.styled.js diff --git a/net/web/src/session/profile/profileImage/ProfileImage.jsx b/net/web/src/session/account/profile/profileImage/ProfileImage.jsx similarity index 100% rename from net/web/src/session/profile/profileImage/ProfileImage.jsx rename to net/web/src/session/account/profile/profileImage/ProfileImage.jsx diff --git a/net/web/src/session/profile/profileImage/ProfileImage.styled.js b/net/web/src/session/account/profile/profileImage/ProfileImage.styled.js similarity index 100% rename from net/web/src/session/profile/profileImage/ProfileImage.styled.js rename to net/web/src/session/account/profile/profileImage/ProfileImage.styled.js diff --git a/net/web/src/session/profile/useProfile.hook.js b/net/web/src/session/account/profile/useProfile.hook.js similarity index 100% rename from net/web/src/session/profile/useProfile.hook.js rename to net/web/src/session/account/profile/useProfile.hook.js diff --git a/net/web/src/session/profile/Profile.styled.js b/net/web/src/session/profile/Profile.styled.js deleted file mode 100644 index 918e6241..00000000 --- a/net/web/src/session/profile/Profile.styled.js +++ /dev/null @@ -1,282 +0,0 @@ -import styled from 'styled-components'; -import Colors from 'constants/Colors'; - -export const ProfileWrapper = styled.div` - height: 100%; - width: 100%; - display: flex; - flex-direction: column; - background-color: ${Colors.profileForm}; - - .header { - margin-left: 16px; - margin-right: 16px; - height: 48px; - border-bottom: 1px solid ${Colors.profileDivider}; - display: flex; - flex-direction: row; - align-items: center; - flex-shrink: 0; - - .handle { - font-size: 20px; - font-weight: bold; - flex-grow: 1; - padding-left: 16px; - } - - .close { - font-size: 16px; - color: ${Colors.primary}; - cursor: pointer; - padding-right: 16px; - } - } - - .content { - min-height: 0; - width: 100%; - overflow: auto; - display: flex; - flex-direction: row; - justify-content: center; - padding-top: 32px; - - .logo { - position: relative; - width: 20vw; - margin-right: 32px; - cursor: pointer; - - &:hover .edit { - opacity: 1; - } - - .edit { - position: absolute; - display: flex; - align-items: center; - justify-content: center; - border-top-left-radius: 4px; - border-bottom-right-radius: 4px; - width: 24px; - height: 24px; - bottom: 0; - right: 0; - color: ${Colors.link}; - background-color: ${Colors.white}; - opacity: 0.7; - } - } - - .details { - display: flex; - flex-direction: column; - - .notset { - font-style: italic; - color: ${Colors.grey}; - } - - .name { - display: flex; - flex-direction: row; - align-items: center; - cursor: pointer; - - &:hover .icon { - border: 1px solid ${Colors.grey}; - background-color: ${Colors.white}; - } - - .icon { - padding-left: 4px; - padding-right: 4px; - border: 1px solid ${Colors.profileForm}; - border-raidus: 4px; - } - - .data { - padding-right: 4px; - font-size: 24px; - font-weight: bold; - } - } - - .location { - display: flex; - flex-direction: row; - align-items: center; - padding-bottom: 8px; - - .data { - padding-left: 8px; - } - } - - .description { - display: flex; - flex-direction: row; - align-items: center; - padding-bottom: 8px; - - .data { - padding-left: 8px; - } - } - } - } - - .view { - width: 100%; - height: 100%; - overflow: auto; - display: flex; - flex-direction: column; - align-items: center; - - .title { - font-size: 18px; - font-weight: bold; - } - - .logo { - position: relative; - width: 60%; - margin-bottom: 16px; - cursor: pointer; - - &:hover .edit { - opacity: 1; - } - - .edit { - position: absolute; - display: flex; - align-items: center; - justify-content: center; - border-top-left-radius: 4px; - border-bottom-right-radius: 4px; - width: 24px; - height: 24px; - bottom: 0; - right: 0; - color: ${Colors.link}; - background-color: ${Colors.white}; - opacity: 0.7; - } - } - - .details { - display: flex; - flex-direction: column; - align-items: center; - - .name { - display: flex; - flex-direction: row; - align-items: center; - cursor: pointer; - - &:hover .icon { - border: 1px solid ${Colors.grey}; - background-color: ${Colors.white}; - } - - .icon { - padding-left: 4px; - padding-right: 4px; - border: 1px solid ${Colors.profileForm}; - border-radius: 4px; - } - - .data { - padding-right: 4px; - font-size: 24px; - font-weight: bold; - } - } - - .location { - display: flex; - flex-direction: row; - align-items: center; - padding-bottom: 8px; - - .data { - padding-left: 8px; - } - } - - .description { - display: flex; - flex-direction: row; - align-items: center; - padding-bottom: 8px; - - .data { - padding-left: 8px; - } - } - } - - .section { - width: 100%; - color: ${Colors.grey}; - padding-top: 24px; - font-size: 12px; - display: flex; - justify-content: center; - } - - .controls { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - border-top: 1px solid ${Colors.divider}; - border-radius: 4px; - padding: 8px; - width: 75%; - } - - .link { - display: flex; - flex-direction: row; - align-items: center; - cursor: pointer; - color: ${Colors.primary}; - padding-top: 8px; - - .label { - padding-left: 8px; - } - } - - .logout { - display: flex; - flex-direction: row; - align-items: center; - cursor: pointer; - color: ${Colors.white}; - background-color: ${Colors.primary}; - margin-top: 8px; - padding: 8px; - border-radius: 4px; - - .label { - padding-left: 8px; - } - } - } -` -export const EditFooter = styled.div` - width: 100%; - display: flex; - - .select { - display: flex; - flex-grow: 1; - } -` -