show the name of current selected scanner

main
alex 2023-05-25 14:48:57 +02:00
parent 487fd255cf
commit 60d18cdaf0
3 changed files with 21 additions and 3 deletions

View File

@ -9,7 +9,7 @@ import Sider from "antd/es/layout/Sider";
import { useContext, useEffect, useState } from "react"; import { useContext, useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom"; import { useLocation, useNavigate } from "react-router-dom";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { Constants, MyAvatar, WebSocketContext } from "../../utils"; import { Constants, MyAvatar, WebSocketContext, getUserId } from "../../utils";
export default function SideMenu({ userSession, setUserSession }) { export default function SideMenu({ userSession, setUserSession }) {
const location = useLocation(); const location = useLocation();
@ -22,6 +22,19 @@ export default function SideMenu({ userSession, setUserSession }) {
}, [location.pathname]); }, [location.pathname]);
const navigate = useNavigate(); const navigate = useNavigate();
function getCurrentUsedScannerName() {
const userId = getUserId();
const scannerName = webSocketContext.Scanners.find(
(scanner) => scanner.UsedByUserId === userId
)?.Name;
console.log(scannerName);
return scannerName === undefined ? "No scanner selected" : scannerName;
}
return ( return (
<Sider <Sider
theme="light" theme="light"
@ -75,7 +88,7 @@ export default function SideMenu({ userSession, setUserSession }) {
items={[ items={[
{ {
icon: <ScanOutlined />, icon: <ScanOutlined />,
label: "Alex's Scanner", label: getCurrentUsedScannerName(),
key: "/scanners", key: "/scanners",
}, },
{ {

View File

@ -3,6 +3,7 @@ import {
FormatDatetime, FormatDatetime,
MyAvatar, MyAvatar,
WebSocketContext, WebSocketContext,
getUserId,
getUserSessionFromLocalStorage, getUserSessionFromLocalStorage,
} from "../../utils"; } from "../../utils";
import { useContext } from "react"; import { useContext } from "react";
@ -44,7 +45,7 @@ const columns = [
<Link <Link
to="#" to="#"
onClick={() => { onClick={() => {
if (localStorage.getItem("userId") === record._usedByUserId) { if (getUserId() === record._usedByUserId) {
message.error("You are already using this scanner"); message.error("You are already using this scanner");
return; return;
} }

View File

@ -433,3 +433,7 @@ export function MyAvatar({
return <MyAvat />; return <MyAvat />;
} }
export function getUserId() {
return localStorage.getItem("userId");
}