Skip to content

Commit 416599d

Browse files
committed
timetravel: modernizing it more
1 parent 8477812 commit 416599d

File tree

12 files changed

+190
-247
lines changed

12 files changed

+190
-247
lines changed

src/packages/frontend/frame-editors/time-travel-editor/document.tsx

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,24 @@
77
Render a static version of a document for use in TimeTravel.
88
*/
99

10-
import { Component, Rendered } from "../../app-framework";
11-
12-
import { fromJS, Map } from "immutable";
10+
import { fromJS } from "immutable";
1311
import { CodemirrorEditor } from "../code-editor/codemirror-editor";
14-
import { TimeTravelActions } from "./actions";
15-
16-
interface Props {
17-
id: string;
18-
actions: TimeTravelActions;
19-
font_size: number;
20-
doc: string;
21-
path: string; // filename of doc, which determines what sort of editor it uses
22-
project_id: string;
23-
editor_settings: Map<string, any>;
24-
}
2512

26-
export class Document extends Component<Props> {
27-
private render_body(): Rendered {
28-
return (
13+
export function Document(props) {
14+
return (
15+
<div className="smc-vfill" style={{ overflowY: "auto" }}>
2916
<CodemirrorEditor
30-
id={this.props.id}
31-
actions={this.props.actions}
32-
path={this.props.path}
33-
project_id={this.props.project_id}
34-
font_size={this.props.font_size}
17+
{...props}
3518
cursors={fromJS({})}
3619
editor_state={fromJS({})}
3720
read_only={true}
3821
is_current={true}
3922
is_public={true}
40-
value={this.props.doc}
4123
misspelled_words={fromJS([]) as any}
4224
resize={0}
4325
gutters={[]}
4426
gutter_markers={fromJS({}) as any}
45-
editor_settings={this.props.editor_settings}
4627
/>
47-
);
48-
}
49-
50-
public render(): Rendered {
51-
return (
52-
<div className="smc-vfill" style={{ overflowY: "auto" }}>
53-
{this.render_body()}
54-
</div>
55-
);
56-
}
28+
</div>
29+
);
5730
}

src/packages/frontend/frame-editors/time-travel-editor/export.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@
88
- This is really just some minimal data *about* the history for now.
99
*/
1010

11-
import { Rendered, Component } from "../../app-framework";
12-
import { Button } from "react-bootstrap";
11+
import { Button } from "antd";
1312
import { TimeTravelActions } from "./actions";
1413
import { Icon } from "../../components";
1514

1615
interface Props {
1716
actions: TimeTravelActions;
1817
}
1918

20-
export class Export extends Component<Props> {
21-
public render(): Rendered {
22-
return (
23-
<Button
24-
onClick={() => this.props.actions.export()}
25-
title="Export information about edit history to a JSON file"
26-
>
27-
<Icon name={"file-export"} /> Export
28-
</Button>
29-
);
30-
}
19+
export function Export({ actions }: Props) {
20+
return (
21+
<Button
22+
onClick={() => actions.export()}
23+
title="Export information about edit history to a JSON file"
24+
>
25+
<Icon name={"file-export"} /> Export
26+
</Button>
27+
);
3128
}

src/packages/frontend/frame-editors/time-travel-editor/load-full-history.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33
* License: MS-RSL – see LICENSE.md for details
44
*/
55

6-
import { Rendered, Component } from "../../app-framework";
7-
import { Button } from "react-bootstrap";
6+
import { Button } from "antd";
87
import { TimeTravelActions } from "./actions";
98
import { Icon } from "../../components";
109

1110
interface Props {
1211
actions: TimeTravelActions;
1312
}
1413

15-
export class LoadFullHistory extends Component<Props> {
16-
public render(): Rendered {
17-
return (
18-
<Button
19-
onClick={() => this.props.actions.load_full_history()}
20-
title={"Load the complete edit history for this file."}
21-
>
22-
<Icon name="file-archive" /> Load All
23-
</Button>
24-
);
25-
}
14+
export function LoadFullHistory({ actions }: Props) {
15+
return (
16+
<Button
17+
onClick={() => actions.load_full_history()}
18+
title={"Load the complete edit history for this file."}
19+
>
20+
<Icon name="file-archive" /> Load All
21+
</Button>
22+
);
2623
}

src/packages/frontend/frame-editors/time-travel-editor/navigation-buttons.tsx

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,55 +12,50 @@ Navigation Buttons to:
1212
- last
1313
*/
1414

15-
import { Button, ButtonGroup } from "react-bootstrap";
16-
import { Component, Rendered } from "../../app-framework";
17-
import { Icon } from "../../components";
18-
15+
import { Button } from "antd";
16+
import { Icon } from "@cocalc/frontend/components";
1917
import { TimeTravelActions } from "./actions";
2018

2119
interface Props {
2220
id: string;
2321
actions: TimeTravelActions;
24-
2522
version0: number;
2623
version1: number;
2724
max: number;
2825
}
2926

30-
export class NavigationButtons extends Component<Props> {
31-
public render(): Rendered {
32-
const { version0, version1, max } = this.props;
33-
return (
34-
<ButtonGroup>
35-
<Button
36-
title={"First version"}
37-
onClick={() => this.props.actions.step(this.props.id, -version0)}
38-
disabled={version0 != null && version0 <= 0}
39-
>
40-
<Icon name="backward" />
41-
</Button>
42-
<Button
43-
title={"Previous version"}
44-
onClick={() => this.props.actions.step(this.props.id, -1)}
45-
disabled={version0 != null && version0 <= 0}
46-
>
47-
<Icon name="step-backward" />
48-
</Button>
49-
<Button
50-
title={"Next version"}
51-
onClick={() => this.props.actions.step(this.props.id, 1)}
52-
disabled={version1 != null && version1 >= max}
53-
>
54-
<Icon name="step-forward" />
55-
</Button>
56-
<Button
57-
title={"Most recent version"}
58-
onClick={() => this.props.actions.step(this.props.id, max - version1)}
59-
disabled={version1 != null && version1 >= max}
60-
>
61-
<Icon name="forward" />
62-
</Button>
63-
</ButtonGroup>
64-
);
65-
}
27+
export function NavigationButtons(props: Props) {
28+
const { version0, version1, max } = props;
29+
return (
30+
<div style={{ display: "inline-flex" }}>
31+
<Button
32+
title={"First version"}
33+
onClick={() => props.actions.step(props.id, -version0)}
34+
disabled={version0 != null && version0 <= 0}
35+
>
36+
<Icon name="backward" />
37+
</Button>
38+
<Button
39+
title={"Previous version"}
40+
onClick={() => props.actions.step(props.id, -1)}
41+
disabled={version0 != null && version0 <= 0}
42+
>
43+
<Icon name="step-backward" />
44+
</Button>
45+
<Button
46+
title={"Next version"}
47+
onClick={() => props.actions.step(props.id, 1)}
48+
disabled={version1 != null && version1 >= max}
49+
>
50+
<Icon name="step-forward" />
51+
</Button>
52+
<Button
53+
title={"Most recent version"}
54+
onClick={() => props.actions.step(props.id, max - version1)}
55+
disabled={version1 != null && version1 >= max}
56+
>
57+
<Icon name="forward" />
58+
</Button>
59+
</div>
60+
);
6661
}

src/packages/frontend/frame-editors/time-travel-editor/navigation-slider.tsx

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,45 @@
33
* License: MS-RSL – see LICENSE.md for details
44
*/
55

6-
import { Component, Rendered } from "../../app-framework";
7-
6+
import { Slider } from "antd";
87
import { TimeTravelActions } from "./actions";
8+
import { TimeAgo } from "../../components";
9+
import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
910

1011
interface Props {
1112
id: string;
1213
actions: TimeTravelActions;
13-
1414
version?: number;
15+
versions;
1516
max: number;
1617
}
1718

18-
export class NavigationSlider extends Component<Props> {
19-
private handle_change(event: any): void {
20-
this.props.actions.set_version(this.props.id, parseInt(event.target.value));
19+
export function NavigationSlider({
20+
id,
21+
actions,
22+
version,
23+
versions,
24+
max,
25+
}: Props) {
26+
const { isVisible } = useFrameContext();
27+
if (version == null || !isVisible) {
28+
return <div />;
2129
}
30+
const renderTooltip = (index) => {
31+
const date = versions.get(index);
32+
if (date == null) return; // shouldn't happen
33+
return <TimeAgo date={date} />;
34+
};
2235

23-
public render(): Rendered {
24-
const { version, max } = this.props;
25-
if (version == null) return <div />;
26-
return (
27-
<input
28-
style={{ cursor: "pointer" }}
29-
type="range"
30-
min={0}
31-
max={max}
32-
value={version}
33-
onChange={this.handle_change.bind(this)}
34-
/>
35-
);
36-
}
36+
return (
37+
<Slider
38+
min={0}
39+
max={max}
40+
value={version}
41+
onChange={(value) => {
42+
actions.set_version(id, value);
43+
}}
44+
tooltip={{ formatter: renderTooltip, placement: "bottom", open: true }}
45+
/>
46+
);
3747
}

src/packages/frontend/frame-editors/time-travel-editor/open-file.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { Rendered, Component } from "../../app-framework";
7-
import { Button } from "react-bootstrap";
7+
import { Button } from "antd";
88
import { TimeTravelActions } from "./actions";
99
import { Icon } from "../../components";
1010

src/packages/frontend/frame-editors/time-travel-editor/open-snapshots.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
just links to the info from backups about *this* file.
1111
*/
1212

13-
import { Button } from "react-bootstrap";
14-
13+
import { Button } from "antd";
1514
import { Rendered, Component } from "@cocalc/frontend/app-framework";
1615
import { TimeTravelActions } from "./actions";
1716
import { Icon } from "@cocalc/frontend/components";

0 commit comments

Comments
 (0)