diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-10-02 18:42:06 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-10-02 18:42:06 -0500 |
| commit | ffd4a8c60476fe75d3c37d8323b51b4367fb7492 (patch) | |
| tree | b549e0081bbf8cf60d61695ffad6284808ff82e0 /src/web | |
| parent | f32f73b402e9bfd5aca47cb94a245fccbd21482f (diff) | |
| download | slskd-ffd4a8c60476fe75d3c37d8323b51b4367fb7492.tar.gz | |
show errors, toast if popup blocked
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/components/System/Logs/Explorer.jsx | 150 |
1 files changed, 82 insertions, 68 deletions
diff --git a/src/web/src/components/System/Logs/Explorer.jsx b/src/web/src/components/System/Logs/Explorer.jsx index ac6d982f..b1391da2 100644 --- a/src/web/src/components/System/Logs/Explorer.jsx +++ b/src/web/src/components/System/Logs/Explorer.jsx @@ -1,7 +1,12 @@ import '../Files/Files.css'; import { getFileBlob, list } from '../../../lib/logs'; import { downloadFile, formatBytes, formatDate } from '../../../lib/util'; -import { LoaderSegment } from '../../Shared'; +import { + ErrorSegment, + LoaderSegment, + PlaceholderSegment, + Switch, +} from '../../Shared'; import React, { useEffect, useState } from 'react'; import { toast } from 'react-toastify'; import { Header, Icon, Table } from 'semantic-ui-react'; @@ -9,6 +14,13 @@ import { Header, Icon, Table } from 'semantic-ui-react'; const view = async (filename) => { const tab = window.open('', '_blank'); + if (!tab) { + toast.error( + 'Unable to open a new window; allow pop-ups for this site to view logs', + ); + return; + } + try { const blob = await getFileBlob({ filename }); @@ -60,17 +72,23 @@ const FileRow = ({ length, modifiedAt, name }) => ( const Explorer = () => { const [files, setFiles] = useState([]); - const [loading, setLoading] = useState(false); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(undefined); const [sortColumn, setSortColumn] = useState('date'); const [sortDirection, setSortDirection] = useState('descending'); const fetch = async () => { setLoading(true); + setError(undefined); try { setFiles(await list()); - } catch (error) { - toast.error(error?.message ?? error); + } catch (fetchError) { + if (fetchError?.response?.status === 404) { + setFiles([]); + } else { + setError(fetchError?.message ?? fetchError); + } } finally { setLoading(false); } @@ -112,10 +130,6 @@ const Explorer = () => { }); }; - if (loading) { - return <LoaderSegment />; - } - const sortedFiles = sortItems(files); return ( @@ -127,74 +141,74 @@ const Explorer = () => { <Icon name="folder open" /> /logs </Header> - <Table - className="unstackable" - size="large" + <Switch + empty={ + !loading && + !error && + files.length === 0 && ( + <PlaceholderSegment + caption="No log files" + icon="file alternate outline" + /> + ) + } + error={error && <ErrorSegment caption={error} />} + loading={loading && <LoaderSegment />} > - <Table.Header> - <Table.Row> - <Table.HeaderCell - className="explorer-list-name" - onClick={() => handleSort('name')} - style={{ cursor: 'pointer' }} - > - Name - {sortColumn === 'name' && ( - <Icon - name={ - sortDirection === 'ascending' - ? 'chevron up' - : 'chevron down' - } - /> - )} - </Table.HeaderCell> - <Table.HeaderCell - className="explorer-list-date" - onClick={() => handleSort('date')} - style={{ cursor: 'pointer' }} - > - Date Modified - {sortColumn === 'date' && ( - <Icon - name={ - sortDirection === 'ascending' - ? 'chevron up' - : 'chevron down' - } - /> - )} - </Table.HeaderCell> - <Table.HeaderCell className="explorer-list-size"> - Size - </Table.HeaderCell> - <Table.HeaderCell className="explorer-list-action" /> - </Table.Row> - </Table.Header> - <Table.Body> - {files.length === 0 ? ( + <Table + className="unstackable" + size="large" + > + <Table.Header> <Table.Row> - <Table.Cell - colSpan={99} - style={{ - opacity: 0.5, - padding: '10px !important', - textAlign: 'center', - }} + <Table.HeaderCell + className="explorer-list-name" + onClick={() => handleSort('name')} + style={{ cursor: 'pointer' }} + > + Name + {sortColumn === 'name' && ( + <Icon + name={ + sortDirection === 'ascending' + ? 'chevron up' + : 'chevron down' + } + /> + )} + </Table.HeaderCell> + <Table.HeaderCell + className="explorer-list-date" + onClick={() => handleSort('date')} + style={{ cursor: 'pointer' }} > - No log files - </Table.Cell> + Date Modified + {sortColumn === 'date' && ( + <Icon + name={ + sortDirection === 'ascending' + ? 'chevron up' + : 'chevron down' + } + /> + )} + </Table.HeaderCell> + <Table.HeaderCell className="explorer-list-size"> + Size + </Table.HeaderCell> + <Table.HeaderCell className="explorer-list-action" /> </Table.Row> - ) : ( - sortedFiles.map((f) => ( + </Table.Header> + <Table.Body> + {sortedFiles.map((f) => ( <FileRow key={f.name} {...f} /> - )) - )} - </Table.Body> - </Table> + ))} + </Table.Body> + </Table> + </Switch> </> ); }; |
