Skip to content

Commit

Permalink
Support Guest Comment
Browse files Browse the repository at this point in the history
  • Loading branch information
vigstudio committed Feb 13, 2023
1 parent c7f6439 commit a12724e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 155 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"homepage": "https://github.com/vigstudio/livewire-comments",
"license": "MIT",
"type": "laravel-library",
"version": "1.0.10",
"version": "1.0.11",
"authors": [
{
"name": "Nghiane.com",
Expand Down
2 changes: 1 addition & 1 deletion public/css/comments.css

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions resources/sass/comments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@

@apply mb-4 w-full bg-gray-50 rounded-lg border border-gray-200;

.vcomments__form__guest {
@apply flex py-2 px-3 border-b;

.vgcomments__form__guest__input {
@apply block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm ml-4;
}
}

.vcomments__form__header {
@apply flex justify-between items-center py-2 px-3 border-b;

Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/comments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
</div>


<script src="https://www.google.com/recaptcha/api.js?render={{ Config::get('vgcomment.recaptcha_key') ?? 'xxx' }}"></script>
<script src="https://www.google.com/recaptcha/api.js?render={{ Config::get('vgcomment.recaptcha_key') }}"></script>
</div>
138 changes: 0 additions & 138 deletions resources/views/livewire/form-guest.blade.php

This file was deleted.

32 changes: 23 additions & 9 deletions resources/views/livewire/form.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div wire:ignore.self x-data="LivewireComments.form('.textarea-vgcomment-box', $wire)"
<div @disabled(!$this->auth && !$this->allow_guest) wire:ignore.self x-data="LivewireComments.form('.textarea-vgcomment-box', $wire)"
x-init="emojiPicker('.emoji-button')"
@insert-content.window="afterUpload($event)"
@post-success-comments.window="cleanData()"
Expand All @@ -13,17 +13,31 @@
}
}">



<div class="vcomments__form">
@if ($this->allow_guest && !$this->auth)
<div class="vcomments__form__guest">

<input @disabled(session()->has('author')) wire:model.defer="request.author_name" placeholder="Name" type="text" autocomplete="given-name" class="vgcomments__form__guest__input">

<input @disabled(session()->has('author')) wire:model.defer="request.author_email" placeholder="Email" type="email" autocomplete="family-name" class="vgcomments__form__guest__input">

<input @disabled(session()->has('author')) wire:model.defer="request.author_url" placeholder="Url" type="text" autocomplete="email" class="vgcomments__form__guest__input">

</div>
@endif

<div class="vcomments__form__header">

<div class="vcomments__header__tooltips-group">

<button x-show="tab == 2" x-on:click="tab = 1" type="button" class="vcomments__btn secondary">
<button @disabled(!$this->auth && !$this->allow_guest) x-show="tab == 2" x-on:click="tab = 1" type="button" class="vcomments__btn secondary">
<x-heroicons::icon name="eye-slash-o" class="vgcomemnt_icon-5" />
<span class="vgcomments__header_title"></span>
</button>

<button x-show="tab == 1" x-on:click="tab = 2" type="button" class="vcomments__btn secondary" wire:click="preview">
<button @disabled(!$this->auth && !$this->allow_guest) x-show="tab == 1" x-on:click="tab = 2" type="button" class="vcomments__btn secondary" wire:click="preview">
<x-heroicons::icon name="eye-o" class="vgcomemnt_icon-5" />
<span class="vgcomments__header_title">{{ __('vgcomment::comment.preview') }}</span>
</button>
Expand All @@ -41,13 +55,13 @@

<input x-ref="uploadFiles" x-on:change="uploadFile($event)" type="file" class="sr-only" multiple="true">

<button type="button" class="emoji-button vcomments__btn secondary" data-popover-target="emoji">
<button @disabled(!$this->auth && !$this->allow_guest) type="button" class="emoji-button vcomments__btn secondary" data-popover-target="emoji">
<x-heroicons::icon name="face-smile-s" class="vgcomemnt_icon-4" />
</button>



<button type="button" class="vcomments__btn secondary" x-on:click="$refs.uploadFiles.click()">
<button @disabled(!$this->auth && !$this->allow_guest) type="button" class="vcomments__btn secondary" x-on:click="$refs.uploadFiles.click()">

<x-heroicons::icon name="paper-clip-s" class="vgcomemnt_icon-4" />

Expand All @@ -65,7 +79,7 @@
<x-livewire-comments::forms.textarea
@class([
'textarea-vgcomment-box',
'disabled' => !$this->auth,
'disabled' => !$this->auth && !$this->allow_guest,
'validate-error' => $errors->has('content'),
])
wire:model.defer="request.content"
Expand Down Expand Up @@ -98,11 +112,11 @@
<button
type="button"
x-on:click="submit()"
@disabled(!$this->auth)
@disabled(!$this->auth && !$this->allow_guest)
@class([
'vcomments__btn',
'disabled' => !$this->auth,
'primary' => $this->auth,
'disabled' => !$this->auth && !$this->allow_guest,
'primary' => $this->auth || $this->allow_guest,
])
wire:loading.attr="disabled">

Expand Down
19 changes: 14 additions & 5 deletions src/Http/Livewire/FormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public function mount()
$this->request['content'] = CommentServiceFacade::findById($this->editId)?->content;
}

if (session()->has('author')) {
$this->request['author_name'] = session('author.name');
$this->request['author_email'] = session('author.email');
$this->request['author_url'] = session('author.url');
}

$this->request['page_id'] = $this->pageId;
$this->request['commentable_id'] = ! empty($this->commentable) ? $this->commentable->id : null;
$this->request['commentable_type'] = ! empty($this->commentable) ? get_class($this->commentable) : null;
Expand All @@ -64,13 +70,16 @@ public function getAuthProperty()
return CommentServiceFacade::getAuth();
}

public function getAllowGuestProperty()
{
$allowGuest = Config::get('vgcomment.allow_guests');

return $allowGuest;
}

public function render()
{
if ($this->auth) {
return view('livewire-comments::livewire.form');
} else {
return view('livewire-comments::livewire.form-guest');
}
return view('livewire-comments::livewire.form');
}

public function submit()
Expand Down

0 comments on commit a12724e

Please sign in to comment.