Skip to content

Commit

Permalink
Fixed this time
Browse files Browse the repository at this point in the history
  • Loading branch information
Raduc4 committed Sep 18, 2023
1 parent 5d52359 commit 3710d0f
Show file tree
Hide file tree
Showing 24 changed files with 413 additions and 3,011 deletions.
2,178 changes: 66 additions & 2,112 deletions Cargo.lock

Large diffs are not rendered by default.

287 changes: 163 additions & 124 deletions components/common/Layout/Layout.tsx

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions components/ui/AddServer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useRegister_c2s } from '@framework/c2s';
import { State } from 'framework/redux/store';
import { RootState } from 'framework/redux/store';
import { Dispatch, SetStateAction, useState } from 'react';
import { useSelector } from 'react-redux';

Expand All @@ -11,9 +11,11 @@ export default function AddServerModal({
onClose: Dispatch<SetStateAction<boolean>>;
}) {
onCloseNavbar(false);
const { uuid } = useSelector((state: State) => state.uuid);

const register = useRegister_c2s();

const { uuid } = useSelector((state: RootState) => state.uuid);

const [fullName, setFullName] = useState('');
const [username, setUsername] = useState('');
const [proposedPassword, setProposedPassword] = useState('');
Expand Down Expand Up @@ -42,9 +44,9 @@ export default function AddServerModal({
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"
/>
</svg>
Expand Down
54 changes: 44 additions & 10 deletions components/ui/workspacesBar/WorkspaceBar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { RootState, useAppSelector } from 'framework/redux/store';
import React, { Dispatch, SetStateAction } from 'react';
import {
RootState,
useAppDispatch,
useAppSelector,
} from 'framework/redux/store';
import Link from 'next/link';
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { setCurrentServer } from 'framework/redux/slices/streamHandler.slice';
import clsx from 'clsx';

function WorkspaceBar({
onOpen,
}: {
onOpen: Dispatch<SetStateAction<boolean>>;
}) {
const sessions = useAppSelector((state: RootState) => state.context.sessions);
const sessions = useAppSelector(
(state: RootState) => state.context.sessions.current_sessions
);

const currentSessionInUse = useAppSelector(
(state) => state.context.sessions.current_used_session_server
);

const dispatch = useAppDispatch();

return (
<div
Expand All @@ -20,14 +35,33 @@ function WorkspaceBar({
>
<span className="text-xl font-medium leading-none text-white">+</span>
</span>
{sessions.map((el, i) => {
{Object.keys(sessions).map((key, i) => {
console.log(key);
return (
<img
key={i}
className="inline-block h-12 w-12 rounded-full"
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
alt=""
/>
<div
key={key}
className={clsx(
currentSessionInUse === key && 'bg-slate-300',
'rounded'
)}
>
<Link
key={key}
href={{
pathname: `/server/findPeers/${key}`,
}}
onClick={() => {
dispatch(setCurrentServer(key));
}}
>
<img
key={i}
className="inline-block h-12 w-12 rounded-full"
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
alt=""
/>
</Link>
</div>
);
})}
</div>
Expand Down
1 change: 1 addition & 0 deletions framework/app/c2s/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as connect_c2s } from './useConnect_c2s';
export { default as useRegister_c2s } from './useRegister_c2s';
export { default as useDisconnect_c2s } from './useDisconnect_c2s';
export { default as useGetAccountInfo_c2s } from './useGetAccountInfo_c2s';
44 changes: 44 additions & 0 deletions framework/app/c2s/useGetAccountInfo_c2s.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { MutationHook } from '@common/types/hooks';
import { useRegister_c2s } from '@common/c2s';
import { UseRegister } from '@common/c2s/useRegister_c2s';
import store from 'framework/redux/store';
import { addToContext } from 'framework/redux/slices/streamHandler.slice';
import { invoke } from '@tauri-apps/api/tauri';
export default useRegister_c2s as UseRegister<typeof handler>;

export type UseGetAccountInfoHookDescriptor = {
invokerInput: {
uuid: string;
cid?: string;
};
dataReturn: any;
};

export const handler: MutationHook<UseGetAccountInfoHookDescriptor> = {
//// Invoker input is connect because connect_after_register is true in register command
invokerOptions: {
type: 'getAccInfo',
},
invoker: async (context) => {
let { invoke, input, options } = context;

const { data } = await invoke(options.type, input);

return data;
},
useHook:
({ invoke }) =>
() => {
return async (input) => {
const response = await invoke(input);
store.dispatch(
addToContext({
req_id: response,
context_type: 'getAccInfo',
})
);

return response;
};
},
};
3 changes: 2 additions & 1 deletion framework/app/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { handler as useDisconnect_c2s } from './c2s/useDisconnect_c2s';
import { handler as useConnect_c2s } from './c2s/useConnect_c2s';
import { handler as useRegister_c2s } from './c2s/useRegister_c2s';
import { handler as useMessage } from './messaging/useMessage';

import { handler as useGetAccountInfo_c2s } from './c2s/useGetAccountInfo_c2s';
export const appHooks = {
c2s: {
useRegister: useRegister_c2s,
useConnect: useConnect_c2s,
useDisconnect: useDisconnect_c2s,
useGetAccountInfo: useGetAccountInfo_c2s,
},
useMessage,
};
1 change: 1 addition & 0 deletions framework/app/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ApiHooks {
useRegister: MutationHook;
useConnect: MutationHook;
useDisconnect: MutationHook;
useGetAccountInfo: MutationHook;
};
useMessage: MutationHook;
}
12 changes: 12 additions & 0 deletions framework/common/c2s/useGetAccountInfo_c2s.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MutationHook } from '@common/types/hooks';
import { useHook, useMutationHook } from '@common/utils/useHook';

export type UseGetAccountinfo<H extends MutationHook = MutationHook<any>> =
ReturnType<H['useHook']>;

const useRegister_c2s: UseGetAccountinfo = () => {
const hook = useHook((hooks) => hooks.c2s.useGetAccountInfo);
return useMutationHook({ ...hook })();
};

export default useRegister_c2s;
3 changes: 2 additions & 1 deletion framework/common/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export type ApiInvokeTypes =
| 'register'
| 'connect'
| 'disconnect'
| 'getSession';
| 'getSession'
| 'getAccInfo';
export interface ApiConfig {
invoker: ApiInvoker;
}
Expand Down
39 changes: 29 additions & 10 deletions framework/redux/slices/streamHandler.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ import { createSlice, current } from '@reduxjs/toolkit';

type Data = ServiceRegisterAccepted | ServiceTCPConnectionAccepted;

type Sessions = {
current_used_session_server: string;
current_sessions: {
[key: string]: { [key: string]: string };
};
};
export type ContextType = 'Register' | 'GetSession';

const initialState: {
context: {
[key: string]: ContextType;
};
sessions: Array<number | string>;
} = { context: {}, sessions: [] };
sessions: Sessions;
} = {
context: {},
sessions: {
current_used_session_server: '',
current_sessions: {},
},
};

const streamExecSlice = createSlice({
name: 'stram_handler',
Expand Down Expand Up @@ -43,20 +55,27 @@ const streamExecSlice = createSlice({
console.log('After', current(state));
},
setSessions: (state, action) => {
const activeSessions: Array<any> = action.payload;

const inactiveSession = state.sessions.filter((item) => {
return !activeSessions.includes(item);
});
const activeSessions: Array<{
cid: string;
peer_connections: {};
}> = action.payload;

state.sessions = activeSessions;
console.log('Before', activeSessions);
for (const session of activeSessions) {
const cid = session.cid;
const peer_connections = session.peer_connections;
state.sessions.current_sessions[cid] = peer_connections;
}

console.log('inactiveSession', inactiveSession);
console.log('active sessions', activeSessions);
console.log('Current state', current(state));
},
setCurrentServer: (state, action) => {
state.sessions.current_used_session_server = action.payload;
},
},
});

const { reducer, actions } = streamExecSlice;
export const { addToContext, setSessions } = actions;
export const { addToContext, setSessions, setCurrentServer } = actions;
export default reducer;
14 changes: 14 additions & 0 deletions pages/server/[serverCid].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Layout } from '@components/common/Layout';

const Server = () => {
return (
<div className="text-4xl text-teal-50 text-center mb-[50%] select-none">
<h1>Welcome to the Citadel Server</h1>
<h2>Click on Discussions to enter the chat</h2>
</div>
);
};

export default Server;

Server.Layout = Layout;
14 changes: 14 additions & 0 deletions pages/server/findPeers/[findPeersServerCid].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Layout } from '@components/common/Layout';

const FindPeers = () => {
return (
<div className="text-4xl text-teal-50 text-center mb-[50%] select-none">
<h1>Welcome to the Citadel Server</h1>
<h2>Find Peers</h2>
</div>
);
};

export default FindPeers;

FindPeers.Layout = Layout;
14 changes: 14 additions & 0 deletions pages/server/storage/[index].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Layout } from '@components/common/Layout';

const Storage = () => {
return (
<div className="text-4xl text-teal-50 text-center mb-[50%] select-none">
<h1>Welcome to the Citadel Server</h1>
<h2>Storage</h2>
</div>
);
};

export default Storage;

Storage.Layout = Layout;
12 changes: 0 additions & 12 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ license = "MIT/Apache-2.0"
repository = "https://github.com/Avarok-Cybersecurity/citadel-workspace"
edition = "2021"

[workspace]
members = [
"prisma-cli"
]

[workspace.dependencies]
prisma-cli = { path = "./prisma-cli"}

[build-dependencies]
tauri-build = { version = "1.3", features = [] }

Expand All @@ -33,10 +25,6 @@ tokio-util = { version = "0.7.8", default-features = false }
citadel_logging = { version = "0.5.0", default-features = false }
tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
log = "^0.4"
specta = {version = "=2.0.0-rc.1", features = ["functions"] }
prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", tag="0.6.9", default-features=false, features = ["sqlite-create-many", "migrations", "sqlite", "specta"] }
tauri-specta = { git = "https://github.com/oscartbeaumont/tauri-specta", branch = "v2", default-features = false, features = ["typescript"] }
rspc = { version = "0.1.2" }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
7 changes: 0 additions & 7 deletions src-tauri/prisma-cli/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/prisma-cli/src/main.rs

This file was deleted.

Binary file removed src-tauri/prisma/dev.db
Binary file not shown.
Binary file removed src-tauri/prisma/dev.db-journal
Binary file not shown.

This file was deleted.

3 changes: 0 additions & 3 deletions src-tauri/prisma/migrations/migration_lock.toml

This file was deleted.

18 changes: 0 additions & 18 deletions src-tauri/prisma/schema.prisma

This file was deleted.

Loading

0 comments on commit 3710d0f

Please sign in to comment.