-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into test-swc-fix
- Loading branch information
Showing
11 changed files
with
343 additions
and
28 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
app/components/boundaries/ConnectedDevices/ConnectedDevicesBoundarie.client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use client'; | ||
import { useSetAtom, atom } from 'jotai'; | ||
import { useEffect, useMemo } from 'react'; | ||
import { getConnectedDevices } from '@/lib/get-connected-devices'; | ||
export const allConnectedDevices = atom<Array<string>>([]); | ||
|
||
export default function ConnectedDevicesWrapper({ | ||
children, | ||
connectedDevices: connectedDevices | ||
}: { | ||
children: React.ReactNode; | ||
connectedDevices: string[]; | ||
}) { | ||
const setConnectedDevices = useSetAtom(allConnectedDevices); | ||
useMemo(() => { | ||
setConnectedDevices(connectedDevices); | ||
}, []); | ||
useEffect(() => { | ||
setInterval(() => { | ||
getConnectedDevices().then((connectedDevices) => { | ||
if ('error' in connectedDevices) return; | ||
setConnectedDevices(connectedDevices); | ||
}); | ||
}, 5000); | ||
}); | ||
return <>{children}</>; | ||
} |
21 changes: 21 additions & 0 deletions
21
app/components/boundaries/ConnectedDevices/ConnectedDevicesBoundarie.server.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { getConnectedDevices } from '@/lib/get-connected-devices'; | ||
import ConnectedDevicesWrapper from './ConnectedDevicesBoundarie.client'; | ||
|
||
export default async function ConnectedDevicesBoundarie({ | ||
children | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const connectedDevices = await getConnectedDevices(); | ||
if ('error' in connectedDevices) | ||
return ( | ||
<ConnectedDevicesWrapper connectedDevices={[]}> | ||
{children} | ||
</ConnectedDevicesWrapper> | ||
); | ||
return ( | ||
<ConnectedDevicesWrapper connectedDevices={connectedDevices}> | ||
{children} | ||
</ConnectedDevicesWrapper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
app/components/dashboard/DashboardCardNetwork/PerUserSpeedDetails.client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
'use client'; | ||
import { useAtomValue } from 'jotai'; | ||
import { allSpeedStates } from '../../boundaries/SpeedBoundarie.client'; | ||
import { useRef } from 'react'; | ||
|
||
export default function PerUserSpeedDetails({ | ||
allUsers | ||
}: { | ||
allUsers: { | ||
index_number: number; | ||
ip: string; | ||
name: string; | ||
display_name: string; | ||
}[]; | ||
}) { | ||
const perUserSpeedModal = useRef( | ||
null | ||
) as unknown as React.MutableRefObject<HTMLDialogElement>; | ||
return ( | ||
<> | ||
<div className="text-right text-sm font-semibold text-gray-400 opacity-80 hover:cursor-pointer"> | ||
<div | ||
onClick={() => perUserSpeedModal.current?.showModal()} | ||
className="mt-2 w-5/6" | ||
> | ||
Show Details | ||
</div> | ||
</div> | ||
<PerUserSpeedDetailsPopUp | ||
allUsers={allUsers} | ||
perUserSpeedModal={perUserSpeedModal} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
function PerUserSpeedDetailsPopUp({ | ||
allUsers, | ||
perUserSpeedModal | ||
}: { | ||
allUsers: { | ||
index_number: number; | ||
ip: string; | ||
name: string; | ||
display_name: string; | ||
}[]; | ||
perUserSpeedModal: React.MutableRefObject<HTMLDialogElement>; | ||
}) { | ||
function closePopUp() { | ||
perUserSpeedModal.current?.close(); | ||
} | ||
const allSpeeds = useAtomValue(allSpeedStates); | ||
if (!allSpeeds[0].length) | ||
return ( | ||
<> | ||
<dialog ref={perUserSpeedModal} className="modal"> | ||
<div className="modal-box !min-h-[400px] w-11/12 min-w-[auto] bg-zinc-900 sm:w-3/4 md:w-1/2 lg:w-1/2"> | ||
<h3 className="pb-5 text-lg font-bold">Per User Speed</h3> | ||
|
||
<div className="overflow-x-auto"> | ||
<table className="table table-fixed"> | ||
<thead> | ||
<tr className="border-zinc-700"> | ||
<th>Name</th> | ||
<th>Download</th> | ||
<th>Upload</th> | ||
</tr> | ||
</thead> | ||
<tbody></tbody> | ||
</table> | ||
</div> | ||
|
||
<button | ||
onClick={closePopUp} | ||
className="btn btn-circle btn-ghost btn-sm absolute right-2 top-2" | ||
> | ||
✕ | ||
</button> | ||
</div> | ||
<div className="modal-backdrop bg-zinc-700 opacity-30"> | ||
<button onClick={closePopUp}>close</button> | ||
</div> | ||
</dialog> | ||
</> | ||
); | ||
const ipToName = allSpeeds[0].map((user) => { | ||
const userDetails = allUsers.filter((u) => u.ip === user.ip)[0]; | ||
if (!userDetails) return; | ||
if (Number(user.in) <= 0 && Number(user.out) <= 0) return; | ||
let userName = | ||
userDetails.display_name || | ||
(userDetails.name != 'Unknown' ? userDetails.name : user.ip); | ||
return { | ||
index_number: userDetails.index_number, | ||
name: userName, | ||
in: user.in, | ||
out: user.out | ||
}; | ||
}); | ||
const ipToNameFiltered = ipToName.filter((u) => u !== undefined) as { | ||
index_number: number; | ||
name: string; | ||
in: string; | ||
out: string; | ||
}[]; | ||
ipToNameFiltered.sort((a, b) => a.index_number - b.index_number); | ||
return ( | ||
<> | ||
<dialog ref={perUserSpeedModal} className="modal"> | ||
<div className="modal-box !min-h-[400px] w-11/12 min-w-[auto] bg-zinc-900 sm:w-3/4 md:w-1/2 lg:w-1/2"> | ||
<h3 className="pb-5 text-lg font-bold">Per User Speed</h3> | ||
|
||
<div className="overflow-x-auto"> | ||
<table className="table table-fixed"> | ||
<thead> | ||
<tr className="border-zinc-700"> | ||
<th>Name</th> | ||
<th>Download</th> | ||
<th>Upload</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ipToNameFiltered.map((user) => ( | ||
<tr className="border-zinc-700" key={user.name}> | ||
<td>{user.name}</td> | ||
<td>{user.in} Mbps</td> | ||
<td>{user.out} Mbps</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<button | ||
onClick={closePopUp} | ||
className="btn btn-circle btn-ghost btn-sm absolute right-2 top-2" | ||
> | ||
✕ | ||
</button> | ||
</div> | ||
<div className="modal-backdrop bg-zinc-700 opacity-30"> | ||
<button onClick={closePopUp}>close</button> | ||
</div> | ||
</dialog> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.