Skip to content

Commit

Permalink
Ajax document saving, socket seperation for documents, several bug fi…
Browse files Browse the repository at this point in the history
…xes, listing users that editing file
  • Loading branch information
dogukanoksuz committed Dec 27, 2020
1 parent 8831787 commit 9cff491
Show file tree
Hide file tree
Showing 23 changed files with 3,928 additions and 180 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"discord.enabled": true
}
2 changes: 1 addition & 1 deletion editor/dist/quill.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion editor/dist/quill.bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion editor/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Collab Quill Editor",
"name": "Collab-Quill-Editor",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand Down
50 changes: 44 additions & 6 deletions editor/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Quill.register({

window.addEventListener('load', () => {
const ydoc = new Y.Doc()
var provider = new WebsocketProvider('ws://localhost:9000', 'quill', ydoc)
const type = ydoc.getText('quill')
var provider = new WebsocketProvider('ws://localhost:9000', documentUUID, ydoc)
const type = ydoc.getText(documentUUID)

let editor = new Quill('#full-container .editor', {
bounds: '#full-container .editor',
Expand All @@ -36,14 +36,15 @@ window.addEventListener('load', () => {
'tableUI': true,
'magicUrl': true,
'imageDrop': true,
'blotFormatter': {

}
'blotFormatter': {}
},

theme: 'snow'
});

editorInstance = editor
providerInstance = provider

const binding = new QuillBinding(type, editor, provider.awareness)

provider.awareness.setLocalStateField('user', {
Expand Down Expand Up @@ -90,4 +91,41 @@ window.addEventListener('load', () => {
tippy('.ql-clean', {
content: 'Biçimlendirmeyi Temizle'
})
})


// Auto-save AJAX
let save = () => {
$.ajax(saveRoute, {
type: 'POST',
data: {
'_token': csrfToken,
'data': $(".ql-editor").html()
},
success: function (data, status, xhr) {
//console.log('status: ' + status + ', data: ' + data);
},
error: function (jqXhr, textStatus, errorMessage) {
clearInterval(saveLoop);
console.log('Error' + errorMessage);
}
})
}

let saveLoop = setInterval(() => {
save()
}, 9999999)

let checker = false;

$(".editor").keypress(function () {
if (!checker) {
clearInterval(saveLoop)
saveLoop = setInterval(() => {
save()
}, 8000)
checker = true
}

})
})

21 changes: 21 additions & 0 deletions server/app/Http/Controllers/API/DocumentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use App\Models\Document;
use Illuminate\Http\Request;

class DocumentController extends Controller
{
public function save($documentId, Request $request)
{
$document = Document::where('id', $documentId)->first();

$document->update([
'content' => $request->data
]);

return response()->json(['message' => 'Success', 'state' => 'ok']);
}
}
7 changes: 1 addition & 6 deletions server/app/Http/Livewire/Document/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ class Show extends Component

public function newDocumentCreated($documents)
{
if (!$documents)
{
$this->documents = auth()->user()->document()
$this->documents = auth()->user()->document()
->orderBy('updated_at', 'DESC')
->where('folder_id', null)
->get();
} else {
$this->documents = $documents;
}
}

public function mount($documents)
Expand Down
7 changes: 1 addition & 6 deletions server/app/Http/Livewire/Folder/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ class Show extends Component

public function newFolderCreated($folders, $folderId)
{
if(!$folders)
{
$this->folders = auth()->user()->folder()->where('parent_folder_id', null)->orderBy('updated_at', 'DESC')->get();
} else {
$this->folders = auth()->user()->folder()->where('parent_folder_id', $folderId)->orderBy('updated_at', 'DESC')->get();
}
$this->folders = auth()->user()->folder()->where('parent_folder_id', null)->orderBy('updated_at', 'DESC')->get();
}

public function mount($folders, $folderId)
Expand Down
1,296 changes: 1,296 additions & 0 deletions server/public/editor/highlight.min.js

Large diffs are not rendered by default.

760 changes: 760 additions & 0 deletions server/public/editor/quill.bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions server/public/editor/quill.bundle.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 9cff491

Please sign in to comment.