Skip to content

Commit 6bb52d6

Browse files
committed
finish modernizing timetravel implementation
1 parent aed9474 commit 6bb52d6

File tree

2 files changed

+33
-47
lines changed

2 files changed

+33
-47
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export function TimeTravel(props: Props) {
202202
<Document
203203
actions={props.actions}
204204
id={props.id}
205-
doc={doc.to_str()}
205+
value={doc.to_str()}
206206
path={doc.value == null ? "a.js" : docpath}
207207
project_id={props.project_id}
208208
font_size={props.font_size}
@@ -394,9 +394,7 @@ export function TimeTravel(props: Props) {
394394
id={props.id}
395395
actions={props.actions}
396396
disabled={versions.size <= 1}
397-
changes_mode={
398-
props.desc != null && props.desc.get("changes_mode", false)
399-
}
397+
changes_mode={props.desc?.get("changes_mode", false)}
400398
/>
401399
);
402400
};
@@ -419,18 +417,19 @@ export function TimeTravel(props: Props) {
419417
}}
420418
>
421419
{renderChangesMode()}
422-
{HAS_SPECIAL_VIEWER.has(docext ?? "") && (
423-
<Tooltip title="Display underlying file as text">
424-
<Checkbox
425-
defaultChecked={!!props.desc.get("text_mode")}
426-
onChange={(e) =>
427-
props.actions.setTextMode(props.id, e.target.checked)
428-
}
429-
>
430-
Text
431-
</Checkbox>
432-
</Tooltip>
433-
)}
420+
{!props.desc?.get("changes_mode", false) &&
421+
HAS_SPECIAL_VIEWER.has(docext ?? "") && (
422+
<Tooltip title="Display underlying file as text">
423+
<Checkbox
424+
defaultChecked={!!props.desc.get("text_mode")}
425+
onChange={(e) =>
426+
props.actions.setTextMode(props.id, e.target.checked)
427+
}
428+
>
429+
Text
430+
</Checkbox>
431+
</Tooltip>
432+
)}
434433
<Tooltip title="Show Git history instead of CoCalc edit history">
435434
<Checkbox
436435
defaultChecked={!!props.desc.get("git_mode")}

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

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

6-
import { Rendered, Component } from "../../app-framework";
7-
import { TimeAgo } from "../../components";
6+
import { TimeAgo } from "@cocalc/frontend/components";
87

98
interface Props {
109
date: Date;
1110
number: number;
1211
max: number;
1312
}
1413

15-
export class Version extends Component<Props> {
16-
private render_time(): Rendered {
17-
return (
14+
export function Version({ date, number, max }: Props) {
15+
if (max == 0) return <span />;
16+
return (
17+
<span>
1818
<span
1919
style={{
2020
fontWeight: "bold",
@@ -23,26 +23,14 @@ export class Version extends Component<Props> {
2323
whiteSpace: "nowrap",
2424
}}
2525
>
26-
<TimeAgo date={this.props.date} />
26+
<TimeAgo date={date} />
2727
</span>
28-
);
29-
}
30-
private render_number(): Rendered {
31-
return (
28+
,{" "}
3229
<span style={{ whiteSpace: "nowrap" }}>
33-
revision {this.props.number} (of {this.props.max})
34-
</span>
35-
);
36-
}
37-
38-
public render(): Rendered {
39-
if (this.props.max == 0) return <span />;
40-
return (
41-
<span>
42-
{this.render_time()}, {this.render_number()}
30+
revision {number} (of {max})
4331
</span>
44-
);
45-
}
32+
</span>
33+
);
4634
}
4735

4836
interface RangeProps {
@@ -51,14 +39,13 @@ interface RangeProps {
5139
max: number;
5240
}
5341

54-
export class VersionRange extends Component<RangeProps> {
55-
public render(): Rendered {
56-
if (this.props.max == 0) return <span />;
57-
return (
58-
<span style={{ whiteSpace: "nowrap" }}>
59-
Versions {this.props.version0 + 1} to {this.props.version1 + 1} (of{" "}
60-
{this.props.max})
61-
</span>
62-
);
42+
export function VersionRange({ version0, version1, max }: RangeProps) {
43+
if (max == 0) {
44+
return <span />;
6345
}
46+
return (
47+
<span style={{ whiteSpace: "nowrap" }}>
48+
Versions {version0 + 1} to {version1 + 1} (of {max})
49+
</span>
50+
);
6451
}

0 commit comments

Comments
 (0)