Skip to content

Commit ebd3b49

Browse files
authored
ENG-607 - Handle canvas already upgraded (#289)
* Enhance Tldraw integration by adding isAlreadyUpgraded check in useRoamStore and updating TldrawCanvas to display upgrade message. This improves user experience by informing users about the latest canvas version. * Fix typo in TldrawCanvas upgrade message for improved clarity. * Update version to 0.14.3 in package.json and package-lock.json for roam
1 parent 0dffc97 commit ebd3b49

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

apps/roam/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "roam",
3-
"version": "0.14.2",
3+
"version": "0.14.3",
44
"description": "Discourse Graph Plugin for roamresearch.com",
55
"scripts": {
66
"postinstall": "patch-package",

apps/roam/src/components/canvas/Tldraw.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ const TldrawCanvas = ({ title }: Props) => {
689689
const lastInsertRef = useRef<Vec2dModel>();
690690
const containerRef = useRef<HTMLDivElement>(null);
691691
const [maximized, setMaximized] = useState(false);
692-
const { store, instanceId, userId } = useRoamStore({
692+
const { store, instanceId, userId, isAlreadyUpgraded } = useRoamStore({
693693
config: customTldrawConfig,
694694
title,
695695
});
@@ -873,6 +873,17 @@ const TldrawCanvas = ({ title }: Props) => {
873873
</style>
874874
{isLoading ? (
875875
<></>
876+
) : isAlreadyUpgraded || !store ? (
877+
<div className="flex h-full items-center justify-center">
878+
<div className="text-center">
879+
<h2 className="mb-2 text-2xl font-semibold">Canvas Upgraded</h2>
880+
<p className="mb-4 text-gray-600">
881+
This canvas is using the latest version.
882+
<br />
883+
Please upgrade your Discourse Graph extension to view this canvas.
884+
</p>
885+
</div>
886+
</div>
876887
) : (
877888
<TldrawEditor
878889
baseUrl="https://samepage.network/assets/tldraw/"

apps/roam/src/utils/useRoamStore.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ export const useRoamStore = ({
4545
}
4646
const instanceId = TLInstance.createCustomId(pageUid);
4747
const userId = TLUser.createCustomId(getCurrentUserUid());
48+
4849
const props = getBlockProps(pageUid) as Record<string, unknown>;
4950
const rjsqb = props["roamjs-query-builder"] as Record<string, unknown>;
5051
const data = rjsqb?.tldraw as Parameters<TLStore["deserialize"]>[0];
51-
return { data, instanceId, userId };
52+
53+
const isAlreadyUpgraded = !!rjsqb?.legacyTldraw;
54+
55+
return { data, instanceId, userId, isAlreadyUpgraded };
5256
}, [tree, pageUid]);
5357

5458
const store = useMemo(() => {
59+
if (initialData.isAlreadyUpgraded) return null;
5560
const _store = config.createStore({
5661
initialData: initialData.data,
5762
instanceId: initialData.instanceId,
@@ -186,6 +191,7 @@ export const useRoamStore = ({
186191
};
187192

188193
useEffect(() => {
194+
if (initialData.isAlreadyUpgraded || !store) return;
189195
const pullWatchProps: Parameters<AddPullWatch> = [
190196
"[:edit/user :block/props :block/string {:block/children ...}]",
191197
`[:block/uid "${pageUid}"]`,
@@ -220,5 +226,6 @@ export const useRoamStore = ({
220226
store,
221227
instanceId: initialData.instanceId,
222228
userId: initialData.userId,
229+
isAlreadyUpgraded: initialData.isAlreadyUpgraded,
223230
};
224231
};

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)