diff --git a/net/server/internal/api_addAccount.go b/net/server/internal/api_addAccount.go index a1e3b491..d86aefd9 100644 --- a/net/server/internal/api_addAccount.go +++ b/net/server/internal/api_addAccount.go @@ -114,7 +114,7 @@ func AddAccount(w http.ResponseWriter, r *http.Request) { Image: detail.Image, Revision: account.ProfileRevision, Version: APP_VERSION, - Node: "https://" + getStrConfigValue(CONFIG_DOMAIN, ""), + Node: getStrConfigValue(CONFIG_DOMAIN, ""), } // send response diff --git a/net/server/internal/api_getAccountListing.go b/net/server/internal/api_getAccountListing.go index bd7aa3c7..f54eaf8a 100644 --- a/net/server/internal/api_getAccountListing.go +++ b/net/server/internal/api_getAccountListing.go @@ -23,7 +23,7 @@ func GetAccountListing(w http.ResponseWriter, r *http.Request) { Location: account.AccountDetail.Location, ImageSet: account.AccountDetail.Image != "", Version: APP_VERSION, - Node: "https://" + getStrConfigValue(CONFIG_DOMAIN, "") + "/", + Node: getStrConfigValue(CONFIG_DOMAIN, ""), }) } diff --git a/net/server/internal/api_getOpenMessage.go b/net/server/internal/api_getOpenMessage.go index 737b531d..3c344687 100644 --- a/net/server/internal/api_getOpenMessage.go +++ b/net/server/internal/api_getOpenMessage.go @@ -50,7 +50,7 @@ func GetOpenMessage(w http.ResponseWriter, r *http.Request) { Location: detail.Location, Image: detail.Image, Version: APP_VERSION, - Node: "https://" + getStrConfigValue(CONFIG_DOMAIN, "") + "/", + Node: getStrConfigValue(CONFIG_DOMAIN, ""), } msg, err := WriteDataMessage(detail.PrivateKey, detail.PublicKey, detail.KeyType, diff --git a/net/server/internal/api_getProfileMessage.go b/net/server/internal/api_getProfileMessage.go index 2d0752f6..0f5e6a8e 100644 --- a/net/server/internal/api_getProfileMessage.go +++ b/net/server/internal/api_getProfileMessage.go @@ -40,7 +40,7 @@ func GetProfileMessage(w http.ResponseWriter, r *http.Request) { Location: detail.Location, Image: detail.Image, Version: APP_VERSION, - Node: "https://" + getStrConfigValue(CONFIG_DOMAIN, "") + "/", + Node: getStrConfigValue(CONFIG_DOMAIN, ""), } msg, res := WriteDataMessage(detail.PrivateKey, detail.PublicKey, detail.KeyType, APP_SIGNPKCS1V15, account.Guid, APP_MSGIDENTITY, &identity) diff --git a/net/server/internal/modelUtil.go b/net/server/internal/modelUtil.go index 4416cf38..850f32dd 100644 --- a/net/server/internal/modelUtil.go +++ b/net/server/internal/modelUtil.go @@ -14,7 +14,7 @@ func getProfileModel(account *store.Account) *Profile { Image: account.AccountDetail.Image, Revision: account.ProfileRevision, Version: APP_VERSION, - Node: "https://" + getStrConfigValue(CONFIG_DOMAIN, "") + "/", + Node: getStrConfigValue(CONFIG_DOMAIN, ""), } } diff --git a/net/server/internal/notify.go b/net/server/internal/notify.go index b4e399c1..2ef5a17b 100644 --- a/net/server/internal/notify.go +++ b/net/server/internal/notify.go @@ -28,7 +28,7 @@ func SendNotifications() { for { select { case notification := <-notify: - node := "https://" + getStrConfigValue(CONFIG_DOMAIN, "") + "/" + node := getStrConfigValue(CONFIG_DOMAIN, "") if notification.Node == node { SendLocalNotification(notification) } else { diff --git a/net/web/src/AppContext/fetchUtil.js b/net/web/src/AppContext/fetchUtil.js index dec3e30b..cee95ccf 100644 --- a/net/web/src/AppContext/fetchUtil.js +++ b/net/web/src/AppContext/fetchUtil.js @@ -44,6 +44,14 @@ export async function createAccount(username, password) { return await profile.json() } +export async function getProfile(token) { + let headers = new Headers() + headers.append('Authorization', 'Bearer ' + token); + let profile = await fetchWithTimeout('/profile', { method: 'GET', timeout: FETCH_TIMEOUT, headers: headers }); + checkResponse(profile) + return await profile.json() +} + export async function getGroups(token, revision) { let headers = new Headers() headers.append('Authorization', 'Bearer ' + token); diff --git a/net/web/src/AppContext/useAppContext.hook.js b/net/web/src/AppContext/useAppContext.hook.js index eca1ffd2..43ffc74f 100644 --- a/net/web/src/AppContext/useAppContext.hook.js +++ b/net/web/src/AppContext/useAppContext.hook.js @@ -1,11 +1,17 @@ import { useEffect, useState, useRef } from 'react'; -import { getGroups, getAvailable, getUsername, setLogin, createAccount } from './fetchUtil'; +import { getProfile, getGroups, getAvailable, getUsername, setLogin, createAccount } from './fetchUtil'; -async function updateGroups(token, revision, groupMap) { +async function updateProfile(token, updateData) { + let profile = await getProfile(token); + updateData({ profile: profile }) +} + +async function updateGroups(token, revision, groupMap, updateData) { let groups = await getGroups(token, revision); for (let group of groups) { groupMap.set(group.id, group); } + updateData({ groups: Array.from(groupMap.values()) }); } async function appCreate(username, password, updateState, setWebsocket) { @@ -33,8 +39,13 @@ function appLogout(updateState, clearWebsocket) { export function useAppContext() { const [state, setState] = useState(null); + const groupRevision = useRef(null); const groups = useRef(new Map()); + + const profileRevision = useRef(null); + const profile = useRef({}); + const ws = useRef(null); const revision = useRef(null); const updateState = (value) => { @@ -47,15 +58,25 @@ export function useAppContext() { }) } + const resetData = () => { + revision.current = null; + profile.current = {}; + profileRevision.current = null; + groups.current = new Map(); + groupRevision.current = null; + } + const userActions = { logout: () => { appLogout(updateState, clearWebsocket); + resetData(); } } const adminActions = { logout: () => { appLogout(updateState, clearWebsocket); + resetData(); } } @@ -76,11 +97,16 @@ export function useAppContext() { // update group if revision changed if (rev.group != groupRevision.current) { - await updateGroups(token, groupRevision.current, groups.current); - updateData({ groups: Array.from(groups.current.values()) }); + await updateGroups(token, groupRevision.current, groups.current, updateData); groupRevision.current = rev.group } + // update profile if revision changed + if (rev.profile != profileRevision.current) { + await updateProfile(token, updateData) + profileRevision.current = rev.profile + } + // check if new revision was received during processing if (rev == revision.current) { revision.current = null diff --git a/net/web/src/User/User.jsx b/net/web/src/User/User.jsx index ca200b3a..689a4573 100644 --- a/net/web/src/User/User.jsx +++ b/net/web/src/User/User.jsx @@ -1,11 +1,23 @@ import React from 'react' import { useUser } from './useUser.hook'; import { Button } from 'antd'; - +import { UserWrapper } from './User.styled'; +import connect from '../connect.png'; + + export function User() { const { state, actions } = useUser() - return + return ( + +
+ +
+
+ +
+
+ ) } diff --git a/net/web/src/User/User.styled.js b/net/web/src/User/User.styled.js new file mode 100644 index 00000000..4bc3fa1f --- /dev/null +++ b/net/web/src/User/User.styled.js @@ -0,0 +1,34 @@ +import { Input, Button, Spin } from 'antd'; +import styled from 'styled-components'; + +export const UserWrapper = styled.div` + display: flex; + flex-direction: row; + width: 100%; + height: 100%; + background-color: #f6f5ed; + + .listing { + width: 30%; + height: 100%; + max-width: 300px; + min-width: 200px; + border: 1px solid #8fbea7; + } + + .canvas { + display: flex; + flex-grow: 1; + height: 100%; + border: 1px solid #8fbea7; + align-items: center; + justify-content: center; + } + + .connect { + width: 33%; + height: 33%; + object-fit: contain; + } +`; + diff --git a/net/web/src/User/useUser.hook.js b/net/web/src/User/useUser.hook.js index c2dc086c..239de300 100644 --- a/net/web/src/User/useUser.hook.js +++ b/net/web/src/User/useUser.hook.js @@ -9,6 +9,8 @@ export function useUser() { const navigate = useNavigate(); const app = useContext(AppContext); +console.log(app); + const actions = { onLogout: async () => { app.actions.logout() diff --git a/net/web/src/connect.png b/net/web/src/connect.png new file mode 100644 index 00000000..ed6c4557 Binary files /dev/null and b/net/web/src/connect.png differ