Skip to content

Commit

Permalink
load in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Jan 17, 2024
1 parent 5c68909 commit 94ccacb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
28 changes: 16 additions & 12 deletions apps/canvas/widget/History.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ function getDatastringFromBlockHeight(blockHeight) {

const oldVersion = useMemo(() => {
const current = Social.get(props.path, state.selectedBlockHeight);
return {
[name]: {
[type]: current,
},
};
return current;
}, [state.selectedBlockHeight]);

const handleRevert = () => {
Social.set(oldVersion);
if (props.onRevert) {
props.onRevert(oldVersion);
} else {
Social.set({
[name]: {
[type]: oldVersion,
},
});
}
};

const renderBlockChangesLink = (blockHeight) => {
Expand All @@ -68,7 +72,7 @@ const renderBlockChangesLink = (blockHeight) => {
function blockHeightToCode(blockHeight) {
const index = blocksChanges.findIndex((el) => el == blockHeight);
return (
<div class="mb-3">
<div className="mb-3">
<Widget
key={blockHeight}
src={"everycanvas.near/widget/History.CodeHistoryCard"}
Expand Down Expand Up @@ -137,9 +141,9 @@ return (
<div>incorrent path</div>
) : (
<div>
<div div class="card mb-3">
<div div className="card mb-3">
<div className="card-header">
<div class="d-flex justify-content-between align-items-center">
<div className="d-flex justify-content-between align-items-center">
<h3>{blocksChanges.length} Commits </h3>
{state.selectedBlockHeight &&
blocksChanges[0] !== state.selectedBlockHeight && (
Expand All @@ -150,20 +154,20 @@ return (
</div>
</div>

<div class="list-group">
<div className="list-group">
{blocksChanges
.slice(0, 5)
.map((height) => renderBlockChangesLink(height))}

<div class="collapse" id="collapseExample">
<div className="collapse" id="collapseExample">
{blocksChanges
.slice(5)
.map((height) => renderBlockChangesLink(height))}
</div>

{blocksChanges.length > 5 && (
<button
class="list-group-item active"
className="list-group-item active"
type="button"
data-bs-toggle="collapse"
data-bs-target="#collapseExample"
Expand Down
14 changes: 7 additions & 7 deletions apps/canvas/widget/History/CodeHistoryCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ let CodeWrapper = styled.div`
return (
<div className="card border-primary">
<div className="card-header">
<small class="text-muted">
<div class="row justify-content-between">
<div class="col-4 d-flex frex-row justify-content-start align-items-center">
<div class="p-2">changes in block #{props.currentBlockHeight}</div>
<small className="text-muted">
<div className="row justify-content-between">
<div className="col-4 d-flex frex-row justify-content-start align-items-center">
<div className="p-2">changes in block #{props.currentBlockHeight}</div>

<OverlayTrigger
placement="auto"
overlay={<Tooltip>count inserted lines</Tooltip>}
>
<span class="badge text-bg-success p-2 me-1 align-self-center">
<span className="badge text-bg-success p-2 me-1 align-self-center">
{state.lineCountInserted}
</span>
</OverlayTrigger>
Expand All @@ -38,13 +38,13 @@ return (
placement="auto"
overlay={<Tooltip>count deleted lines</Tooltip>}
>
<span class="badge text-bg-danger p-2 me-1 align-self-center">
<span className="badge text-bg-danger p-2 me-1 align-self-center">
{state.lineCountDeleted}
</span>
</OverlayTrigger>
</div>

<div class="col-7 d-flex justify-content-end align-items-center">
<div className="col-7 d-flex justify-content-end align-items-center">
{getDatastringFromBlockHeight(props.currentBlockHeight)}
</div>
</div>
Expand Down
21 changes: 17 additions & 4 deletions apps/canvas/widget/hyperfile/load.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@

const { loadSnapshot, path } = props;

State.init({
src: path ?? "",
src: path ?? "",
});

function onRevert(v) {
console.log("reverting", v)
if (v.adapter) {
console.log("adapter", v.adapter);
const { get } = VM.require(v.adapter) || {
get: (v) => console.log("no get: ", v),
};
if (get) {
loadSnapshot(get(v.reference));
}
} else {
console.log("no adapter", v.adapter);
}
}

return (
<div>
<h1 class="text-center">History</h1>
Expand All @@ -26,9 +40,8 @@ return (
src={"everycanvas.near/widget/History"}
props={{
path: state.src,
onRevert: onRevert,
}}
/>
</div>
);

return <button onClick={loadSnapshot} />
1 change: 1 addition & 0 deletions src/components/custom/tldraw/ShareZone.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function ShareZone({ path }) {
});

const loadSnapshot = useCallback((snapshot) => {
console.log("loading snapshot", snapshot);
snapshot = typeof snapshot === "string" ? JSON.parse(snapshot) : snapshot;
editor.store.loadSnapshot(snapshot);
});
Expand Down

0 comments on commit 94ccacb

Please sign in to comment.