Skip to content

Commit

Permalink
Correct peer representation
Browse files Browse the repository at this point in the history
  • Loading branch information
Raduc4 committed Aug 30, 2023
1 parent dc5cb78 commit 8c30ea8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 59 deletions.
102 changes: 61 additions & 41 deletions components/common/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export const Layout = ({ children }: Props) => {
const current_sessions = useAppSelector(
(state) => state.context.sessions.current_sessions
);
const current_server_cid = useAppSelector(
(state) => state.context.sessions.current_used_session_server
);

console.log(current_sessions);

const peers = Object.keys(current_sessions[current_server_cid] ?? {}).length;

return (
<ApiProvider>
Expand Down Expand Up @@ -159,29 +166,33 @@ export const Layout = ({ children }: Props) => {
Your Peers
</div>
<ul role="list" className="-mx-2 mt-2 space-y-1">
{Object.keys(current_sessions).map((key) => (
<li key={key}>
<a
href={`/server/${currentUsedSessionCid}/${current_sessions[key]}`}
className={classNames(
key
? 'bg-gray-800 text-white'
: 'text-gray-400 hover:text-white hover:bg-gray-800',
'group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold'
)}
>
<span className="relative inline-block">
<img
className="h-6 w-6 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=""
/>
<span className="absolute bottom-0 right-0 block h-1.5 w-1.5 rounded-full bg-gray-300 ring-2 ring-white" />
</span>
<span className="truncate">{key}</span>
</a>
</li>
))}
{peers === 0 ? (
<></>
) : (
Object.keys(current_sessions).map((key) => (
<li key={key}>
<a
href={`/server/${currentUsedSessionCid}/${current_sessions[key]}`}
className={classNames(
key
? 'bg-gray-800 text-white'
: 'text-gray-400 hover:text-white hover:bg-gray-800',
'group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold'
)}
>
<span className="relative inline-block">
<img
className="h-6 w-6 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=""
/>
<span className="absolute bottom-0 right-0 block h-1.5 w-1.5 rounded-full bg-gray-300 ring-2 ring-white" />
</span>
<span className="truncate">{key}</span>
</a>
</li>
))
)}
</ul>
</li>
<li>
Expand Down Expand Up @@ -292,24 +303,33 @@ export const Layout = ({ children }: Props) => {
Your Peers
</div>
<ul role="list" className="-mx-2 mt-2 space-y-1">
{Object.keys(current_sessions).map((key) => (
<li key={key}>
<Link
href={`/server/${currentUsedSessionCid}/${current_sessions[key]}`}
className={classNames(
key
? 'bg-gray-800 text-white'
: 'text-gray-400 hover:text-white hover:bg-gray-800',
'group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold'
)}
>
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-lg border border-gray-700 bg-gray-800 text-[0.625rem] font-medium text-gray-400 group-hover:text-white">
{key[0]}
</span>
<span className="truncate">{key}</span>
</Link>
</li>
))}
{peers === 0 ? (
<></>
) : (
Object.keys(current_sessions).map((key) => (
<li key={key}>
<a
href={`/server/${currentUsedSessionCid}/${current_sessions[key]}`}
className={classNames(
key
? 'bg-gray-800 text-white'
: 'text-gray-400 hover:text-white hover:bg-gray-800',
'group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold'
)}
>
<span className="relative inline-block">
<img
className="h-6 w-6 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=""
/>
<span className="absolute bottom-0 right-0 block h-1.5 w-1.5 rounded-full bg-gray-300 ring-2 ring-white" />
</span>
<span className="truncate">{key}</span>
</a>
</li>
))
)}
</ul>
</li>
{/* {sec type} */}
Expand Down
20 changes: 6 additions & 14 deletions components/ui/workspacesBar/WorkspaceBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import Link from 'next/link';
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { setCurrentServer } from 'framework/redux/slices/streamHandler.slice';

function WorkspaceBar({
onOpen,
}: {
Expand All @@ -16,16 +17,6 @@ function WorkspaceBar({
);

const dispatch = useAppDispatch();
const [sessionsArr, setSessions] = useState<Array<any>>([]);

useEffect(() => {
for (const session in sessions) {
setSessions((prev) => {
if (prev.includes(session)) return prev; // if session already exists, don't add it
return [...prev, session];
});
}
}, [sessions]);

return (
<div
Expand All @@ -40,14 +31,15 @@ function WorkspaceBar({
<span className="text-xl font-medium leading-none text-white">+</span>
</span>
{Object.keys(sessions).map((key, i) => {
const el = sessions[key];
return (
<Link
key={el.cid}
key={key}
href={{
pathname: `/server/${el}`,
pathname: `/server/${key}`,
}}
onClick={() => {
dispatch(setCurrentServer(key));
}}
onClick={() => dispatch(setCurrentServer(el))}
>
<img
key={i}
Expand Down
1 change: 1 addition & 0 deletions framework/redux/slices/streamHandler.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const streamExecSlice = createSlice({
peer_connections: {};
}> = action.payload;

console.log('Before', activeSessions);
for (const session of activeSessions) {
const cid = session.cid;
const peer_connections = session.peer_connections;
Expand Down
9 changes: 5 additions & 4 deletions pages/server/[server].tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Layout } from '@components/common/Layout';
import React, { useEffect } from 'react';
import React from 'react';
import Chat from '@components/chat';
import { useRouter } from 'next/router';
import { useAppSelector } from 'framework/redux/store';

export default function SpecificServer({ connErr }: { connErr: string }) {
const router = useRouter();
const serverCid = router.query.server;

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

return (
<>
Expand Down

0 comments on commit 8c30ea8

Please sign in to comment.