diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Shares/ShareService.cs | 16 | ||||
| -rw-r--r-- | src/slskd/Shares/Types/Share.cs | 6 | ||||
| -rw-r--r-- | src/web/src/components/System/Shares/ShareTable.js | 4 | ||||
| -rw-r--r-- | src/web/src/components/System/Shares/index.js | 16 |
4 files changed, 23 insertions, 19 deletions
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 /// <param name="directories"></param> /// <param name="files"></param> [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) { 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 }) => { <Icon name='folder'/> <Link to='#'>{share.localPath}</Link> </Table.Cell> - <Table.Cell>{share.directories}</Table.Cell> - <Table.Cell>{share.files}</Table.Cell> + <Table.Cell>{share.directories ?? '?'}</Table.Cell> + <Table.Cell>{share.files ?? '?'}</Table.Cell> <Table.Cell>{share.alias}</Table.Cell> <Table.Cell>{share.remotePath}</Table.Cell> </Table.Row>))} diff --git a/src/web/src/components/System/Shares/index.js b/src/web/src/components/System/Shares/index.js index f4f9ac94..3d5b1858 100644 --- a/src/web/src/components/System/Shares/index.js +++ b/src/web/src/components/System/Shares/index.js @@ -24,21 +24,25 @@ 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({ quiet: true }); + + if (!scanning) { + // 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); } - }, [scanned]); + }, [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]) => { |
