From 2c5f1095ea179cc302bfaa5d3a0d6ba18ca501c7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 25 Nov 2022 17:28:48 -0600 Subject: make share counts nullable --- src/slskd/Shares/ShareService.cs | 16 ++++++++-------- src/slskd/Shares/Types/Share.cs | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 7051fda3..1d4a6ceb 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -131,8 +131,8 @@ namespace slskd.Shares State.SetValue(state => state with { Hosts = Hosts.Select(host => host.Name).ToArray(), - Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories), - Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files), + Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories ?? 0), + Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files ?? 0), }); } @@ -237,8 +237,8 @@ namespace slskd.Shares State.SetValue(state => state with { Hosts = Hosts.Select(host => host.Name).ToArray(), - Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories), - Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files), + Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories ?? 0), + Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files ?? 0), }); return removed; @@ -332,8 +332,8 @@ namespace slskd.Shares State.SetValue(state => state with { - Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories), - Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files), + Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories ?? 0 ), + Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files ?? 0), Ready = true, }); } @@ -460,8 +460,8 @@ namespace slskd.Shares Ready = true, ScanProgress = 1, Hosts = Hosts.Select(host => host.Name).ToList().AsReadOnly(), - Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories), - Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files), + Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories ?? 0), + Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files ?? 0), }); } catch (Exception ex) diff --git a/src/slskd/Shares/Types/Share.cs b/src/slskd/Shares/Types/Share.cs index 42a2e9e2..d60998f6 100644 --- a/src/slskd/Shares/Types/Share.cs +++ b/src/slskd/Shares/Types/Share.cs @@ -38,7 +38,7 @@ namespace slskd.Shares /// /// [JsonConstructor] - public Share (string id, string alias, bool isExcluded, string localPath, string raw, string remotePath, int directories, int files) + public Share (string id, string alias, bool isExcluded, string localPath, string raw, string remotePath, int? directories, int? files) { Id = id; Alias = alias; @@ -91,8 +91,8 @@ namespace slskd.Shares public string LocalPath { get; init; } public string Raw { get; init; } public string RemotePath { get; init; } - public int Directories { get; private set; } - public int Files { get; private set; } + public int? Directories { get; private set; } + public int? Files { get; private set; } public void UpdateStatistics(int directories, int files) { -- cgit v1.2.3 From e34571b4c8579ea3fdb4d68ee6926868f456515f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 25 Nov 2022 17:29:02 -0600 Subject: show '?' when counts are null --- src/web/src/components/System/Shares/ShareTable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Shares/ShareTable.js b/src/web/src/components/System/Shares/ShareTable.js index 095a8380..fd2c7623 100644 --- a/src/web/src/components/System/Shares/ShareTable.js +++ b/src/web/src/components/System/Shares/ShareTable.js @@ -35,8 +35,8 @@ const ShareTable = ({ shares, onClick }) => { {share.localPath} - {share.directories} - {share.files} + {share.directories ?? '?'} + {share.files ?? '?'} {share.alias} {share.remotePath} ))} -- cgit v1.2.3 From 46fdeeec1db71068cf2562070a3802f812cef6e4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 25 Nov 2022 17:29:10 -0600 Subject: refresh shares when state changes --- src/web/src/components/System/Shares/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Shares/index.js b/src/web/src/components/System/Shares/index.js index f4f9ac94..c4282986 100644 --- a/src/web/src/components/System/Shares/index.js +++ b/src/web/src/components/System/Shares/index.js @@ -24,17 +24,18 @@ const Index = ({ state = {} } = {}) => { const [modal, setModal] = useState(false); const { scanning, scanProgress, scanPending, directories, files } = state; - const scanned = !scanning; useEffect(() => { getAll(); }, []); useEffect(() => { - if (scanned) { - getAll(); + getAll(); + + if (!scanning) { + setTimeout(() => getAll(), 1000); } - }, [scanned]); + }, [scanning, scanPending]); const getAll = async () => { try { -- cgit v1.2.3 From fd72cac19e6beaa2ec6377b791f9b3d0bbd88d94 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 25 Nov 2022 17:40:39 -0600 Subject: suppress loader --- src/web/src/components/System/Shares/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Shares/index.js b/src/web/src/components/System/Shares/index.js index c4282986..3d5b1858 100644 --- a/src/web/src/components/System/Shares/index.js +++ b/src/web/src/components/System/Shares/index.js @@ -30,16 +30,19 @@ const Index = ({ state = {} } = {}) => { }, []); useEffect(() => { - getAll(); + getAll({ quiet: true }); if (!scanning) { - setTimeout(() => getAll(), 1000); + // the state change out of scanning can fire before + // shares are updated, which leaves them stale. wait a second + // and fetch again. + setTimeout(() => getAll({ quiet: true }), 1000); } }, [scanning, scanPending]); - const getAll = async () => { + const getAll = async ({ quiet } = { quiet: false }) => { try { - setLoading(true); + if (!quiet) setLoading(true); const sharesByHost = await sharesLib.getAll(); const flattened = Object.entries(sharesByHost).reduce((acc, [host, shares]) => { -- cgit v1.2.3