mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
preparing session screen
This commit is contained in:
parent
b57314b29a
commit
bdd7ecee5a
@ -12,6 +12,7 @@ import { ChannelContextProvider } from 'context/ChannelContext';
|
|||||||
import { StoreContextProvider } from 'context/StoreContext';
|
import { StoreContextProvider } from 'context/StoreContext';
|
||||||
import { UploadContextProvider } from 'context/UploadContext';
|
import { UploadContextProvider } from 'context/UploadContext';
|
||||||
import { ViewportContextProvider } from 'context/ViewportContext';
|
import { ViewportContextProvider } from 'context/ViewportContext';
|
||||||
|
import { ConversationContextProvider } from 'context/ConversationContext';
|
||||||
|
|
||||||
import { AppWrapper } from 'App.styled';
|
import { AppWrapper } from 'App.styled';
|
||||||
import { Root } from './root/Root';
|
import { Root } from './root/Root';
|
||||||
@ -36,10 +37,15 @@ function App() {
|
|||||||
<Router>
|
<Router>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={ <Root /> } />
|
<Route path="/" element={ <Root /> } />
|
||||||
|
<Route path="/admin" element={ <Admin /> } />
|
||||||
<Route path="/login" element={ <Access mode="login" /> } />
|
<Route path="/login" element={ <Access mode="login" /> } />
|
||||||
<Route path="/create" element={ <Access mode="create" /> } />
|
<Route path="/create" element={ <Access mode="create" /> } />
|
||||||
<Route path="/session" element={ <Session /> } />
|
<Route path="/session" element={
|
||||||
<Route path="/admin" element={ <Admin /> } />
|
<ConversationContextProvider>
|
||||||
|
<Session />
|
||||||
|
</ConversationContextProvider>
|
||||||
|
}>
|
||||||
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
</Router>
|
</Router>
|
||||||
</AppWrapper>
|
</AppWrapper>
|
||||||
|
@ -37,7 +37,7 @@ export function Access({ mode }) {
|
|||||||
{ (viewport.state.display === 'large' || viewport.state.display === 'xlarge') && (
|
{ (viewport.state.display === 'large' || viewport.state.display === 'xlarge') && (
|
||||||
<div class="split-layout">
|
<div class="split-layout">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
<img class="splash" src={login} alt={login} />
|
<img class="splash" src={login} alt="Databag Splash" />
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<Prompt />
|
<Prompt />
|
||||||
|
@ -1,5 +1,20 @@
|
|||||||
|
import { UserOutlined } from '@ant-design/icons';
|
||||||
|
import { AdminWrapper } from './Admin.styled';
|
||||||
|
import { useAdmin } from './useAdmin.hook';
|
||||||
|
|
||||||
export function Admin() {
|
export function Admin() {
|
||||||
return <></>
|
|
||||||
|
const { state, actions } = useAdmin();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminWrapper>
|
||||||
|
<div class="app-title">
|
||||||
|
<span>Databag</span>
|
||||||
|
<div class="user" onClick={() => actions.onUser()}>
|
||||||
|
<UserOutlined />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AdminWrapper>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
net/web/src/admin/Admin.styled.js
Normal file
31
net/web/src/admin/Admin.styled.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import styled from 'styled-components';
|
||||||
|
import Colors from 'constants/Colors';
|
||||||
|
|
||||||
|
export const AdminWrapper = styled.div`
|
||||||
|
max-width: 400px;
|
||||||
|
width: 90%;
|
||||||
|
height: 90%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.app-title {
|
||||||
|
font-size: 24px;
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: center;
|
||||||
|
flex: 1;
|
||||||
|
color: ${Colors.grey};
|
||||||
|
|
||||||
|
.user {
|
||||||
|
color: ${Colors.grey};
|
||||||
|
position: absolute;
|
||||||
|
top: 0px;
|
||||||
|
right: 0px;
|
||||||
|
font-size: 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
|
25
net/web/src/admin/useAdmin.hook.js
Normal file
25
net/web/src/admin/useAdmin.hook.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { useContext, useState } from 'react';
|
||||||
|
import { AppContext } from 'context/AppContext';
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
|
export function useAdmin() {
|
||||||
|
|
||||||
|
const [state, setState] = useState({
|
||||||
|
});
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const app = useContext(AppContext);
|
||||||
|
|
||||||
|
const updateState = (value) => {
|
||||||
|
setState((s) => ({ ...s, ...value }));
|
||||||
|
}
|
||||||
|
|
||||||
|
const actions = {
|
||||||
|
onUser: () => {
|
||||||
|
navigate('/login');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return { state, actions };
|
||||||
|
}
|
||||||
|
|
@ -89,7 +89,7 @@ export function useConversationContext() {
|
|||||||
members.add(conversation.guid);
|
members.add(conversation.guid);
|
||||||
}
|
}
|
||||||
for (let member of conversation.data.channelDetail.members) {
|
for (let member of conversation.data.channelDetail.members) {
|
||||||
if (profile.state.profile.guid != member) {
|
if (profile.state.profile.guid !== member) {
|
||||||
members.add(member);
|
members.add(member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ export function useConversationContext() {
|
|||||||
const setTopicDelta = async (delta, curView) => {
|
const setTopicDelta = async (delta, curView) => {
|
||||||
for (let topic of delta) {
|
for (let topic of delta) {
|
||||||
if (topic.data == null) {
|
if (topic.data == null) {
|
||||||
if (curView == view.current) {
|
if (curView === view.current) {
|
||||||
topics.current.delete(topic.id);
|
topics.current.delete(topic.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ export function useConversationContext() {
|
|||||||
if (cur == null) {
|
if (cur == null) {
|
||||||
cur = { id: topic.id, data: {} };
|
cur = { id: topic.id, data: {} };
|
||||||
}
|
}
|
||||||
if (topic.data.detailRevision != cur.data.detailRevision) {
|
if (topic.data.detailRevision !== cur.data.detailRevision) {
|
||||||
if(topic.data.topicDetail) {
|
if(topic.data.topicDetail) {
|
||||||
cur.data.topicDetail = topic.data.topicDetail;
|
cur.data.topicDetail = topic.data.topicDetail;
|
||||||
cur.data.detailRevision = topic.data.detailRevision;
|
cur.data.detailRevision = topic.data.detailRevision;
|
||||||
@ -153,7 +153,7 @@ export function useConversationContext() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur.revision = topic.revision;
|
cur.revision = topic.revision;
|
||||||
if (curView == view.current) {
|
if (curView === view.current) {
|
||||||
topics.current.set(topic.id, cur);
|
topics.current.set(topic.id, cur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ export function useConversationContext() {
|
|||||||
const setTopics = async (ev) => {
|
const setTopics = async (ev) => {
|
||||||
const curView = view.current;
|
const curView = view.current;
|
||||||
try {
|
try {
|
||||||
if (ev.type == EVENT_OPEN) {
|
if (ev.type === EVENT_OPEN) {
|
||||||
const { cardId, channelId } = ev.data;
|
const { cardId, channelId } = ev.data;
|
||||||
channelView.current.cardId = cardId;
|
channelView.current.cardId = cardId;
|
||||||
channelView.current.channelId = channelId;
|
channelView.current.channelId = channelId;
|
||||||
@ -175,7 +175,7 @@ export function useConversationContext() {
|
|||||||
channelView.current.revision = delta.revision;
|
channelView.current.revision = delta.revision;
|
||||||
channelView.current.begin = delta.marker;
|
channelView.current.begin = delta.marker;
|
||||||
}
|
}
|
||||||
else if (ev.type == EVENT_MORE) {
|
else if (ev.type === EVENT_MORE) {
|
||||||
if (channelView.current.init) {
|
if (channelView.current.init) {
|
||||||
channelView.current.batch += 1;
|
channelView.current.batch += 1;
|
||||||
let delta = await getTopicDelta(null, channelView.current.batch * TOPIC_BATCH, null, channelView.current.begin);
|
let delta = await getTopicDelta(null, channelView.current.batch * TOPIC_BATCH, null, channelView.current.begin);
|
||||||
@ -183,16 +183,16 @@ export function useConversationContext() {
|
|||||||
channelView.current.begin = delta.marker;
|
channelView.current.begin = delta.marker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ev.type == EVENT_UPDATE || ev.type == EVENT_RESYNC) {
|
else if (ev.type === EVENT_UPDATE || ev.type === EVENT_RESYNC) {
|
||||||
let deltaRevision = getChannelRevision();
|
let deltaRevision = getChannelRevision();
|
||||||
if (channelView.current.init && deltaRevision != channelView.current.revision) {
|
if (channelView.current.init && deltaRevision !== channelView.current.revision) {
|
||||||
let delta = await getTopicDelta(channelView.current.revision, null, channelView.current.begin, null);
|
let delta = await getTopicDelta(channelView.current.revision, null, channelView.current.begin, null);
|
||||||
await setTopicDelta(delta.topics, curView);
|
await setTopicDelta(delta.topics, curView);
|
||||||
channelView.current.revision = delta.revision;
|
channelView.current.revision = delta.revision;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curView == view.current) {
|
if (curView === view.current) {
|
||||||
let chan = getChannel();
|
let chan = getChannel();
|
||||||
let subject = getSubject(chan);
|
let subject = getSubject(chan);
|
||||||
let contacts = getContacts(chan);
|
let contacts = getContacts(chan);
|
||||||
@ -211,7 +211,7 @@ export function useConversationContext() {
|
|||||||
catch (err) {
|
catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
updateState({ error: true });
|
updateState({ error: true });
|
||||||
if (ev.type == EVENT_RESYNC) {
|
if (ev.type === EVENT_RESYNC) {
|
||||||
window.alert("failed to syncrhonize conversation");
|
window.alert("failed to syncrhonize conversation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,14 +222,14 @@ export function useConversationContext() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serialize.current == 0) {
|
if (serialize.current === 0) {
|
||||||
serialize.current++;
|
serialize.current++;
|
||||||
|
|
||||||
while (events.current.length > 0) {
|
while (events.current.length > 0) {
|
||||||
|
|
||||||
// collapse updates
|
// collapse updates
|
||||||
while (events.current.length > 1) {
|
while (events.current.length > 1) {
|
||||||
if(events.current[0].type == EVENT_UPDATE && events.current[1].type == EVENT_UPDATE) {
|
if(events.current[0].type === EVENT_UPDATE && events.current[1].type === EVENT_UPDATE) {
|
||||||
events.current.shift();
|
events.current.shift();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1,5 +1,42 @@
|
|||||||
|
import { useEffect, useContext } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { SessionWrapper } from './Session.styled';
|
||||||
|
import { Button } from 'antd';
|
||||||
|
import { AppContext } from 'context/AppContext';
|
||||||
|
import { ViewportContext } from 'context/ViewportContext';
|
||||||
|
|
||||||
export function Session() {
|
export function Session() {
|
||||||
return <></>
|
|
||||||
|
const app = useContext(AppContext);
|
||||||
|
const viewport = useContext(ViewportContext);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (app.state) {
|
||||||
|
if (!app.state.access) {
|
||||||
|
navigate('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [app, navigate]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SessionWrapper>
|
||||||
|
{ (viewport.state.display === 'xlarge') && (
|
||||||
|
<div class="desktop-layout">
|
||||||
|
<Button type="primary" onClick={app.actions.logout}>Logout</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{ (viewport.state.display === 'large' || viewport.state.display === 'medium') && (
|
||||||
|
<div class="tablet-layout">
|
||||||
|
<Button type="primary" onClick={app.actions.logout}>Logout</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{ (viewport.state.display === 'small') && (
|
||||||
|
<div class="mobile-layout">
|
||||||
|
<Button type="primary" onClick={app.actions.logout}>Logout</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</SessionWrapper>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
net/web/src/session/Session.styled.js
Normal file
15
net/web/src/session/Session.styled.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
export const SessionWrapper = styled.div`
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.desktop-layout {
|
||||||
|
}
|
||||||
|
|
||||||
|
.tablet-layout {
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-layout {
|
||||||
|
}
|
||||||
|
`;
|
Loading…
Reference in New Issue
Block a user