mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
basic UI for row editing
This commit is contained in:
parent
3ea920c1f8
commit
32e1b4c3fd
13 changed files with 248 additions and 65 deletions
|
@ -4,7 +4,6 @@ import classnames from 'classnames';
|
|||
|
||||
type Props = {
|
||||
active: Boolean,
|
||||
|
||||
onPress: Function,
|
||||
}
|
||||
export const Switch = ({ active, onPress = () => {} }: Props) => (
|
||||
|
|
|
@ -28,8 +28,11 @@ type Props = {
|
|||
author: String,
|
||||
distance: Array<Number>,
|
||||
tab: Array<string>,
|
||||
}
|
||||
min: number,
|
||||
max: number,
|
||||
},
|
||||
},
|
||||
marks: { [x: number]: string },
|
||||
editing: Boolean,
|
||||
routes_sorted: Array<string>,
|
||||
|
||||
|
@ -39,7 +42,18 @@ type Props = {
|
|||
setDialogActive: Function,
|
||||
};
|
||||
|
||||
class Component extends React.Component<Props> {
|
||||
type State = {
|
||||
editing_item: ?string,
|
||||
}
|
||||
|
||||
class Component extends React.Component<Props, State> {
|
||||
state = {
|
||||
editing_item: null,
|
||||
};
|
||||
|
||||
startEditing = editing_item => this.setState({ editing_item });
|
||||
stopEditing = () => this.setState({ editing_item: null });
|
||||
|
||||
setTitle = ({ target: { value } }) => {
|
||||
this.props.searchSetTitle(value);
|
||||
};
|
||||
|
@ -67,6 +81,8 @@ class Component extends React.Component<Props> {
|
|||
marks,
|
||||
} = this.props;
|
||||
|
||||
const { editing_item } = this.state;
|
||||
|
||||
return (
|
||||
<div className="dialog-content">
|
||||
{ list.length === 0 && loading &&
|
||||
|
@ -136,9 +152,12 @@ class Component extends React.Component<Props> {
|
|||
<RouteRow
|
||||
editing={editing}
|
||||
{...route}
|
||||
key={route._id}
|
||||
openRoute={this.openRoute}
|
||||
tab={tab}
|
||||
is_editing={(editing_item === route._id)}
|
||||
startEditing={this.startEditing}
|
||||
stopEditing={this.stopEditing}
|
||||
key={route._id}
|
||||
/>
|
||||
))
|
||||
}
|
||||
|
|
|
@ -1,41 +1,67 @@
|
|||
// @flow
|
||||
import React from 'react';
|
||||
import { Icon } from '$components/panels/Icon';
|
||||
import classnames from 'classnames';
|
||||
import { RouteRowEditor } from '$components/maps/RouteRowEditor';
|
||||
|
||||
type Props = {
|
||||
title: String,
|
||||
distance: Number,
|
||||
created_at: String,
|
||||
_id: String,
|
||||
editing: Boolean,
|
||||
_id: string,
|
||||
title: string,
|
||||
distance: number,
|
||||
tab: string,
|
||||
is_editing: boolean,
|
||||
is_public: boolean,
|
||||
|
||||
openRoute: Function,
|
||||
|
||||
openRoute: (_id: string) => {},
|
||||
startEditing: (_id: string) => {},
|
||||
stopEditing: () => {},
|
||||
};
|
||||
|
||||
export const RouteRow = ({
|
||||
title, distance, _id, openRoute, tab,
|
||||
title, distance, _id, openRoute, tab, is_editing, startEditing, stopEditing, is_public
|
||||
}: Props) => (
|
||||
<div className="route-row-wrapper">
|
||||
<div
|
||||
className="route-row"
|
||||
onClick={() => openRoute(_id)}
|
||||
>
|
||||
<div className="route-row-edit">
|
||||
<div className={classnames('route-row-wrapper', { is_editing })}>
|
||||
{
|
||||
tab === 'mine' &&
|
||||
<div className="route-row-edit" onClick={() => startEditing(_id)}>
|
||||
<Icon icon="icon-edit-1" />
|
||||
</div>
|
||||
<div className="route-title">
|
||||
{title || _id}
|
||||
</div>
|
||||
<div className="route-description">
|
||||
<span>
|
||||
<Icon icon="icon-link-1" />
|
||||
{_id}
|
||||
</span>
|
||||
<span>
|
||||
<Icon icon="icon-cycle-1" />
|
||||
{(distance && `${distance} km`) || '0 km'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
{
|
||||
!is_editing
|
||||
?
|
||||
<div
|
||||
className="route-row"
|
||||
>
|
||||
<div onClick={() => openRoute(_id)}>
|
||||
<div className="route-title">
|
||||
<span>{(title || _id)}</span>
|
||||
</div>
|
||||
<div className="route-description">
|
||||
<span>
|
||||
<Icon icon="icon-link-1" />
|
||||
{_id}
|
||||
</span>
|
||||
<span>
|
||||
<Icon icon="icon-cycle-1" />
|
||||
{(distance && `${distance} km`) || '0 km'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="route-row-panel">
|
||||
<div className="">
|
||||
<Icon icon="icon-trash-4" size={24} />
|
||||
Удалить
|
||||
</div>
|
||||
<div className="flex_1 justify-end" onClick={() => startEditing(_id)}>
|
||||
<Icon icon="icon-edit-1" size={24} />
|
||||
Правка
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
: <RouteRowEditor title={title} is_public={is_public} distance={distance} _id={_id} />
|
||||
}
|
||||
|
||||
</div>
|
||||
);
|
||||
|
|
81
src/components/maps/RouteRowEditor.jsx
Normal file
81
src/components/maps/RouteRowEditor.jsx
Normal file
|
@ -0,0 +1,81 @@
|
|||
// @flow
|
||||
import React from 'react';
|
||||
import { Icon } from '$components/panels/Icon';
|
||||
import { Switch } from '$components/Switch';
|
||||
|
||||
type Props = {
|
||||
title: string,
|
||||
is_public: boolean,
|
||||
distance: number,
|
||||
_id: string,
|
||||
};
|
||||
|
||||
type State = {
|
||||
title: string,
|
||||
is_public: boolean,
|
||||
};
|
||||
|
||||
export class RouteRowEditor extends React.PureComponent<Props, State> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
title: props.title,
|
||||
is_public: props.is_public,
|
||||
};
|
||||
}
|
||||
|
||||
stopEditing = () => console.log();
|
||||
setPublic = () => this.setState({ is_public: !this.state.is_public });
|
||||
setTitle = ({ target: { value } }: { target: { value: string } }) => this.setState({ title: value });
|
||||
|
||||
render() {
|
||||
const {
|
||||
state: { title, is_public },
|
||||
props: { distance, _id }
|
||||
} = this;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="route-row"
|
||||
>
|
||||
<div className="route-title">
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={this.setTitle}
|
||||
placeholder="Введите название"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
<div className="route-description">
|
||||
<span>
|
||||
<Icon icon="icon-link-1" />
|
||||
{_id}
|
||||
</span>
|
||||
<span>
|
||||
<Icon icon="icon-cycle-1" />
|
||||
{(distance && `${distance} km`) || '0 km'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="route-row-editor">
|
||||
<div className="route-row-buttons">
|
||||
<div className="flex_1" onClick={this.setPublic}>
|
||||
<Switch
|
||||
active={is_public}
|
||||
/>
|
||||
{
|
||||
is_public
|
||||
? ' В каталоге карт'
|
||||
: ' Только по ссылке'
|
||||
}
|
||||
</div>
|
||||
<div className="button primary" onClick={this.stopEditing}>
|
||||
OK
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
|
@ -92,8 +92,6 @@ export class Component extends React.PureComponent<Props, void> {
|
|||
state: { menuOpened },
|
||||
} = this;
|
||||
|
||||
const route_count = Object.keys(user.routes).length;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="panel active panel-user">
|
||||
|
@ -114,7 +112,6 @@ export class Component extends React.PureComponent<Props, void> {
|
|||
<div className="control-bar">
|
||||
<button
|
||||
className={classnames({
|
||||
disabled: route_count <= 0,
|
||||
active: dialog_active && (dialog === DIALOGS.MAP_LIST)
|
||||
})}
|
||||
onClick={this.openMapsDialog}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue