Remove dependency on uuid package, and use crypto.randomUUID() instead

This commit is contained in:
Alejandro Celaya
2024-10-02 12:06:22 +02:00
parent a90ef56eb8
commit 69344a01ac
6 changed files with 14 additions and 37 deletions

View File

@@ -4,7 +4,6 @@ import type { FC } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button } from 'reactstrap';
import { v4 as uuid } from 'uuid';
import { NoMenuLayout } from '../common/NoMenuLayout';
import type { FCWithDeps } from '../container/utils';
import { componentFactory, useDependencies } from '../container/utils';
@@ -45,7 +44,7 @@ const CreateServer: FCWithDeps<CreateServerProps, CreateServerDeps> = ({ servers
const [isConfirmModalOpen, toggleConfirmModal] = useToggle();
const [serverData, setServerData] = useState<ServerData>();
const saveNewServer = useCallback((theServerData: ServerData) => {
const id = uuid();
const id = crypto.randomUUID();
createServers([{ ...theServerData, id }]);
navigate(`/server/${id}`);

View File

@@ -1,6 +1,5 @@
import type { PayloadAction } from '@reduxjs/toolkit';
import { createSlice } from '@reduxjs/toolkit';
import { v4 as uuid } from 'uuid';
import type { ServerData, ServersMap, ServerWithId } from '../data';
interface EditServer {
@@ -20,7 +19,7 @@ const serverWithId = (server: ServerWithId | ServerData): ServerWithId => {
return server;
}
return { ...server, id: uuid() };
return { ...server, id: crypto.randomUUID() };
};
const serversListToMap = (servers: ServerWithId[]): ServersMap => servers.reduce<ServersMap>(