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 { useLocation, useNavigate } from "react-router-dom";
import PropTypes from "prop-types";
import { Constants, MyAvatar, WebSocketContext } from "../../utils";
import { Constants, MyAvatar, WebSocketContext, getUserId } from "../../utils";
export default function SideMenu({ userSession, setUserSession }) {
const location = useLocation();
@ -22,6 +22,19 @@ export default function SideMenu({ userSession, setUserSession }) {
}, [location.pathname]);
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 (
<Sider
theme="light"
@ -75,7 +88,7 @@ export default function SideMenu({ userSession, setUserSession }) {
items={[
{
icon: <ScanOutlined />,
label: "Alex's Scanner",
label: getCurrentUsedScannerName(),
key: "/scanners",
},
{

View File

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

View File

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