aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-07-07 10:26:58 -0500
committerJP Dillingham <jp@dillingham.me>2026-07-07 11:00:43 -0500
commit5bc50e07cfb9d2bdbc0c8f90d6a6eda24158076e (patch)
treed266661f09d3d1d1a3e13eaadb12c5bb0d651903 /src/web
parent3313514f7793c40d9377f67aebbd832eb8daf822 (diff)
downloadslskd-5bc50e07cfb9d2bdbc0c8f90d6a6eda24158076e.tar.gz
remove StartOffset
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/Dashboard/HistoricalStatistics.jsx8
-rw-r--r--src/web/src/components/Dashboard/Leaderboard.jsx7
-rw-r--r--src/web/src/components/Dashboard/SearchBar.jsx6
-rw-r--r--src/web/src/components/Dashboard/TransferErrors.jsx48
-rw-r--r--src/web/src/components/Shared/Graph.jsx19
-rw-r--r--src/web/src/lib/util.js6
6 files changed, 44 insertions, 50 deletions
diff --git a/src/web/src/components/Dashboard/HistoricalStatistics.jsx b/src/web/src/components/Dashboard/HistoricalStatistics.jsx
index c14649c4..a640fc1b 100644
--- a/src/web/src/components/Dashboard/HistoricalStatistics.jsx
+++ b/src/web/src/components/Dashboard/HistoricalStatistics.jsx
@@ -1,4 +1,4 @@
-import { formatBytes, formatSpeed } from '../../lib/util';
+import { formatBytes, formatSpeed, formatWait } from '../../lib/util';
import { Graph, LoaderSegment } from '../Shared';
import Leaderboard from './Leaderboard';
import TopDirectories from './TopDirectories';
@@ -32,12 +32,6 @@ const errorCount = (directionData = {}) =>
(directionData.Cancelled?.count ?? 0) +
(directionData.TimedOut?.count ?? 0);
-const formatWait = (seconds) => {
- if (!seconds || seconds === 0) return '0s';
- if (seconds < 60) return `${Math.round(seconds)}s`;
- return `${(seconds / 60).toFixed(1)}m`;
-};
-
const buildChartData = (histogram) =>
Object.entries(histogram)
.sort(([a], [b]) => new Date(a) - new Date(b))
diff --git a/src/web/src/components/Dashboard/Leaderboard.jsx b/src/web/src/components/Dashboard/Leaderboard.jsx
index 4a37870c..a3df7d2c 100644
--- a/src/web/src/components/Dashboard/Leaderboard.jsx
+++ b/src/web/src/components/Dashboard/Leaderboard.jsx
@@ -1,6 +1,6 @@
import * as reports from '../../lib/reports';
import { formatBytes, formatSpeed } from '../../lib/util';
-import React, { useEffect, useState } from 'react';
+import React, { useEffect, useRef, useState } from 'react';
import { Divider, Grid, Header, Icon, Loader, Table } from 'semantic-ui-react';
const SORT_FIELDS = [
@@ -108,6 +108,7 @@ const initialState = {
const Leaderboard = ({ downloads, end, start, uploads }) => {
const [state, setState] = useState(initialState);
+ const sortRef = useRef(null);
useEffect(() => {
setState((previous) => ({
@@ -120,6 +121,8 @@ const Leaderboard = ({ downloads, end, start, uploads }) => {
const onSort = async (sort) => {
if (sort === state.sortBy) return;
+ sortRef.current = sort;
+
setState((previous) => ({
...previous,
sortBy: sort,
@@ -151,6 +154,8 @@ const Leaderboard = ({ downloads, end, start, uploads }) => {
console.error(error);
}
+ if (sortRef.current !== sort) return;
+
setState((previous) => ({
...previous,
rows: { upload: newUploads, download: newDownloads },
diff --git a/src/web/src/components/Dashboard/SearchBar.jsx b/src/web/src/components/Dashboard/SearchBar.jsx
index e8c0b7e4..43e7d18a 100644
--- a/src/web/src/components/Dashboard/SearchBar.jsx
+++ b/src/web/src/components/Dashboard/SearchBar.jsx
@@ -1,7 +1,7 @@
import '../Search/Search.css';
import { urlBase } from '../../config';
import * as library from '../../lib/searches';
-import React, { useRef, useState } from 'react';
+import React, { useEffect, useRef, useState } from 'react';
import { Link, useHistory } from 'react-router-dom';
import { toast } from 'react-toastify';
import { Button, Icon, Input, Segment } from 'semantic-ui-react';
@@ -48,7 +48,9 @@ const SearchBar = ({ server } = {}) => {
}
};
- inputRef?.current?.inputRef?.current?.focus();
+ useEffect(() => {
+ inputRef?.current?.inputRef?.current?.focus();
+ }, []);
return (
<Segment
diff --git a/src/web/src/components/Dashboard/TransferErrors.jsx b/src/web/src/components/Dashboard/TransferErrors.jsx
index 7def5ca6..5246abd0 100644
--- a/src/web/src/components/Dashboard/TransferErrors.jsx
+++ b/src/web/src/components/Dashboard/TransferErrors.jsx
@@ -102,36 +102,40 @@ const TransferErrors = ({ chartData, download, end, start, upload }) => {
setParetoDirection(d);
setParetoLoading(true);
- if (d === 'All') {
- const [uploadRows, downloadRows] = await Promise.all([
- fetchPareto('Upload'),
- fetchPareto('Download'),
- ]);
- setParetoRows(buildParetoRows(uploadRows, downloadRows));
- } else {
- const rows = await fetchPareto(d);
- setParetoRows(rows.map((r) => ({ ...r, direction: d })));
+ try {
+ if (d === 'All') {
+ const [uploadRows, downloadRows] = await Promise.all([
+ fetchPareto('Upload'),
+ fetchPareto('Download'),
+ ]);
+ setParetoRows(buildParetoRows(uploadRows, downloadRows));
+ } else {
+ const rows = await fetchPareto(d);
+ setParetoRows(rows.map((r) => ({ ...r, direction: d })));
+ }
+ } finally {
+ setParetoLoading(false);
}
-
- setParetoLoading(false);
};
const onRecentDirectionChange = async (d) => {
setRecentDirection(d);
setRecentLoading(true);
- if (d === 'All') {
- const [uploadRows, downloadRows] = await Promise.all([
- fetchRecent('Upload'),
- fetchRecent('Download'),
- ]);
- setRecentRows(mergeRecent(uploadRows, downloadRows));
- } else {
- const rows = await fetchRecent(d);
- setRecentRows(rows.map((r) => ({ ...r, direction: d })));
+ try {
+ if (d === 'All') {
+ const [uploadRows, downloadRows] = await Promise.all([
+ fetchRecent('Upload'),
+ fetchRecent('Download'),
+ ]);
+ setRecentRows(mergeRecent(uploadRows, downloadRows));
+ } else {
+ const rows = await fetchRecent(d);
+ setRecentRows(rows.map((r) => ({ ...r, direction: d })));
+ }
+ } finally {
+ setRecentLoading(false);
}
-
- setRecentLoading(false);
};
return (
diff --git a/src/web/src/components/Shared/Graph.jsx b/src/web/src/components/Shared/Graph.jsx
index 4d672d3d..0f753b72 100644
--- a/src/web/src/components/Shared/Graph.jsx
+++ b/src/web/src/components/Shared/Graph.jsx
@@ -1,3 +1,4 @@
+import { formatBytes, formatSpeed, formatWait } from '../../lib/util';
import React, { useEffect, useMemo, useState } from 'react';
import {
Area,
@@ -26,24 +27,6 @@ export const useDarkMode = () => {
return isDark;
};
-const formatBytes = (bytes) => {
- if (!bytes || bytes === 0) return '0 B';
- const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
- const index = Math.floor(Math.log(bytes) / Math.log(1_024));
- return `${(bytes / 1_024 ** index).toFixed(1)} ${units[index]}`;
-};
-
-const formatSpeed = (bytesPerSecond) => {
- if (!bytesPerSecond || bytesPerSecond === 0) return '0 B/s';
- return `${formatBytes(bytesPerSecond)}/s`;
-};
-
-const formatWait = (seconds) => {
- if (!seconds || seconds === 0) return '0s';
- if (seconds < 60) return `${Math.round(seconds)}s`;
- return `${(seconds / 60).toFixed(1)}m`;
-};
-
const UNIT_FORMATTERS = {
bytes: formatBytes,
count: (v) => v.toLocaleString(),
diff --git a/src/web/src/lib/util.js b/src/web/src/lib/util.js
index b499f81e..854e625e 100644
--- a/src/web/src/lib/util.js
+++ b/src/web/src/lib/util.js
@@ -44,6 +44,12 @@ export const formatSpeed = (bytesPerSecond, decimals = 1) => {
return `${formatBytes(bytesPerSecond, decimals)}/s`;
};
+export const formatWait = (seconds) => {
+ if (!seconds || seconds === 0) return '0s';
+ if (seconds < 60) return `${Math.round(seconds)}s`;
+ return `${(seconds / 60).toFixed(1)}m`;
+};
+
export const formatDate = (date) => {
return new Date(date).toLocaleString();
};