Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

File drop UI fixes and improvements #5505

Merged
merged 37 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
89bc443
Fix file drop UI
SimonBrandner Dec 16, 2020
41e2ffd
Added background
SimonBrandner Dec 16, 2020
da97d18
Added a comment
SimonBrandner Dec 16, 2020
dcb30b7
Fix left panel resizer
SimonBrandner Dec 17, 2020
e70dee0
Fix flickering
SimonBrandner Dec 17, 2020
044e02b
Remove spaces in empty line
SimonBrandner Dec 17, 2020
bebbb3b
Merge branch 'develop' into improve-file-drop-ui
SimonBrandner Dec 17, 2020
365d252
Fix removing event listeners
SimonBrandner Dec 17, 2020
5d7e45e
Added dragCounter
SimonBrandner Dec 17, 2020
c1a105f
Merge branch 'develop' into improve-file-drop-ui
SimonBrandner Feb 25, 2021
ad85764
Fix timeline expansion
SimonBrandner Feb 25, 2021
aa4ec9f
Make $droptarget-bg-color more opaque
SimonBrandner Feb 25, 2021
8551855
Add $droptarget-bg-color to the dark theme
SimonBrandner Feb 25, 2021
a3001f7
Remove rounded corners of the drop area
SimonBrandner Feb 25, 2021
26b70b6
Remove label background
SimonBrandner Feb 25, 2021
6a7340e
Use new upload icon
SimonBrandner Feb 25, 2021
1c48804
Remove unnecessary class
SimonBrandner Feb 25, 2021
43e1144
Don't use TintableSVG
SimonBrandner Feb 25, 2021
7277c28
Fix weird crash
SimonBrandner Feb 25, 2021
49ea9a4
Remove sdk import
SimonBrandner Feb 25, 2021
1a7f909
Animate icon size
SimonBrandner Feb 26, 2021
f0c2684
Fix formatting
SimonBrandner Feb 26, 2021
172cc01
Add background animation
SimonBrandner Feb 26, 2021
3e0558f
Remove droptarget colors
SimonBrandner Feb 26, 2021
49ea83e
i18n
SimonBrandner Feb 26, 2021
e90ae2e
Delint
SimonBrandner Feb 26, 2021
819a0b0
min-width
SimonBrandner Feb 26, 2021
0d6a9fc
Remove weird styling
SimonBrandner Feb 26, 2021
11c5aa0
Remove mx_RoomView_container
SimonBrandner Feb 26, 2021
9a5ba07
Fix auxPanel
SimonBrandner Feb 26, 2021
3bed374
Remove unnecessary code
SimonBrandner Feb 26, 2021
3a643e5
Remove unnecessary changes
SimonBrandner Feb 26, 2021
ebedd3c
Remove space
SimonBrandner Mar 2, 2021
ff00683
Use ===
SimonBrandner Mar 2, 2021
0a4c0b6
Move fileDropTarget to RoomView
SimonBrandner Mar 2, 2021
4476843
Remove unused _t
SimonBrandner Mar 2, 2021
831cc7e
i18n
SimonBrandner Mar 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/css/structures/_MainSplit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
display: flex;
flex-direction: row;
min-width: 0;
min-height: 0;
height: 100%;
}

Expand Down
52 changes: 35 additions & 17 deletions res/css/structures/_RoomView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,54 @@ limitations under the License.
flex-direction: column;
}


@keyframes mx_RoomView_fileDropTarget_animation {
from {
opacity: 0;
}
to {
opacity: 0.95;
}
}

.mx_RoomView_fileDropTarget {
min-width: 0px;
width: 100%;
height: 100%;

font-size: $font-18px;
text-align: center;

pointer-events: none;

padding-left: 12px;
padding-right: 12px;
margin-left: -12px;

border-top-left-radius: 10px;
border-top-right-radius: 10px;
background-color: $primary-bg-color;
opacity: 0.95;

background-color: $droptarget-bg-color;
border: 2px #e1dddd solid;
border-bottom: none;
position: absolute;
top: 52px;
bottom: 0px;
z-index: 3000;

display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

animation: mx_RoomView_fileDropTarget_animation;
animation-duration: 0.5s;
}

.mx_RoomView_fileDropTargetLabel {
top: 50%;
width: 100%;
margin-top: -50px;
position: absolute;
@keyframes mx_RoomView_fileDropTarget_image_animation {
from {
width: 0px;
}
to {
width: 32px;
}
}

.mx_RoomView_fileDropTarget_image {
animation: mx_RoomView_fileDropTarget_image_animation;
animation-duration: 0.5s;
margin-bottom: 16px;
}

.mx_RoomView_auxPanel {
Expand Down Expand Up @@ -117,7 +136,6 @@ limitations under the License.
}

.mx_RoomView_body {
position: relative; //for .mx_RoomView_auxPanel_fullHeight
display: flex;
flex-direction: column;
flex: 1;
Expand Down
20 changes: 2 additions & 18 deletions res/img/upload-big.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions res/themes/light/css/_light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ $groupFilterPanel-bg-color: rgba(232, 232, 232, 0.77);
// used by RoomDirectory permissions
$plinth-bg-color: $secondary-accent-color;

// used by RoomDropTarget
$droptarget-bg-color: rgba(255,255,255,0.5);

// used by AddressSelector
$selected-color: $secondary-accent-color;

Expand Down
61 changes: 49 additions & 12 deletions src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export interface IState {
rejecting?: boolean;
rejectError?: Error;
hasPinnedWidgets?: boolean;
dragCounter: number;
}

export default class RoomView extends React.Component<IProps, IState> {
Expand Down Expand Up @@ -239,6 +240,7 @@ export default class RoomView extends React.Component<IProps, IState> {
canReply: false,
layout: SettingsStore.getValue("layout"),
matrixClientIsReady: this.context && this.context.isInitialSyncComplete(),
dragCounter: 0,
};

this.dispatcherRef = dis.register(this.onAction);
Expand Down Expand Up @@ -533,8 +535,8 @@ export default class RoomView extends React.Component<IProps, IState> {
if (!roomView.ondrop) {
roomView.addEventListener('drop', this.onDrop);
roomView.addEventListener('dragover', this.onDragOver);
roomView.addEventListener('dragleave', this.onDragLeaveOrEnd);
roomView.addEventListener('dragend', this.onDragLeaveOrEnd);
roomView.addEventListener('dragenter', this.onDragEnter);
roomView.addEventListener('dragleave', this.onDragLeave);
}
}

Expand Down Expand Up @@ -578,8 +580,8 @@ export default class RoomView extends React.Component<IProps, IState> {
const roomView = this.roomView.current;
roomView.removeEventListener('drop', this.onDrop);
roomView.removeEventListener('dragover', this.onDragOver);
roomView.removeEventListener('dragleave', this.onDragLeaveOrEnd);
roomView.removeEventListener('dragend', this.onDragLeaveOrEnd);
roomView.removeEventListener('dragenter', this.onDragEnter);
roomView.removeEventListener('dragleave', this.onDragLeave);
}
dis.unregister(this.dispatcherRef);
if (this.context) {
Expand Down Expand Up @@ -1139,14 +1141,38 @@ export default class RoomView extends React.Component<IProps, IState> {
this.updateTopUnreadMessagesBar();
};

private onDragEnter = ev => {
ev.stopPropagation();
ev.preventDefault();

this.setState({
dragCounter: this.state.dragCounter + 1,
draggingFile: true,
});
};

private onDragLeave = ev => {
ev.stopPropagation();
ev.preventDefault();

this.setState({
dragCounter: this.state.dragCounter - 1,
});

if (this.state.dragCounter === 0) {
this.setState({
draggingFile: false,
});
}
};

private onDragOver = ev => {
ev.stopPropagation();
ev.preventDefault();

ev.dataTransfer.dropEffect = 'none';

if (ev.dataTransfer.types.includes("Files") || ev.dataTransfer.types.includes("application/x-moz-file")) {
this.setState({ draggingFile: true });
ev.dataTransfer.dropEffect = 'copy';
}
};
Expand All @@ -1157,14 +1183,12 @@ export default class RoomView extends React.Component<IProps, IState> {
ContentMessages.sharedInstance().sendContentListToRoom(
ev.dataTransfer.files, this.state.room.roomId, this.context,
);
this.setState({ draggingFile: false });
dis.fire(Action.FocusComposer);
};

private onDragLeaveOrEnd = ev => {
ev.stopPropagation();
ev.preventDefault();
this.setState({ draggingFile: false });
this.setState({
draggingFile: false,
dragCounter: this.state.dragCounter - 1,
});
};

private injectSticker(url, info, text) {
Expand Down Expand Up @@ -1758,6 +1782,19 @@ export default class RoomView extends React.Component<IProps, IState> {
}
}

let fileDropTarget = null;
if (this.state.draggingFile) {
fileDropTarget = (
<div className="mx_RoomView_fileDropTarget">
<img
src={require("../../../res/img/upload-big.svg")}
className="mx_RoomView_fileDropTarget_image"
/>
{ _t("Drop file here to upload") }
</div>
);
}

// We have successfully loaded this room, and are not previewing.
// Display the "normal" room view.

Expand Down Expand Up @@ -1869,7 +1906,6 @@ export default class RoomView extends React.Component<IProps, IState> {
room={this.state.room}
fullHeight={false}
userId={this.context.credentials.userId}
draggingFile={this.state.draggingFile}
maxHeight={this.state.auxPanelMaxHeight}
showApps={this.state.showApps}
onResize={this.onResize}
Expand Down Expand Up @@ -2037,6 +2073,7 @@ export default class RoomView extends React.Component<IProps, IState> {
<div className="mx_RoomView_body">
{auxPanel}
<div className={timelineClasses}>
{fileDropTarget}
{topUnreadMessagesBar}
{jumpToBottom}
{messagePanel}
Expand Down
21 changes: 0 additions & 21 deletions src/components/views/rooms/AuxPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ limitations under the License.
import React from 'react';
import {MatrixClientPeg} from "../../../MatrixClientPeg";
import { Room } from 'matrix-js-sdk/src/models/room'
import * as sdk from '../../../index';
import dis from "../../../dispatcher/dispatcher";
import * as ObjectUtils from '../../../ObjectUtils';
import AppsDrawer from './AppsDrawer';
import { _t } from '../../../languageHandler';
import classNames from 'classnames';
import RateLimitedFunc from '../../../ratelimitedfunc';
import SettingsStore from "../../../settings/SettingsStore";
Expand All @@ -36,9 +34,6 @@ interface IProps {
userId: string,
showApps: boolean, // Render apps

// set to true to show the file drop target
draggingFile: boolean,

// maxHeight attribute for the aux panel and the video
// therein
maxHeight: number,
Expand Down Expand Up @@ -150,21 +145,6 @@ export default class AuxPanel extends React.Component<IProps, IState> {
}

render() {
const TintableSvg = sdk.getComponent("elements.TintableSvg");

let fileDropTarget = null;
if (this.props.draggingFile) {
fileDropTarget = (
<div className="mx_RoomView_fileDropTarget">
<div className="mx_RoomView_fileDropTargetLabel" title={_t("Drop File Here")}>
<TintableSvg src={require("../../../../res/img/upload-big.svg")} width="45" height="59" />
<br />
{ _t("Drop file here to upload") }
</div>
</div>
);
}

const callView = (
<CallViewForRoom
roomId={this.props.room.roomId}
Expand Down Expand Up @@ -247,7 +227,6 @@ export default class AuxPanel extends React.Component<IProps, IState> {
<AutoHideScrollbar className={classes} style={style} >
{ stateViews }
{ appsDrawer }
{ fileDropTarget }
{ callView }
{ this.props.children }
</AutoHideScrollbar>
Expand Down
1 change: 1 addition & 0 deletions src/contexts/RoomContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const RoomContext = createContext<IState>({
canReply: false,
layout: Layout.Group,
matrixClientIsReady: false,
dragCounter: 0,
Copy link
Contributor Author

@SimonBrandner SimonBrandner Dec 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not necessary here? But there is draggingFile: false, is that intentional?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly worried that counting enters/leaves will cause problems and desync (there's a ton of ways to leave a browser window without triggering a dragleave event, making you always +1)

Can we get away with a simple isDragging instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is the only solution I've found... I don't think I quite understand what you mean by isDragging here. There seems to be a isDragging method in react-dnd but I don't think this can be used here. What am I missing?

});
RoomContext.displayName = "RoomContext";
export default RoomContext;
3 changes: 1 addition & 2 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1381,8 +1381,6 @@
"Remove %(phone)s?": "Remove %(phone)s?",
"A text message has been sent to +%(msisdn)s. Please enter the verification code it contains.": "A text message has been sent to +%(msisdn)s. Please enter the verification code it contains.",
"Phone Number": "Phone Number",
"Drop File Here": "Drop File Here",
"Drop file here to upload": "Drop file here to upload",
"This user has not verified all of their sessions.": "This user has not verified all of their sessions.",
"You have not verified this user.": "You have not verified this user.",
"You have verified this user. This user has verified all of their sessions.": "You have verified this user. This user has verified all of their sessions.",
Expand Down Expand Up @@ -2514,6 +2512,7 @@
"No more results": "No more results",
"Room": "Room",
"Failed to reject invite": "Failed to reject invite",
"Drop file here to upload": "Drop file here to upload",
"You have %(count)s unread notifications in a prior version of this room.|other": "You have %(count)s unread notifications in a prior version of this room.",
"You have %(count)s unread notifications in a prior version of this room.|one": "You have %(count)s unread notification in a prior version of this room.",
"Tried to load a specific point in this room's timeline, but you do not have permission to view the message in question.": "Tried to load a specific point in this room's timeline, but you do not have permission to view the message in question.",
Expand Down