Skip to content

Commit

Permalink
feat: creator meta
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Nov 27, 2023
1 parent 15a85ec commit 46bdab1
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/components/custom/tldraw/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ function EverythingCanvas({
autoFocus,
hideUi,
initialSnapshot,
plugins, // we could replace showAction, pass plugins to action button
}) {
const parts = persistance.split("/");
const creatorId = parts[0];


const [store] = useState(() => {
if (initialSnapshot) {
const newStore = createTLStore({
Expand All @@ -33,10 +36,34 @@ function EverythingCanvas({
});

const setAppToState = useCallback((editor) => {
// Do something
// Once the canvas mounts
// Can we set widget on top of canvas
}, []);
editor.user.updateUserPreferences({
id: creatorId,
})

editor.getInitialMetaForShape = (_shape) => {
return {
createdBy: editor.user.getId(),
createdAt: Date.now(),
updatedBy: editor.user.getId(),
updatedAt: Date.now(),
};
};
// We can also use the sideEffects API to modify a shape before
// its change is committed to the database. This will run for
// all shapes whenever they are updated.
// editor.sideEffects.registerBeforeChangeHandler(
// "shape",
// (record, _prev, source) => {
// if (source !== "user") return record;
// record.meta = {
// ...record.meta,
// updatedBy: editor.user.getId(),
// updatedAt: Date.now(),
// };
// return record;
// }
// );
}, [creatorId]);

return (
<div className={"tldraw__editor"}>
Expand All @@ -58,7 +85,7 @@ function EverythingCanvas({
autoFocus={autoFocus ?? true}
hideUi={hideUi ?? false}
>
<ActionButton plugins={plugins} />
<ActionButton />
<TldrawLogo />
</Tldraw>
</div>
Expand Down

0 comments on commit 46bdab1

Please sign in to comment.