aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-11-25 17:48:51 -0600
committerGitHub <noreply@github.com>2022-11-25 17:48:51 -0600
commita391956c967a7c436ce6fabdbbd8ddcbda562e26 (patch)
tree8b7b2bbaeffb1b90e310a8e2a7e913bf2592127a /src
parenta99d796464528e2add10b358a3344b7c1d1278dd (diff)
parentfd72cac19e6beaa2ec6377b791f9b3d0bbd88d94 (diff)
downloadslskd-a391956c967a7c436ce6fabdbbd8ddcbda562e26.tar.gz
Merge pull request #783 from slskd/shares
Update the shares UI when config changes, or after scanning
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Shares/ShareService.cs16
-rw-r--r--src/slskd/Shares/Types/Share.cs6
-rw-r--r--src/web/src/components/System/Shares/ShareTable.js4
-rw-r--r--src/web/src/components/System/Shares/index.js16
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]) => {