1/n Use zustand to reduce re-renders

This commit is contained in:
Igor Katson 2023-12-17 19:27:22 +00:00
parent 3dc2e3eace
commit e6ef3ff23f
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
14 changed files with 210 additions and 87 deletions

View file

@ -1,13 +1,10 @@
import { useContext, useState } from "react";
import { TorrentStats } from "../../api-types";
import {
AppContext,
APIContext,
RefreshTorrentStatsContext,
} from "../../context";
import { APIContext, RefreshTorrentStatsContext } from "../../context";
import { IconButton } from "./IconButton";
import { DeleteTorrentModal } from "../modal/DeleteTorrentModal";
import { FaPause, FaPlay, FaTrash } from "react-icons/fa";
import { useErrorStore } from "../../stores/errorStore";
export const TorrentActions: React.FC<{
id: number;
@ -23,7 +20,8 @@ export const TorrentActions: React.FC<{
const canPause = state == "live";
const canUnpause = state == "paused" || state == "error";
const ctx = useContext(AppContext);
const setCloseableError = useErrorStore((state) => state.setCloseableError);
const API = useContext(APIContext);
const unpause = () => {
@ -34,7 +32,7 @@ export const TorrentActions: React.FC<{
refreshCtx.refresh();
},
(e) => {
ctx.setCloseableError({
setCloseableError({
text: `Error starting torrent id=${id}`,
details: e,
});
@ -51,7 +49,7 @@ export const TorrentActions: React.FC<{
refreshCtx.refresh();
},
(e) => {
ctx.setCloseableError({
setCloseableError({
text: `Error pausing torrent id=${id}`,
details: e,
});