Skip to content

Commit

Permalink
CRISTAL-385: Only use realtime when a realtime url is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelleduc committed Dec 23, 2024
1 parent a7f4c2d commit 3c07c95
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 32 deletions.
2 changes: 1 addition & 1 deletion editors/tiptap/src/extensions/collaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const CollaborationKit = Extension.create<CollaborationKitOptions>({

this.storage.provider = new TiptapCollabProvider({
// See server.js from @xwiki/cristal-web
baseUrl: this.options.baseUrl || "http://localhost:15681/collaboration",
baseUrl: this.options.baseUrl,
name: this.options.channel,
// The Y.Doc that is synchronized between editing users.
document: ydoc,
Expand Down
68 changes: 50 additions & 18 deletions editors/tiptap/src/vue/c-edit-tiptap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const content = ref("");
const title = ref("");
const titlePlaceholder = ref("");

const hasRealtime = cristal.getWikiConfig().realtimeURL != undefined;

const currentPageName: Ref<string | undefined> =
documentService.getCurrentDocumentReferenceString();

Expand All @@ -97,6 +99,7 @@ const save = async (authors: User[]) => {
"Saving changes made by: ",
authors.map((author) => author.name).join(", "),
);

// TODO: html does not make any sense here.
const storage = cristal
.getContainer()
Expand All @@ -116,7 +119,15 @@ const save = async (authors: User[]) => {
documentService.notifyDocumentChange("update", currentPage.value!);
};
const submit = async () => {
await editor.value?.storage.cristalCollaborationKit.autoSaver.save();
if (!hasRealtime) {
await save([
{
name: currentUser.name,
},
]);
} else {
await editor.value?.storage.cristalCollaborationKit.autoSaver.save();
}
view();
};

Expand Down Expand Up @@ -155,6 +166,14 @@ const currentUser = {

let editor: Ref<Editor | undefined> = ref(undefined);

const debounced = debounce(() => {
save([
{
name: currentUser.name,
},
]);
}, 500);

function editorInit(
container: Container,
linkSuggest: LinkSuggestService | undefined,
Expand All @@ -163,6 +182,17 @@ function editorInit(
serializer: ModelReferenceSerializer,
parser: RemoteURLParser,
) {
const realtimeExtension = [];
if (hasRealtime) {
realtimeExtension.push(
CollaborationKit.configure({
channel: currentPageName.value,
user: currentUser,
saveCallback: save,
baseUrl: realtimeURL,
}),
);
}
return new Editor({
content: content.value || "",
extensions: [
Expand Down Expand Up @@ -193,13 +223,13 @@ function editorInit(
// TODO: the protocols should be injected by extension.
protocols: ["http", "https", "cristalfs"],
}),
CollaborationKit.configure({
channel: currentPageName.value,
user: currentUser,
saveCallback: save,
baseUrl: realtimeURL,
}),
...realtimeExtension,
],
onUpdate() {
if (!hasRealtime) {
debounced();
}
},
});
}

Expand Down Expand Up @@ -279,15 +309,17 @@ watch(
// Otherwise, the title will not be updated unless the content is updated too.
watch(
title,
debounce(
async () =>
await editor.value?.storage.cristalCollaborationKit.autoSaver.save([
{
name: currentUser.name,
},
]),
500,
),
debounce(async () => {
if (hasRealtime) {
return await editor.value?.storage.cristalCollaborationKit.autoSaver.save(
[
{
name: currentUser.name,
},
],
);
}
}, 500),
);
</script>

Expand Down Expand Up @@ -317,11 +349,11 @@ watch(
<form class="pagemenu" @submit="submit">
<div class="pagemenu-status">
<c-connection-status
v-if="editor"
v-if="editor && hasRealtime"
:provider="editor.storage.cristalCollaborationKit.provider"
></c-connection-status>
<c-save-status
v-if="editor"
v-if="editor && hasRealtime"
:auto-saver="editor.storage.cristalCollaborationKit.autoSaver"
></c-save-status>
</div>
Expand Down
39 changes: 26 additions & 13 deletions web/public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"baseURL": "https://cristal.demo.xwiki.com/xwiki",
"baseRestURL": "/rest/cristal/page?media=json",
"homePage": "Main.WebHome",
"designSystem": "vuetify"
"designSystem": "vuetify",
"realtimeURL": "http://localhost:15681/collaboration"
},
"XWikiOffline": {
"name": "XWikiOffline",
Expand All @@ -17,7 +18,8 @@
"baseURL": "https://cristal.demo.xwiki.com/xwiki",
"baseRestURL": "/rest/cristal/page?media=json",
"homePage": "Main.WebHome",
"designSystem": "vuetify"
"designSystem": "vuetify",
"realtimeURL": "http://localhost:15681/collaboration"
},
"XWikiSSR": {
"name": "XWikiSSR",
Expand All @@ -27,7 +29,8 @@
"baseURL": "https://cristal.demo.xwiki.com/xwiki",
"baseRestURL": "/rest/cristal/page?media=json",
"homePage": "Main.WebHome",
"designSystem": "vuetify"
"designSystem": "vuetify",
"realtimeURL": "http://localhost:15681/collaboration"
},
"XWikiDSFR": {
"name": "XWikiDSFR",
Expand All @@ -37,7 +40,8 @@
"baseURL": "https://cristal.demo.xwiki.com/xwiki",
"baseRestURL": "/rest/cristal/page?media=json",
"homePage": "Main.WebHome",
"designSystem": "dsfr"
"designSystem": "dsfr",
"realtimeURL": "http://localhost:15681/collaboration"
},
"XWikiSL": {
"name": "XWikiSL",
Expand All @@ -47,7 +51,8 @@
"baseURL": "https://cristal.demo.xwiki.com/xwiki",
"baseRestURL": "/rest/cristal/page?media=json",
"homePage": "Main.WebHome",
"designSystem": "shoelace"
"designSystem": "shoelace",
"realtimeURL": "http://localhost:15681/collaboration"
},
"Localhost": {
"name": "Localhost",
Expand All @@ -57,7 +62,8 @@
"baseURL": "http://localhost:15680/xwiki",
"baseRestURL": "/rest/cristal/page?media=json",
"homePage": "Main.WebHome",
"designSystem": "vuetify"
"designSystem": "vuetify",
"realtimeURL": "http://localhost:15681/collaboration"
},
"LocalhostSL": {
"name": "LocalhostSL",
Expand All @@ -67,7 +73,8 @@
"baseURL": "http://localhost:15680/xwiki",
"baseRestURL": "/rest/cristal/page?media=json",
"homePage": "Main.WebHome",
"designSystem": "shoelace"
"designSystem": "shoelace",
"realtimeURL": "http://localhost:15681/collaboration"
},
"LocalhostDSFR": {
"name": "LocalhostDSFR",
Expand All @@ -77,7 +84,8 @@
"baseURL": "http://localhost:15680/xwiki",
"baseRestURL": "/rest/cristal/page?media=json",
"homePage": "Main.WebHome",
"designSystem": "dsfr"
"designSystem": "dsfr",
"realtimeURL": "http://localhost:15681/collaboration"
},
"LocalhostOffline": {
"name": "LocalhostOffline",
Expand All @@ -87,7 +95,8 @@
"baseURL": "http://localhost:15680/xwiki",
"baseRestURL": "/rest/cristal/page?media=json",
"homePage": "Main.WebHome",
"designSystem": "vuetify"
"designSystem": "vuetify",
"realtimeURL": "http://localhost:15681/collaboration"
},
"GitHub": {
"name": "GitHub",
Expand All @@ -97,7 +106,8 @@
"baseURL": "https://github.com/ldubost/test/tree/master/",
"baseRestURL": "https://raw.githubusercontent.com/ldubost/test/master/",
"homePage": "README.md",
"designSystem": "vuetify"
"designSystem": "vuetify",
"realtimeURL": "http://localhost:15681/collaboration"
},
"GitHubOffline": {
"name": "GitHubOffline",
Expand All @@ -107,7 +117,8 @@
"baseURL": "https://github.com/ldubost/test/tree/master/",
"baseRestURL": "https://raw.githubusercontent.com/ldubost/test/master/",
"homePage": "README.md",
"designSystem": "vuetify"
"designSystem": "vuetify",
"realtimeURL": "http://localhost:15681/collaboration"
},
"GitHubSL": {
"name": "GitHubSL",
Expand All @@ -117,7 +128,8 @@
"baseURL": "https://github.com/ldubost/test/tree/master/",
"baseRestURL": "https://raw.githubusercontent.com/ldubost/test/master/",
"homePage": "README.md",
"designSystem": "shoelace"
"designSystem": "shoelace",
"realtimeURL": "http://localhost:15681/collaboration"
},
"Nextcloud": {
"name": "Nextcloud",
Expand All @@ -127,6 +139,7 @@
"baseURL": "http://localhost:9292/",
"baseRestURL": "http://localhost:9292/remote.php/dav/files",
"designSystem": "shoelace",
"homePage": "home"
"homePage": "home",
"realtimeURL": "http://localhost:15681/collaboration"
}
}

0 comments on commit 3c07c95

Please sign in to comment.