aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-05-25 10:11:42 -0500
committerGitHub <noreply@github.com>2022-05-25 10:11:42 -0500
commit52bb4a4c2457314bf6bc7713e0687d20fdf55a37 (patch)
treef05d716047b4c038f2c0b4c670967556440da944 /src/web
parentc9968c85dcbaab05d50dbbb1f0cdd4d9bd1b6d65 (diff)
parente55a220ad618bce5f9d8bf7ed7c83cbeac96713a (diff)
downloadslskd-52bb4a4c2457314bf6bc7713e0687d20fdf55a37.tar.gz
Merge pull request #484 from slskd/cleanup
Add a new header and mass-operation buttons for Downloads and Uploads
Diffstat (limited to 'src/web')
-rw-r--r--src/web/package-lock.json1
-rw-r--r--src/web/src/components/App.css43
-rw-r--r--src/web/src/components/App.js10
-rw-r--r--src/web/src/components/Browse/Browse.css11
-rw-r--r--src/web/src/components/Browse/Browse.js5
-rw-r--r--src/web/src/components/Chat/Chat.css10
-rw-r--r--src/web/src/components/Chat/Chat.js5
-rw-r--r--src/web/src/components/Rooms/Rooms.css10
-rw-r--r--src/web/src/components/Rooms/Rooms.js5
-rw-r--r--src/web/src/components/Search/List/SearchList.js68
-rw-r--r--src/web/src/components/Search/Search.css6
-rw-r--r--src/web/src/components/Search/Searches.js20
-rw-r--r--src/web/src/components/Shared/Div.js11
-rw-r--r--src/web/src/components/Shared/Nbsp.js5
-rw-r--r--src/web/src/components/Shared/ShrinkableButton.js6
-rw-r--r--src/web/src/components/Shared/ShrinkableDropdownButton.js46
-rw-r--r--src/web/src/components/Shared/index.js10
-rw-r--r--src/web/src/components/System/Info.js6
-rw-r--r--src/web/src/components/Transfers/TransferGroup.js14
-rw-r--r--src/web/src/components/Transfers/Transfers.css52
-rw-r--r--src/web/src/components/Transfers/Transfers.js190
-rw-r--r--src/web/src/components/Transfers/TransfersHeader.js155
-rw-r--r--src/web/src/components/Users/Users.css8
-rw-r--r--src/web/src/components/Users/Users.js6
-rw-r--r--src/web/src/lib/transfers.js21
25 files changed, 570 insertions, 154 deletions
diff --git a/src/web/package-lock.json b/src/web/package-lock.json
index 0e1481c9..e9c25042 100644
--- a/src/web/package-lock.json
+++ b/src/web/package-lock.json
@@ -5,6 +5,7 @@
"requires": true,
"packages": {
"": {
+ "name": "web",
"version": "0.1.0",
"hasInstallScript": true,
"dependencies": {
diff --git a/src/web/src/components/App.css b/src/web/src/components/App.css
index 1f52554c..e0935163 100644
--- a/src/web/src/components/App.css
+++ b/src/web/src/components/App.css
@@ -80,37 +80,6 @@ body {
width: 65px;
}
-.transfer-button {
- color: black;
-}
-
-.transfer-card {
- width: 1200px !important;
- margin-left: auto !important;
- margin-right: auto !important;
-}
-
-.transfer-segment {
- margin-top: 16px;
- padding-left: 15px;
- padding-right: 15px;
-}
-
-.transfer-placeholder {
- font-weight: 100;
- text-align: center;
- margin-top: 50px !important;
-}
-
-.transferlist-size {
- width: 150px;
- min-width: 150px;
-}
-
-.transferlist-filename {
- word-wrap: break-word !important;
-}
-
.showmore-button {
padding: 20px !important;
max-width: 1200px !important;
@@ -150,3 +119,15 @@ body {
.loader-segment.ui.placeholder > :before {
background-color: transparent !important;
}
+
+.page {
+ padding-left: 15px;
+ padding-right: 15px;
+ max-width: 1200px !important;
+ margin-left: auto !important;
+ margin-right: auto !important;
+}
+
+.page:last-child {
+ margin-bottom: 17px;
+} \ No newline at end of file
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js
index 1078935a..8c879480 100644
--- a/src/web/src/components/App.js
+++ b/src/web/src/components/App.js
@@ -260,7 +260,7 @@ class App extends Component {
<AppContext.Provider value={{ state: applicationState, options: applicationOptions }}>
<Switch>
<Route path={`${urlBase}/searches/:id?`} render={(props) =>
- this.withTokenCheck(<div className='search-container'>
+ this.withTokenCheck(<div className='page'>
<Searches
server={applicationState.server}
{...props}
@@ -272,10 +272,14 @@ class App extends Component {
<Route path={`${urlBase}/chat`} render={(props) => this.withTokenCheck(<Chat {...props}/>)}/>
<Route path={`${urlBase}/rooms`} render={(props) => this.withTokenCheck(<Rooms {...props}/>)}/>
<Route path={`${urlBase}/uploads`} render={
- (props) => this.withTokenCheck(<Transfers {...props} direction='upload' />)
+ (props) =>
+ this.withTokenCheck(<div className='page'><Transfers {...props} direction='upload'/></div>)
}/>
<Route path={`${urlBase}/downloads`} render={
- (props) => this.withTokenCheck(<Transfers {...props} direction='download' />)
+ (props) =>
+ this.withTokenCheck(<div className='page'>
+ <Transfers {...props} direction='download' server={applicationState.server}/>
+ </div>)
}/>
<Route path={`${urlBase}/system/:tab?`} render={
(props) => this.withTokenCheck(
diff --git a/src/web/src/components/Browse/Browse.css b/src/web/src/components/Browse/Browse.css
index 336dfd6c..51e7aa84 100644
--- a/src/web/src/components/Browse/Browse.css
+++ b/src/web/src/components/Browse/Browse.css
@@ -1,3 +1,14 @@
+.browse-segment {
+ margin-top: 15px !important;
+ height: 78px !important;
+ display: flex;
+}
+
+.browse-segment-icon {
+ padding-top: 10px;
+ padding-right: .5em;
+}
+
.browse-results {
margin: unset !important;
}
diff --git a/src/web/src/components/Browse/Browse.js b/src/web/src/components/Browse/Browse.js
index bca73c97..5b845b7b 100644
--- a/src/web/src/components/Browse/Browse.js
+++ b/src/web/src/components/Browse/Browse.js
@@ -170,7 +170,8 @@ class Browse extends Component {
return (
<div className='search-container'>
- <Segment className='search-segment' raised>
+ <Segment className='browse-segment' raised>
+ <div className="browse-segment-icon"><Icon name="folder open" size="big"/></div>
<Input
input={<input placeholder="Username" type="search" data-lpignore="true"></input>}
size='big'
@@ -200,7 +201,7 @@ class Browse extends Component {
<span className='browse-error'>Failed to browse {username}</span> :
<div className='browse-container'>
{emptyTree ?
- <PlaceholderSegment icon='folder open'/> :
+ <PlaceholderSegment icon='folder open' caption='No user share to display'/> :
<Card className='browse-tree-card' raised>
<Card.Content>
<Card.Header>
diff --git a/src/web/src/components/Chat/Chat.css b/src/web/src/components/Chat/Chat.css
index c414264b..107c6474 100644
--- a/src/web/src/components/Chat/Chat.css
+++ b/src/web/src/components/Chat/Chat.css
@@ -18,15 +18,23 @@
margin-bottom: 17px;
}
-.chats > .segment:first-child {
+.chat-segment {
margin-top: 15px !important;
height: 78px;
+ display: flex;
+}
+
+.chat-segment-icon {
+ padding-top: 10px;
+ padding-right: .5em;
}
.conversation-menu {
overflow-x: auto;
box-shadow: unset !important;
height: 47px;
+ width: 100%;
+ margin-top: unset !important;
}
.conversation-menu > .menu-item {
diff --git a/src/web/src/components/Chat/Chat.js b/src/web/src/components/Chat/Chat.js
index 81d02461..47c1dba0 100644
--- a/src/web/src/components/Chat/Chat.js
+++ b/src/web/src/components/Chat/Chat.js
@@ -150,7 +150,8 @@ class Chat extends Component {
return (
<div className='chats'>
- <Segment raised>
+ <Segment className='chat-segment' raised>
+ <div className="chat-segment-icon"><Icon name="comment" size="big"/></div>
<ChatMenu
conversations={conversations}
active={active}
@@ -159,7 +160,7 @@ class Chat extends Component {
/>
</Segment>
{!active ?
- <PlaceholderSegment icon='comment'/> :
+ <PlaceholderSegment icon='comment' caption='No chats to display'/> :
<Card className='chat-active-card' raised>
<Card.Content onClick={() => this.focusInput()}>
<Card.Header>
diff --git a/src/web/src/components/Rooms/Rooms.css b/src/web/src/components/Rooms/Rooms.css
index 87180fd5..961d7e00 100644
--- a/src/web/src/components/Rooms/Rooms.css
+++ b/src/web/src/components/Rooms/Rooms.css
@@ -7,15 +7,23 @@
margin-bottom: 17px;
}
-.rooms > .segment:first-child {
+.rooms-segment {
margin-top: 15px !important;
height: 78px;
+ display: flex;
+}
+
+.rooms-segment-icon {
+ padding-top: 10px;
+ padding-right: .5em;
}
.room-menu {
overflow-x: auto;
box-shadow: unset !important;
height: 47px;
+ width: 100%;
+ margin-top: unset !important;
}
.room-menu > .menu-item {
diff --git a/src/web/src/components/Rooms/Rooms.js b/src/web/src/components/Rooms/Rooms.js
index e19face3..822cdaf4 100644
--- a/src/web/src/components/Rooms/Rooms.js
+++ b/src/web/src/components/Rooms/Rooms.js
@@ -150,7 +150,8 @@ class Rooms extends Component {
return (
<div className='rooms'>
- <Segment raised>
+ <Segment className='rooms-segment' raised>
+ <div className="rooms-segment-icon"><Icon name="comments" size="big"/></div>
<RoomMenu
joined={joined}
active={active}
@@ -159,7 +160,7 @@ class Rooms extends Component {
/>
</Segment>
{!active ?
- <PlaceholderSegment icon='comments'/> :
+ <PlaceholderSegment icon='comments' caption='No rooms to display'/> :
<Card className='room-active-card' raised>
<Card.Content onClick={() => this.focusInput()}>
<Card.Header>
diff --git a/src/web/src/components/Search/List/SearchList.js b/src/web/src/components/Search/List/SearchList.js
index b6e001a6..9826bdc5 100644
--- a/src/web/src/components/Search/List/SearchList.js
+++ b/src/web/src/components/Search/List/SearchList.js
@@ -1,4 +1,4 @@
-import React, { useMemo } from 'react';
+import React from 'react';
import SearchListRow from './SearchListRow';
import ErrorSegment from '../../Shared/ErrorSegment';
@@ -9,8 +9,6 @@ import {
Table,
Icon,
Loader,
- Segment,
- Header,
List,
} from 'semantic-ui-react';
@@ -21,55 +19,39 @@ const SearchList = ({
onRemove = () => { },
onStop = () => { },
}) => {
- const searchCount = useMemo(() => {
- return Object.values(searches).length
- }, [searches])
-
return (
<Card className='search-list-card' raised>
<Card.Content>
- <div style={{marginTop: -20 }}>
+ <div>
<Switch
connecting={connecting && <Loader active inline='centered' size='small'/>}
error={error && <ErrorSegment caption={error} />}
>
- <Header size='small' className='filelist-header'>
- <div>
- <Icon size='large' name='search'/>
- Searches
- </div>
- </Header>
<List>
<List.Item>
- <Switch
- noSearches={!searchCount &&
- <Segment basic style={{opacity: .5}} textAlign='center'>No searches to display</Segment>
- }
- >
- <Table size='large'>
- <Table.Header>
- <Table.Row>
- <Table.HeaderCell className="search-list-action"><Icon name="info circle"/></Table.HeaderCell>
- <Table.HeaderCell className="search-list-phrase">Search</Table.HeaderCell>
- <Table.HeaderCell className="search-list-files">Files</Table.HeaderCell>
- <Table.HeaderCell className="search-list-locked">Locked</Table.HeaderCell>
- <Table.HeaderCell className="search-list-responses">Responses</Table.HeaderCell>
- <Table.HeaderCell className="search-list-started">Ended</Table.HeaderCell>
- <Table.HeaderCell className="search-list-action"></Table.HeaderCell>
- </Table.Row>
- </Table.Header>
- <Table.Body>
- {Object.values(searches)
- .sort((a, b) => (new Date(b.startedAt) - new Date(a.startedAt)))
- .map((search, index) => <SearchListRow
- search={search}
- key={index}
- onRemove={onRemove}
- onStop={onStop}
- />)}
- </Table.Body>
- </Table>
- </Switch>
+ <Table size='large'>
+ <Table.Header>
+ <Table.Row>
+ <Table.HeaderCell className="search-list-action"><Icon name="info circle"/></Table.HeaderCell>
+ <Table.HeaderCell className="search-list-phrase">Search</Table.HeaderCell>
+ <Table.HeaderCell className="search-list-files">Files</Table.HeaderCell>
+ <Table.HeaderCell className="search-list-locked">Locked</Table.HeaderCell>
+ <Table.HeaderCell className="search-list-responses">Responses</Table.HeaderCell>
+ <Table.HeaderCell className="search-list-started">Ended</Table.HeaderCell>
+ <Table.HeaderCell className="search-list-action"></Table.HeaderCell>
+ </Table.Row>
+ </Table.Header>
+ <Table.Body>
+ {Object.values(searches)
+ .sort((a, b) => (new Date(b.startedAt) - new Date(a.startedAt)))
+ .map((search, index) => <SearchListRow
+ search={search}
+ key={index}
+ onRemove={onRemove}
+ onStop={onStop}
+ />)}
+ </Table.Body>
+ </Table>
</List.Item>
</List>
</Switch>
diff --git a/src/web/src/components/Search/Search.css b/src/web/src/components/Search/Search.css
index 42912ed5..f66a3bc7 100644
--- a/src/web/src/components/Search/Search.css
+++ b/src/web/src/components/Search/Search.css
@@ -13,6 +13,12 @@
.search-segment {
margin-top: 15px !important;
height: 78px !important;
+ display: flex;
+}
+
+.search-segment-icon {
+ padding-top: 10px;
+ padding-right: .5em;
}
.search-card {
diff --git a/src/web/src/components/Search/Searches.js b/src/web/src/components/Search/Searches.js
index 9caeb77e..76644cc2 100644
--- a/src/web/src/components/Search/Searches.js
+++ b/src/web/src/components/Search/Searches.js
@@ -15,10 +15,12 @@ import {
Input,
Segment,
Button,
+ Icon,
} from 'semantic-ui-react';
import SearchDetail from './Detail/SearchDetail';
import ErrorSegment from '../Shared/ErrorSegment';
+import PlaceholderSegment from '../Shared/PlaceholderSegment';
const Searches = ({ server }) => {
const [connecting, setConnecting] = useState(true);
@@ -187,6 +189,7 @@ const Searches = ({ server }) => {
return (
<>
<Segment className='search-segment' raised>
+ <div className="search-segment-icon"><Icon name="search" size="big"/></div>
<Input
input={
<input
@@ -211,13 +214,16 @@ const Searches = ({ server }) => {
onKeyUp={(e) => e.key === 'Enter' ? create() : ''}
/>
</Segment>
- <SearchList
- connecting={connecting}
- error={error}
- searches={searches}
- onRemove={remove}
- onStop={stop}
- />
+ {Object.keys(searches).length === 0
+ ? <PlaceholderSegment icon="search" caption="No searches to display"/>
+ : <SearchList
+ connecting={connecting}
+ error={error}
+ searches={searches}
+ onRemove={remove}
+ onStop={stop}
+ />
+ }
</>
)
};
diff --git a/src/web/src/components/Shared/Div.js b/src/web/src/components/Shared/Div.js
new file mode 100644
index 00000000..e9bf999a
--- /dev/null
+++ b/src/web/src/components/Shared/Div.js
@@ -0,0 +1,11 @@
+import React from 'react';
+
+const Div = ({ hidden, children, ...rest }) => {
+ if (hidden) {
+ return <></>;
+ }
+
+ return (<div {...rest}>{children}</div>);
+}
+
+export default Div; \ No newline at end of file
diff --git a/src/web/src/components/Shared/Nbsp.js b/src/web/src/components/Shared/Nbsp.js
new file mode 100644
index 00000000..1c8bbfa2
--- /dev/null
+++ b/src/web/src/components/Shared/Nbsp.js
@@ -0,0 +1,5 @@
+const Nbsp = () => {
+ return ' ';
+}
+
+export default Nbsp; \ No newline at end of file
diff --git a/src/web/src/components/Shared/ShrinkableButton.js b/src/web/src/components/Shared/ShrinkableButton.js
index c5a96849..77981953 100644
--- a/src/web/src/components/Shared/ShrinkableButton.js
+++ b/src/web/src/components/Shared/ShrinkableButton.js
@@ -3,13 +3,13 @@ import React from 'react';
import { useMediaQuery } from 'react-responsive';
import { Button, Icon, Popup } from 'semantic-ui-react';
-const ShrinkableButton = ({ iconName, mediaQuery, children, ...rest }) => {
+const ShrinkableButton = ({ icon, mediaQuery, children, ...rest }) => {
const shouldShrink = useMediaQuery({ query: mediaQuery })
if (!shouldShrink) {
return (
<Button {...rest}>
- <Icon name={iconName}/>
+ <Icon name={icon}/>
{children}
</Button>
)
@@ -20,7 +20,7 @@ const ShrinkableButton = ({ iconName, mediaQuery, children, ...rest }) => {
content={children}
trigger={
<Button icon {...rest}>
- <Icon name={iconName}/>
+ <Icon name={icon}/>
</Button>
}
/>
diff --git a/src/web/src/components/Shared/ShrinkableDropdownButton.js b/src/web/src/components/Shared/ShrinkableDropdownButton.js
new file mode 100644
index 00000000..2f4db781
--- /dev/null
+++ b/src/web/src/components/Shared/ShrinkableDropdownButton.js
@@ -0,0 +1,46 @@
+import React from 'react';
+
+import {
+ Button,
+ Dropdown,
+} from 'semantic-ui-react';
+
+import ShrinkableButton from './ShrinkableButton';
+
+const ShrinkableDropdownButton = ({
+ color,
+ icon,
+ mediaQuery,
+ disabled,
+ loading,
+ options,
+ onClick,
+ onChange,
+ hidden,
+ children,
+}) => {
+ if (hidden) {
+ return <></>;
+ }
+
+ return (
+ <Button.Group color={color}>
+ <ShrinkableButton
+ icon={icon}
+ onClick={onClick}
+ mediaQuery={mediaQuery}
+ disabled={disabled}
+ loading={loading}
+ >{children}</ShrinkableButton>
+ <Dropdown
+ disabled={disabled}
+ className='button icon'
+ options={options}
+ onChange={onChange}
+ trigger={<></>}
+ />
+ </Button.Group>
+ );
+}
+
+export default ShrinkableDropdownButton; \ No newline at end of file
diff --git a/src/web/src/components/Shared/index.js b/src/web/src/components/Shared/index.js
new file mode 100644
index 00000000..e9c9128d
--- /dev/null
+++ b/src/web/src/components/Shared/index.js
@@ -0,0 +1,10 @@
+export { default as CodeEditor } from './CodeEditor';
+export { default as Div } from './Div';
+export { default as ErrorSegment } from './ErrorSegment';
+export { default as FileList } from './FileList';
+export { default as LoaderSegment } from './LoaderSegment';
+export { default as Nbsp } from './Nbsp';
+export { default as PlaceholderSegment } from './PlaceholderSegment';
+export { default as ShrinkableButton } from './ShrinkableButton';
+export { default as ShrinkableDropdownButton } from './ShrinkableDropdownButton';
+export { default as Switch } from './Switch'; \ No newline at end of file
diff --git a/src/web/src/components/System/Info.js b/src/web/src/components/System/Info.js
index 655ac431..8991777b 100644
--- a/src/web/src/components/System/Info.js
+++ b/src/web/src/components/System/Info.js
@@ -22,7 +22,7 @@ const Info = ({ state }) => {
<div className='footer-buttons'>
<div style={{float: 'left'}}>
<ShrinkableButton
- iconName='refresh'
+ icon='refresh'
mediaQuery='(max-width: 516px)'
primary
onClick={() => getVersion({ forceCheck: true })}
@@ -33,7 +33,7 @@ const Info = ({ state }) => {
<Modal
trigger={
<ShrinkableButton
- iconName='shutdown'
+ icon='shutdown'
mediaQuery='(max-width: 516px)'
negative
>
@@ -49,7 +49,7 @@ const Info = ({ state }) => {
<Modal
trigger={
<ShrinkableButton
- iconName='redo'
+ icon='redo'
mediaQuery='(max-width: 516px)'
negative
>
diff --git a/src/web/src/components/Transfers/TransferGroup.js b/src/web/src/components/Transfers/TransferGroup.js
index 69b766a2..a8a2f627 100644
--- a/src/web/src/components/Transfers/TransferGroup.js
+++ b/src/web/src/components/Transfers/TransferGroup.js
@@ -50,12 +50,6 @@ class TransferGroup extends Component {
}
}
- isStateRetryable = (state) =>
- this.props.direction === 'download' && state.includes('Completed') && state !== 'Completed, Succeeded';
- isStateCancellable = (state) =>
- ['InProgress', 'Requested', 'Queued', 'Queued, Remotely', 'Queued, Locally', 'Initializing'].find(s => s === state);
- isStateRemovable = (state) => state.includes('Completed');
-
retryAll = async (selected) => {
await Promise.all(selected.map(file => this.retry(file)));
}
@@ -101,9 +95,9 @@ class TransferGroup extends Component {
const selected = this.getSelectedFiles();
const all = selected.length > 1 ? ' Selected' : '';
- const allRetryable = selected.filter(f => this.isStateRetryable(f.state)).length === selected.length;
- const anyCancellable = selected.filter(f => this.isStateCancellable(f.state)).length > 0;
- const allRemovable = selected.filter(f => this.isStateRemovable(f.state)).length === selected.length;
+ const allRetryable = selected.filter(f => transfers.isStateRetryable(f.state)).length === selected.length;
+ const anyCancellable = selected.filter(f => transfers.isStateCancellable(f.state)).length > 0;
+ const allRemovable = selected.filter(f => transfers.isStateRemovable(f.state)).length === selected.length;
return (
<Card key={user.username} className='transfer-card' raised>
@@ -151,7 +145,7 @@ class TransferGroup extends Component {
{(allRetryable || anyCancellable) && allRemovable && <Button.Or/>}
{allRemovable &&
<Button
- icon='delete'
+ icon='trash alternate'
content={`Remove${all}`}
onClick={() => this.removeAll(direction, user.username, selected)}
/>}
diff --git a/src/web/src/components/Transfers/Transfers.css b/src/web/src/components/Transfers/Transfers.css
new file mode 100644
index 00000000..88f9e736
--- /dev/null
+++ b/src/web/src/components/Transfers/Transfers.css
@@ -0,0 +1,52 @@
+.transfers-header-segment {
+ margin-top: 15px !important;
+ height: 78px !important;
+ padding-top: 20px !important;
+ display: flex;
+}
+
+.transfers-segment-icon {
+ padding-top: 5px;
+ padding-right: 1em;
+}
+
+.transfers-header-action-button {
+ float: right;
+ margin-top: -48px !important;
+}
+
+.transfer-button {
+ color: black;
+}
+
+.transfer-card {
+ width: 100% !important;
+ margin-left: auto !important;
+ margin-right: auto !important;
+}
+
+.transfer-segment {
+ margin-top: 16px;
+ padding-left: 15px;
+ padding-right: 15px;
+}
+
+.transfer-placeholder {
+ font-weight: 100;
+ text-align: center;
+ margin-top: 50px !important;
+}
+
+.transferlist-size {
+ width: 150px;
+ min-width: 150px;
+}
+
+.transferlist-filename {
+ word-wrap: break-word !important;
+}
+
+.transfers-header-buttons {
+ display: inline;
+ margin-left: auto;
+}
diff --git a/src/web/src/components/Transfers/Transfers.js b/src/web/src/components/Transfers/Transfers.js
index 76e73a53..30905f74 100644
--- a/src/web/src/components/Transfers/Transfers.js
+++ b/src/web/src/components/Transfers/Transfers.js
@@ -1,49 +1,155 @@
-import React, { Component } from 'react';
-import * as transfers from '../../lib/transfers';
-import PlaceholderSegment from '../Shared/PlaceholderSegment';
+import React, { useState, useEffect, useMemo } from 'react';
+import * as transfersLib from '../../lib/transfers';
+import { toast } from 'react-toastify';
+
+import {
+ LoaderSegment,
+ PlaceholderSegment,
+} from '../Shared';
import TransferGroup from './TransferGroup';
+import TransfersHeader from './TransfersHeader';
+
+import './Transfers.css';
+
+const Transfers = ({ direction, server }) => {
+ const [connecting, setConnecting] = useState(true);
+ const [transfers, setTransfers] = useState([]);
+
+ const [retrying, setRetrying] = useState(false);
+ const [cancelling, setCancelling] = useState(false);
+ const [removing, setRemoving] = useState(false);
+
+ useEffect(() => {
+ setConnecting(true);
+
+ const init = async () => {
+ await fetch();
+ setConnecting(false);
+ }
+
+ init();
+ const interval = window.setInterval(fetch, 1000);
+
+ return () => {
+ clearInterval(interval);
+ }
+ }, [direction]); // eslint-disable-line react-hooks/exhaustive-deps
+
+ useMemo(() => {
+ // this is used to prevent weird update issues if switching
+ // between uploads and downloads. useEffect fires _after_ the
+ // prop 'direction' updates, meaning there's a flash where the
+ // screen contents switch to the new direction for a brief moment
+ // before the connecting animation shows. this memo fires the instant
+ // the direction prop changes, preventing this flash.
+ setConnecting(true);
+ }, [direction]); // eslint-disable-line react-hooks/exhaustive-deps
+
+ const fetch = async () => {
+ try {
+ const response = await transfersLib.getAll({ direction });
+ setTransfers(response);
+ } catch (error) {
+ console.error(error);
+ toast.error(error?.response?.data ?? error?.message ?? error);
+ }
+ }
+
+ const retry = async ({ file, suppressStateChange = false }) => {
+ const { username, filename, size } = file;
+
+ try {
+ if (!suppressStateChange) setRetrying(true);
+ await transfersLib.download({username, files: [{filename, size }] });
+ if (!suppressStateChange) setRetrying(false);
+ } catch (error) {
+ console.log(error);
+ toast.error(error?.response?.data ?? error?.message ?? error);
+ if (!suppressStateChange) setRetrying(false);
+ }
+ }
-class Transfers extends Component {
- state = { fetchState: '', downloads: [], interval: undefined }
-
- componentDidMount = () => {
- this.fetch();
- this.setState({ interval: window.setInterval(this.fetch, 500) });
- }
-
- componentWillUnmount = () => {
- clearInterval(this.state.interval);
- this.setState({ interval: undefined });
- }
-
- fetch = () => {
- this.setState({ fetchState: 'pending' }, async () => {
- try {
- const response = await transfers.getAll({ direction: this.props.direction })
- this.setState({
- fetchState: 'complete', downloads: response,
- })
- } catch (err) {
- this.setState({ fetchState: 'failed' })
- }
- })
- }
-
- render = () => {
- const { downloads = [] } = this.state;
- const { direction } = this.props;
-
- return (
- downloads.length === 0 ?
- <PlaceholderSegment icon={direction}/> :
- <div className='transfer-segment'>
- {downloads.map((user, index) =>
- <TransferGroup key={index} direction={this.props.direction} user={user}/>
- )}
- </div>
- );
+ const retryAll = async (transfers) => {
+ setRetrying(true);
+ await Promise.all(transfers.map(file => retry({ file, suppressStateChange: true })))
+ setRetrying(false);
}
+
+ const cancel = async ({ file, suppressStateChange = false }) => {
+ const { username, id } = file;
+
+ try {
+ if (!suppressStateChange) setCancelling(true);
+ await transfersLib.cancel({ direction, username, id });
+ if (!suppressStateChange) setCancelling(false);
+ } catch (error) {
+ console.log(error);
+ toast.error(error?.response?.data ?? error?.message ?? error);
+ if (!suppressStateChange) setCancelling(false);
+ }
+ }
+
+ const cancelAll = async (transfers) => {
+ setCancelling(true);
+ await Promise.all(transfers.map(file => cancel({ file, suppressStateChange: true })));
+ setCancelling(false);
+ }
+
+ const remove = async ({ file, suppressStateChange = false }) => {
+ const { username, id } = file;
+
+ try {
+ if (!suppressStateChange) setRemoving(true);
+ await transfersLib.cancel({ direction, username, id, remove: true });
+ if (!suppressStateChange) setRemoving(false);
+ } catch (error) {
+ console.log(error);
+ toast.error(error?.response?.data ?? error?.message ?? error);
+ if (!suppressStateChange) setRemoving(false);
+ }
+ }
+
+ const removeAll = async (transfers) => {
+ setRemoving(true);
+ await Promise.all(transfers.map(file => remove({ file, suppressStateChange: true })));
+ setRemoving(false);
+ }
+
+ if (connecting) {
+ return <LoaderSegment/>
+ }
+
+ return (
+ <>
+ <TransfersHeader
+ direction={direction}
+ transfers={transfers}
+ server={server}
+ onRetryAll={retryAll}
+ retrying={retrying}
+ onCancelAll={cancelAll}
+ cancelling={cancelling}
+ onRemoveAll={removeAll}
+ removing={removing}
+ />
+ {transfers.length === 0
+ ? <PlaceholderSegment icon={direction} caption={`No ${direction}s to display`}/>
+ : transfers.map((user, index) =>
+ <TransferGroup
+ key={index}
+ direction={direction}
+ user={user}
+ retry={retry}
+ retryAll={retryAll}
+ cancel={cancel}
+ cancelAll={cancelAll}
+ remove={remove}
+ removeAll={removeAll}
+ />
+ )}
+ </>
+ );
}
export default Transfers; \ No newline at end of file
diff --git a/src/web/src/components/Transfers/TransfersHeader.js b/src/web/src/components/Transfers/TransfersHeader.js
new file mode 100644
index 00000000..d3ef383b
--- /dev/null
+++ b/src/web/src/components/Transfers/TransfersHeader.js
@@ -0,0 +1,155 @@
+import React, { useState, useMemo } from 'react';
+
+import {
+ Segment,
+ Icon,
+} from 'semantic-ui-react';
+
+import {
+ Div,
+ Nbsp,
+} from '../Shared';
+
+import ShrinkableDropdownButton from '../Shared/ShrinkableDropdownButton';
+import { isStateCancellable, isStateRetryable } from '../../lib/transfers';
+
+const getRetryableFiles = ({ files, retryOption }) => {
+ switch (retryOption) {
+ case 'Errored':
+ return files.filter(file =>
+ ['Completed, TimedOut',
+ 'Completed, Errored',
+ 'Completed, Rejected'].includes(file.state));
+ case 'Cancelled':
+ return files.filter(file => file.state === 'Completed, Cancelled');
+ case 'All':
+ return files.filter(file => isStateRetryable(file.state));
+ default:
+ return [];
+ }
+}
+
+const getCancellableFiles = ({ files, cancelOption }) => {
+ switch (cancelOption) {
+ case 'All':
+ return files.filter(file => isStateCancellable(file.state));
+ case 'Queued':
+ return files.filter(file => ['Queued, Locally', 'Queued, Remotely'].includes(file.state));
+ case 'In Progress':
+ return files.filter(file => file.state === 'InProgress')
+ default:
+ return [];
+ }
+}
+
+const getRemovableFiles = ({ files, removeOption }) => {
+ switch (removeOption) {
+ case 'Succeeded':
+ return files.filter(file => file.state === 'Completed, Succeeded');
+ case 'Errored':
+ return files.filter(file =>
+ ['Completed, TimedOut',
+ 'Completed, Errored',
+ 'Completed, Rejected'].includes(file.state));
+ case 'Cancelled':
+ return files.filter(file => file.state === 'Completed, Cancelled');
+ case 'Completed':
+ return files.filter(file => file.state.includes('Completed'));
+ default:
+ return [];
+ }
+}
+
+const TransfersHeader = ({
+ direction,
+ transfers,
+ server = { isConnected: true },
+ onRetryAll,
+ retrying = false,
+ onCancelAll,
+ cancelling = false,
+ onRemoveAll,
+ removing = false,
+}) => {
+ const [removeOption, setRemoveOption] = useState('Succeeded');
+ const [cancelOption, setCancelOption] = useState('All');
+ const [retryOption, setRetryOption] = useState('Errored');
+
+ const files = useMemo(() => {
+ const files = transfers.reduce((acc, username) => {
+ const allUserFiles = username.directories.reduce((acc, directory) => {
+ acc = acc.concat(directory.files);
+ return acc;
+ }, []);
+
+ acc = acc.concat(allUserFiles)
+ return acc;
+ }, []);
+
+ return files.filter(file => file.direction.toLowerCase() === direction);
+ }, [transfers, direction]);
+
+ const empty = files.length === 0;
+ const working = retrying || cancelling || removing;
+
+ return (
+ <Segment className='transfers-header-segment' raised>
+ <div className="transfers-segment-icon"><Icon name={direction} size="big"/></div>
+ <Div hidden={empty} className="transfers-header-buttons">
+ <ShrinkableDropdownButton
+ hidden={direction === 'upload'}
+ color='green'
+ icon='redo'
+ mediaQuery='(max-width: 715px)'
+ onClick={() => onRetryAll(getRetryableFiles({ files, retryOption }))}
+ disabled={working || empty || !server.isConnected}
+ loading={retrying}
+ options={[
+ { key: 'errored', text: 'Errored', value: 'Errored' },
+ { key: 'cancelled', text: 'Cancelled', value: 'Cancelled' },
+ { key: 'all', text: 'All', value: 'All' },
+ ]}
+ onChange={(_, data) => setRetryOption(data.value)}
+ >
+ {`Retry ${retryOption === 'All' ? retryOption : `All ${retryOption}`}`}
+ </ShrinkableDropdownButton>
+ <Nbsp/>
+ <ShrinkableDropdownButton
+ color='red'
+ icon='x'
+ mediaQuery='(max-width: 715px)'
+ onClick={() => onCancelAll(getCancellableFiles({ files, cancelOption }))}
+ disabled={working || empty}
+ loading={cancelling}
+ options={[
+ { key: 'all', text: 'All', value: 'All' },
+ { key: 'queued', text: 'Queued', value: 'Queued' },
+ { key: 'inProgress', text: 'In Progress', value: 'In Progress' },
+ ]}
+ onChange={(_, data) => setCancelOption(data.value)}
+ >
+ {`Cancel ${cancelOption === 'All' ? cancelOption : `All ${cancelOption}`}`}
+ </ShrinkableDropdownButton>
+ <Nbsp/>
+ <ShrinkableDropdownButton
+ icon='trash alternate'
+ mediaQuery='(max-width: 715px)'
+ onClick={() => onRemoveAll(getRemovableFiles({ files, removeOption }))}
+ disabled={working || empty}
+ loading={removing}
+ options={[
+ { key: 'succeeded', text: 'Succeeded', value: 'Succeeded' },
+ { key: 'errored', text: 'Errored', value: 'Errored' },
+ { key: 'cancelled', text: 'Cancelled', value: 'Cancelled' },
+ { key: 'completed', text: 'Completed', value: 'Completed' },
+ ]}
+ onChange={(_, data) => setRemoveOption(data.value)}
+ >
+ {`Remove All ${removeOption}`}
+ </ShrinkableDropdownButton>
+ </Div>
+ </Segment>
+ )
+};
+
+export default TransfersHeader; \ No newline at end of file
diff --git a/src/web/src/components/Users/Users.css b/src/web/src/components/Users/Users.css
index 29e31f48..c9244834 100644
--- a/src/web/src/components/Users/Users.css
+++ b/src/web/src/components/Users/Users.css
@@ -10,9 +10,15 @@
margin-bottom: 17px;
}
-.users-selection {
+.users-segment {
margin-top: 15px !important;
height: 78px !important;
+ display: flex;
+}
+
+.users-segment-icon {
+ padding-top: 10px;
+ padding-right: .5em;
}
.users-input {
diff --git a/src/web/src/components/Users/Users.js b/src/web/src/components/Users/Users.js
index 71084bcb..6478f2be 100644
--- a/src/web/src/components/Users/Users.js
+++ b/src/web/src/components/Users/Users.js
@@ -4,6 +4,7 @@ import {
Segment,
Loader,
Input,
+ Icon,
} from 'semantic-ui-react';
import User from './User';
@@ -81,7 +82,8 @@ const Users = (props) => {
return (
<div className='users-container'>
- <Segment className='users-selection' raised>
+ <Segment className='users-segment' raised>
+ <div className="users-segment-icon"><Icon name="users" size="big"/></div>
<Input
input={
<input placeholder="Username" type="search" data-lpignore="true" disabled={!!user || fetching}></input>}
@@ -104,7 +106,7 @@ const Users = (props) => {
{error ?
<span>Failed to retrieve information for {selectedUsername}</span> :
!user ?
- <PlaceholderSegment icon='users'/> :
+ <PlaceholderSegment icon='users' caption='No user info to display'/> :
<Segment className='users-user' raised>
<Item.Group>
<User {...user}/>
diff --git a/src/web/src/lib/transfers.js b/src/web/src/lib/transfers.js
index 1d9da319..4a6eec5e 100644
--- a/src/web/src/lib/transfers.js
+++ b/src/web/src/lib/transfers.js
@@ -19,6 +19,25 @@ export const cancel = ({ direction, username, id, remove = false }) => {
return api.delete(`/transfers/${direction}s/${username}/${id}?remove=${remove}`);
};
+// 'Requested'
+// 'Queued, Remotely'
+// 'Queued, Locally'
+// 'Initializing'
+// 'InProgress'
+// 'Completed, Succeeded'
+// 'Completed, Cancelled'
+// 'Completed, TimedOut'
+// 'Completed, Errored'
+// 'Completed, Rejected'
+
export const getPlaceInQueue = ({ username, id }) => {
return api.get(`/transfers/downloads/${username}/${id}`);
-}; \ No newline at end of file
+};
+
+export const isStateRetryable = (state) =>
+ state.includes('Completed') && state !== 'Completed, Succeeded';
+
+export const isStateCancellable = (state) =>
+ ['InProgress', 'Requested', 'Queued', 'Queued, Remotely', 'Queued, Locally', 'Initializing'].find(s => s === state);
+
+export const isStateRemovable = (state) => state.includes('Completed');