Scroll to epoch

This commit is contained in:
Ayaz Hafiz 2023-07-31 18:18:41 -05:00
parent e3129032e8
commit 8069d3ad34
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
6 changed files with 144 additions and 25 deletions

View file

@ -3,6 +3,7 @@ import FileInput, { LoadedEvents } from "./components/FileInput";
import Ui from "./components/Ui";
import data from "./checkmate.json";
import { AllEvents } from "./schema";
import { BrowserRouter } from "react-router-dom";
export default function App() {
const [events, setEvents] = React.useState<LoadedEvents | null>({
@ -11,14 +12,16 @@ export default function App() {
});
return (
<div className="w-screen h-screen p-2 bg-gray-100 flex flex-col">
<div>
<FileInput setResult={setEvents} />
<BrowserRouter>
<div className="w-screen h-screen p-2 bg-gray-100 flex flex-col">
<div>
<FileInput setResult={setEvents} />
</div>
<div className="flex-1 overflow-hidden">
<EventsWrapper events={events} />
</div>
</div>
<div className="flex-1 overflow-hidden">
<EventsWrapper events={events} />
</div>
</div>
</BrowserRouter>
);
}

View file

@ -1,8 +1,30 @@
import clsx from "clsx";
import { EventEpoch } from "../../engine/engine";
import { HashLink } from "react-router-hash-link";
export enum EpochCellView {
Events,
Graph,
}
function invert(cell: EpochCellView): EpochCellView {
if (cell === EpochCellView.Events) {
return EpochCellView.Graph;
}
return EpochCellView.Events;
}
function asStr(cell: EpochCellView): string {
switch (cell) {
case EpochCellView.Events:
return "events";
case EpochCellView.Graph:
return "graph";
}
}
interface EpochCellProps {
noLeadingText?: boolean;
view: EpochCellView;
epoch: EventEpoch;
className?: string;
}
@ -21,15 +43,18 @@ const EPOCH_STYLES_ARRAY = [
export const EPOCH_STYLES = clsx(...EPOCH_STYLES_ARRAY);
export default function EpochCell({
epoch,
className,
noLeadingText,
}: EpochCellProps) {
export default function EpochCell({ epoch, className, view }: EpochCellProps) {
const invertedView = invert(view);
return (
<div className={clsx(EPOCH_STYLES, className)}>
{noLeadingText ? "" : "Epoch "}
{epoch}
</div>
<HashLink smooth to={`#${asStr(invertedView)}-${epoch}`}>
<div
id={`${asStr(view)}-${epoch}`}
className={clsx(EPOCH_STYLES, className)}
>
{view === EpochCellView.Graph ? "Epoch " : ""}
{epoch}
</div>
</HashLink>
);
}

View file

@ -4,7 +4,7 @@ import { EventEpoch } from "../engine/engine";
import { lastSubEvent } from "../engine/event_util";
import { UnificationMode, Event } from "../schema";
import { Refine } from "../utils/refine";
import EpochCell from "./Common/EpochCell";
import EpochCell, { EpochCellView } from "./Common/EpochCell";
import { CommonProps } from "./EventItem/types";
import { VariableEl } from "./EventItem/Variable";
@ -97,7 +97,7 @@ function Unification(props: UnificationProps): JSX.Element {
if (!containsCurrentEpoch) return null;
return (
<EpochCell
noLeadingText
view={EpochCellView.Events}
epoch={currentEpoch}
className="inline-block align-middle mr-2"
></EpochCell>

View file

@ -31,7 +31,7 @@ import VariableNode, {
import { SubsSnapshot } from "../../engine/subs";
import { KeydownHandler } from "../Events";
import { TypedEmitter } from "tiny-typed-emitter";
import EpochCell from "../Common/EpochCell";
import EpochCell, { EpochCellView } from "../Common/EpochCell";
export interface VariablesGraphProps {
subs: SubsSnapshot;
@ -447,7 +447,7 @@ function Graph({
}}
>
<Panel position="top-left">
<EpochCell epoch={subs.epoch}></EpochCell>
<EpochCell view={EpochCellView.Graph} epoch={subs.epoch}></EpochCell>
</Panel>
<Panel position="top-right">
<LayoutPanel