-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ahmadrosid/share-conversation
Shared chat
- Loading branch information
Showing
19 changed files
with
545 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Document; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Storage; | ||
use Illuminate\Support\Str; | ||
|
||
class DocumentController extends Controller | ||
{ | ||
public function copy(Document $document) | ||
{ | ||
// Check if document is public | ||
if (!$document->is_public) { | ||
abort(403); | ||
} | ||
|
||
// Copy the file to a new location | ||
$newPath = 'documents/' . auth()->id() . '/' . Str::random(40) . '.pdf'; | ||
Storage::copy($document->file_path, $newPath); | ||
|
||
// Create a new document record | ||
$newDocument = Document::create([ | ||
'file_path' => $newPath, | ||
'file_name' => $document->file_name, | ||
'file_size' => $document->file_size, | ||
'user_id' => auth()->id(), | ||
'is_public' => false, | ||
]); | ||
|
||
return redirect()->route('documents.show', $newDocument) | ||
->with('success', 'Document copied successfully to your library.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use App\Models\Document; | ||
use App\Models\Thread; | ||
use Livewire\Component; | ||
|
||
class PublicChatInterface extends Component | ||
{ | ||
public Document $document; | ||
public $threads; | ||
public $currentThread; | ||
|
||
public function mount(Document $document) | ||
{ | ||
$this->document = $document; | ||
$this->threads = $document->threads; | ||
$this->currentThread = $this->threads->first(); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.public-chat-interface', [ | ||
'messages' => $this->currentThread?->messages ?? collect(), | ||
]); | ||
} | ||
|
||
public function selectThread(Thread $thread) | ||
{ | ||
$this->currentThread = $thread; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use App\Models\Document; | ||
use Livewire\Component; | ||
use Livewire\WithPagination; | ||
use Illuminate\Support\Str; | ||
|
||
class SharedDocuments extends Component | ||
{ | ||
use WithPagination; | ||
|
||
public function toggleShare($documentId) | ||
{ | ||
$document = Document::where('user_id', auth()->id()) | ||
->findOrFail($documentId); | ||
|
||
if (!$document->sharing_token) { | ||
$document->update([ | ||
'sharing_token' => Str::random(32), | ||
'is_public' => true, | ||
]); | ||
} else { | ||
$document->update([ | ||
'is_public' => !$document->is_public | ||
]); | ||
} | ||
} | ||
|
||
public function render() | ||
{ | ||
$sharedDocuments = Document::where('user_id', auth()->id()) | ||
->whereNotNull('sharing_token') | ||
->latest() | ||
->paginate(10); | ||
|
||
return view('livewire.shared-documents', [ | ||
'documents' => $sharedDocuments | ||
])->layout('layouts.app'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
database/migrations/2024_11_18_040219_add_sharing_token_to_documents_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('documents', function (Blueprint $table) { | ||
$table->string('sharing_token')->nullable()->unique(); | ||
$table->boolean('is_public')->default(false); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('documents', function (Blueprint $table) { | ||
$table->dropColumn(['sharing_token', 'is_public']); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@props(['class' => 'w-5 h-5']) | ||
|
||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" {{ $attributes->merge(['class' => $class]) }}> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" /> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@props(['class' => 'w-5 h-5']) | ||
|
||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" {{ $attributes->merge(['class' => $class]) }}> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z" /> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" /> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@props(['class' => 'w-5 h-5']) | ||
|
||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" {{ $attributes->merge(['class' => $class]) }}> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M16.5 10.5V6.75a4.5 4.5 0 10-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 002.25-2.25v-6.75a2.25 2.25 0 00-2.25-2.25H6.75a2.25 2.25 0 00-2.25 2.25v6.75a2.25 2.25 0 002.25 2.25z" /> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@props(['class' => 'w-5 h-5']) | ||
|
||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" {{ $attributes->merge(['class' => $class]) }}> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M7.217 10.907a2.25 2.25 0 1 0 0 2.186m0-2.186c.18.324.283.696.283 1.093s-.103.77-.283 1.093m0-2.186 9.566-5.314m-9.566 7.5 9.566 5.314m0 0a2.25 2.25 0 1 0 3.935 2.186 2.25 2.25 0 0 0-3.935-2.186Zm0-12.814a2.25 2.25 0 1 0 3.933-2.185 2.25 2.25 0 0 0-3.933 2.185Z" /> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@props(['class' => 'w-5 h-5']) | ||
|
||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" {{ $attributes->merge(['class' => $class]) }}> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M13.5 10.5V6.75a4.5 4.5 0 119 0v3.75M3.75 21.75h10.5a2.25 2.25 0 002.25-2.25v-6.75a2.25 2.25 0 00-2.25-2.25H3.75a2.25 2.25 0 00-2.25 2.25v6.75a2.25 2.25 0 002.25 2.25z" /> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<x-full-screen-layout> | ||
<x-slot name="title"> | ||
{{ $document->file_name }} | ||
</x-slot> | ||
<div> | ||
<div class="h-[6vh] p-2 py-3 items-center flex justify-between pt-4"> | ||
<div class="text-neutral-900 font-semibold dark:text-neutral-200"> | ||
{{ $document->file_name }} | ||
</div> | ||
<div class="text-sm text-neutral-500"> | ||
{{ __('Shared Document') }} | ||
</div> | ||
</div> | ||
<div class="flex flex-col lg:grid lg:grid-cols-2 gap-2 h-auto sm:h-[94vh] p-2"> | ||
<div class="order-2 lg:order-1 flex-grow lg:flex-grow-0 flex flex-col bg-white h-full overflow-hidden dark:bg-neutral-700"> | ||
<div id="pdf-viewer" data-url="{{ $pdfUrl }}" class="w-full h-full"></div> | ||
</div> | ||
<div class="order-1 lg:order-2 flex-grow lg:flex-grow-0 h-[900px] sm:h-auto"> | ||
<livewire:public-chat-interface :document="$document" /> | ||
</div> | ||
</div> | ||
</div> | ||
</x-full-screen-layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.