mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
feature (links): leverage default browser navigation and behavior for links #27,#26
This commit is contained in:
parent
c9c4ee1639
commit
d88c845a06
2 changed files with 33 additions and 30 deletions
|
|
@ -55,34 +55,39 @@ export class FilesPage extends React.Component {
|
|||
if(this.observers.ls) this.observers.ls.unsubscribe();
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps){
|
||||
let new_path = function(path){
|
||||
if(path === undefined){ path = "/"; }
|
||||
if(/\/$/.test(path) === false){ path = path + "/"; }
|
||||
if(/^\//.test(path) === false){ path = "/"+ path; }
|
||||
return path;
|
||||
}(nextProps.match.params.path);
|
||||
if(new_path !== this.state.path){
|
||||
this.setState({path: new_path, loading: true});
|
||||
this.onRefresh(new_path);
|
||||
}
|
||||
}
|
||||
|
||||
hideError(){
|
||||
this.setState({error: false});
|
||||
}
|
||||
|
||||
onRefresh(path = this.state.path){
|
||||
this.resetHeight();
|
||||
if(this.observers.ls) this.observers.ls.unsubscribe();
|
||||
this.observers.ls = Files.ls(path).subscribe((files) => {
|
||||
this.setState({files: files, loading: false})
|
||||
files = files.map((file) => {
|
||||
let path = this.state.path+file.name;
|
||||
file.link = file.type === "file" ? "/view"+path : "/files"+path+"/";
|
||||
return file;
|
||||
});
|
||||
this.setState({files: files, loading: false});
|
||||
}, (error) => {
|
||||
console.log("ERROR", error);
|
||||
this.setState({error: error});
|
||||
});
|
||||
this.setState({error: false});
|
||||
}
|
||||
|
||||
onPathUpdate(path, type = 'directory'){
|
||||
window.timestamp = new Date();
|
||||
if(type === 'file'){
|
||||
this.props.history.push('/view'+path);
|
||||
}else{
|
||||
this.setState({path: path, loading: true});
|
||||
this.onRefresh(path)
|
||||
if(path !== this.state.path){
|
||||
this.props.history.push('/files'+path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onCreate(path, type, file){
|
||||
if(type === 'file'){
|
||||
return Files.touch(path, file);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { DragSource, DropTarget } from 'react-dnd';
|
||||
|
||||
import './thing.scss';
|
||||
import { Card, NgIf, Icon, EventEmitter, Prompt } from '../../components/';
|
||||
import { pathBuilder } from '../../helpers/';
|
||||
import { Card, NgIf, Icon, EventEmitter } from '../../components/';
|
||||
import { pathBuilder, prompt } from '../../helpers/';
|
||||
|
||||
const fileSource = {
|
||||
beginDrag(props, monitor, component) {
|
||||
|
|
@ -146,19 +147,16 @@ export class ExistingThing extends React.Component {
|
|||
|
||||
return connectDragSource(connectDropNativeFile(connectDropFile(
|
||||
<div className="component_thing">
|
||||
<Link to={this.props.file.link}>
|
||||
<Card className={this.state.hover} onClick={this.onSelect.bind(this)} onMouseEnter={() => this.setState({hover: true})} onMouseLeave={() => this.setState({hover: false})} className={className}>
|
||||
<DateTime show={this.state.hover !== true || this.state.icon === 'loading'} timestamp={this.props.file.time} />
|
||||
<Updater filename={this.props.file.name}
|
||||
icon={this.props.file.icon || this.props.file.type}
|
||||
can_move={this.props.file.can_move !== false}
|
||||
can_delete={this.props.file.can_delete !== false}
|
||||
show={this.state.hover === true && this.state.icon !== 'loading' && !('ontouchstart' in window)}
|
||||
onRename={this.onRename.bind(this)}
|
||||
onDelete={this.onDeleteRequest.bind(this)} />
|
||||
<Icon name={this.props.file.icon || this.props.file.type} />
|
||||
<Filename filename={this.props.file.name} onRename={this.onRename.bind(this)} is_renaming={this.state.is_renaming} />
|
||||
<FileSize type={this.props.file.type} size={this.props.file.size} />
|
||||
<Message message={this.state.message} />
|
||||
<DateTime show={this.state.icon !== 'loading'} timestamp={this.props.file.time} />
|
||||
<ActionButton onClickRename={this.onRenameRequest.bind(this)} onClickDelete={this.onDeleteRequest.bind(this)} can_move={this.props.file.can_move !== false} can_delete={this.props.file.can_delete !== false} />
|
||||
</Card>
|
||||
<Prompt appear={this.state.delete_request} error={this.state.delete_error} message={this.state.delete_message} onCancel={this.onDeleteCancel.bind(this)} onSubmit={this.onDeleteConfirm.bind(this)}/>
|
||||
</Link>
|
||||
</div>
|
||||
)));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue