preparing to render profile

This commit is contained in:
Roland Osborne 2022-03-17 14:42:51 -07:00
parent 037e5ebb71
commit 68c6acaf64
12 changed files with 94 additions and 12 deletions

View File

@ -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

View File

@ -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, ""),
})
}

View File

@ -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,

View File

@ -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)

View File

@ -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, ""),
}
}

View File

@ -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 {

View File

@ -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);

View File

@ -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

View File

@ -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 <Button type="primary" onClick={() => actions.onLogout()} style={{ alignSelf: 'center', marginTop: '16px', width: '33%' }}>Sign Out</Button>
return (
<UserWrapper>
<div class="listing">
<Button type="primary" onClick={() => actions.onLogout()} style={{ alignSelf: 'center', marginTop: '16px', width: '33%' }}>Sign Out</Button>
</div>
<div class="canvas">
<img class="connect" src={connect} alt="" />
</div>
</UserWrapper>
)
}

View File

@ -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;
}
`;

View File

@ -9,6 +9,8 @@ export function useUser() {
const navigate = useNavigate();
const app = useContext(AppContext);
console.log(app);
const actions = {
onLogout: async () => {
app.actions.logout()

BIN
net/web/src/connect.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB