From 6ddfff6a60a2eb80aedce33d4cd2d90f85b1f49c Mon Sep 17 00:00:00 2001 From: Jaton David Date: Mon, 16 Dec 2024 14:43:35 +0100 Subject: [PATCH] Loader on button that interract with db --- .../components/messaging/chatbar.blade.php | 86 ++++++++++--------- .../messaging/discussion-sidebar.blade.php | 66 +++++++------- resources/views/dashboard.blade.php | 7 +- resources/views/friendships/create.blade.php | 31 ++++--- 4 files changed, 108 insertions(+), 82 deletions(-) diff --git a/resources/views/components/messaging/chatbar.blade.php b/resources/views/components/messaging/chatbar.blade.php index 3b64ccb..3c93bdc 100644 --- a/resources/views/components/messaging/chatbar.blade.php +++ b/resources/views/components/messaging/chatbar.blade.php @@ -5,9 +5,13 @@ class="rounded-full secondary-background-app p-2 flex items-center justify-cente Icone - + +
@csrf @@ -77,46 +81,46 @@ function handleDrop(event) { \ No newline at end of file diff --git a/resources/views/components/messaging/discussion-sidebar.blade.php b/resources/views/components/messaging/discussion-sidebar.blade.php index 4405298..e25b602 100644 --- a/resources/views/components/messaging/discussion-sidebar.blade.php +++ b/resources/views/components/messaging/discussion-sidebar.blade.php @@ -28,21 +28,21 @@ class="flex items-center justify-center">

Sélectionnez le/les amis à ajouter à la discussion

@foreach ($friends as $friend) -
-
- @if ($friend->image) - Avatar - @else - Avatar - @endif - {{ $friend->name }} -
- +
+
+ @if ($friend->image) + Avatar + @else + Avatar + @endif + {{ $friend->name }}
+ +
@endforeach

Sélectionnez au moins un ami.

@@ -53,9 +53,12 @@ class="h-5 w-5 bg-gray-400 rounded-full focus:ring-0 border-none checked:bg-gray Annuler - + Créer la discussion +
@@ -63,19 +66,19 @@ class="h-5 w-5 bg-gray-400 rounded-full focus:ring-0 border-none checked:bg-gray
@foreach ($discussions as $discussion) -
  • - Avatar - -
    -
    {{ $discussion->name }}
    -
    - @if ($discussion->messages->first()) - {{ $discussion->messages->first()->message }} - @endif -
    +
  • + Avatar + +
    +
    {{ $discussion->name }}
    +
    + @if ($discussion->messages->first()) + {{ $discussion->messages->first()->message }} + @endif
    -
  • + + @endforeach @@ -92,12 +95,17 @@ function chatForm() { validateForm() { // Réinitialise l'erreur des amis this.errors.friends = this.selectedFriends.length === 0; - + let createChatBtn = document.getElementById('create-chat'); + let createChatLoader = document.getElementById('create-chat-loader'); + createChatBtn.style.display = 'none'; + createChatLoader.style.display = 'block'; if (!this.errors.friends) { // Soumet le formulaire si la validation passe this.$el.submit(); } + createChatBtn.style.display = 'block'; + createChatLoader.style.display = 'none'; } } } - + \ No newline at end of file diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 093c678..291777f 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -206,6 +206,8 @@ function startAutoRefresh(intervalTime = 5000) { function sendMessage() { const messageContent = document.getElementById('message-content').value; + document.getElementById('send-message-btn').style.display = 'none'; + document.getElementById('send-message-loader').style.display = 'block'; if (!messageContent) return; fetch(`/chat/${currentChatId}/messages`, { @@ -223,6 +225,8 @@ function sendMessage() { document.getElementById('message-content').value = ''; }) .catch(error => console.error('Erreur:', error)); + document.getElementById('send-message-btn').style.display = 'block'; + document.getElementById('send-message-loader').style.display = 'none'; } function scrollToBottom() { @@ -253,7 +257,6 @@ function leaveChat() { } }) .then(data => { - alert(data.message || "Vous avez quitté la conversation."); currentChatId = null; document.getElementById('chat-area').style.display = 'none'; @@ -266,7 +269,7 @@ function leaveChat() { alert("Une erreur s'est produite en essayant de quitter la conversation."); }); } -leaveChatWithLoad() +function leaveChatWithLoad() { const loader = document.getElementById('leave-chat-loader'); const button = event.target; diff --git a/resources/views/friendships/create.blade.php b/resources/views/friendships/create.blade.php index 0cf3d95..4b3019d 100644 --- a/resources/views/friendships/create.blade.php +++ b/resources/views/friendships/create.blade.php @@ -6,35 +6,46 @@
    + class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 @error('name') border-red-500 @enderror" + placeholder="Enter friend's username"> @error('name') -

    {{ $message }}

    +

    {{ $message }}

    @enderror
    - + +
    @if(session('success')) -

    - {{ session('success') }} -

    +

    + {{ session('success') }} +

    @endif @if(session('error')) -

    - {{ session('error') }} -

    +

    + {{ session('error') }} +

    @endif
    + + \ No newline at end of file