Skip to content

Commit

Permalink
Clean dead code and add missing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
max15015 committed Dec 17, 2024
1 parent a3d46b1 commit 9cb9593
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 231 deletions.
62 changes: 57 additions & 5 deletions app/Models/Friendship.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,86 @@ class Friendship extends Model
{
use HasFactory;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'friendships';

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'friend_id',
'status',
];

/**
* Get the user that owns the friendship.
*
* This defines the relationship between the Friendship model and the User model.
* A friendship belongs to a user, identified by the 'user_id'.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id'); // Relation avec le modèle User
return $this->belongsTo(User::class, 'user_id');
}

/**
* Get the friend associated with the friendship.
*
* This defines the relationship between the Friendship model and the User model.
* A friendship belongs to a friend, identified by the 'friend_id'.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function friend(): BelongsTo
{
return $this->belongsTo(User::class, 'friend_id'); // Relation avec le modèle User
return $this->belongsTo(User::class, 'friend_id');
}

/**
* Determine if the friendship is accepted.
*
* This method checks if the friendship status is 'accepted'.
* It returns true if the status is 'accepted', otherwise false.
*
* @return bool
*/
public function isAccepted(): bool
{
return $this->status === 'accepted'; // Retourne true si le statut est 'accepted'
return $this->status === 'accepted';
}

/**
* Determine if the friendship is pending.
*
* This method checks if the friendship status is 'pending'.
* It returns true if the status is 'pending', otherwise false.
*
* @return bool
*/
public function isPending(): bool
{
return $this->status === 'pending'; // Retourne true si le statut est 'pending'
return $this->status === 'pending';
}

/**
* Determine if the friendship is blocked.
*
* This method checks if the friendship status is 'blocked'.
* It returns true if the status is 'blocked', otherwise false.
*
* @return bool
*/
public function isBlocked(): bool
{
return $this->status === 'blocked'; // Retourne true si le statut est 'blocked'
return $this->status === 'blocked';
}
}
25 changes: 23 additions & 2 deletions app/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,29 @@ class Message extends Model
{
use HasFactory;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'messages';

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'message',
'chat_id',
'user_id',
];

/**
* Chat where message was sent
* Get the chat that the message belongs to.
*
* This method defines the relationship between the Message model and the Chat model.
* A message belongs to a chat, identified by the 'chat_id'.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
Expand All @@ -27,7 +40,15 @@ public function chats()
return $this->belongsTo(Chat::class);
}

public function user() // Utiliser 'user()' au lieu de 'users()'
/**
* Get the user that sent the message.
*
* This method defines the relationship between the Message model and the User model.
* A message belongs to a user, identified by the 'user_id'.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
En attente
</a>
</div>
<!-- Bouton "Ajouter" aligné à droite -->
<div class="ml-auto">
<a href="{{ route('friends.create') }}" class="text-white btn-inactive font-semibold py-1 px-3 rounded-full
{{ Route::currentRouteName() === 'friends.create' ? 'btn-active' : 'btn-inactive' }}">
Expand Down
6 changes: 3 additions & 3 deletions resources/views/components/messaging/chatbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class="rounded-full secondary-background-app p-2 flex items-center justify-cente
@csrf
<input type="hidden" id="discussion-id" name="discussion_id" value="CHAT_ID">
<h3 class="text-lg font-semibold text-gray-300 mb-5">Créer une capsule</h3>
<!-- Field for the file of the capsule -->

<div class="flex items-center justify-center h-full w-full">
<div class="border-dashed border-4 border-gray-500 rounded-lg bg-gray-900 hover:bg-gray-700 transition duration-300" ondrop="handleDrop(event)" ondragover="handleDragOver(event)">
<label for="file" class="flex flex-col items-center justify-center cursor-pointer h-full w-full">
Expand All @@ -29,7 +29,7 @@ class="rounded-full secondary-background-app p-2 flex items-center justify-cente
<input id="file" name="file" type="file" class="inset-0 opacity-0 cursor-pointer" accept=".jpeg,.png,.jpg,.gif,.mp3,.mp4,.mov" onchange="updateFileName()" x-model="file" required>
</div>
</div>
<!-- Field for the message of the capsule -->

<div class="mb-4">
<x-input-label for="message" value="Message" />
<x-text-input id="message" name="message" type="text" class="block w-full mt-1" x-model="chatMessage" required />
Expand All @@ -38,7 +38,7 @@ class="rounded-full secondary-background-app p-2 flex items-center justify-cente
<input type="datetime-local" id="date-time" name="date_time" class="block w-full mt-1 border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm" />
</div>
</div>
<!-- Action buttons -->

<div class="mt-6 flex justify-end">
<x-secondary-button x-on:click="$dispatch('close'); document.getElementById('create-file-modal-form').reset(); document.getElementById('file-info').innerHTML = '<p class=&quot;text-gray-300 font-medium&quot;>Glissez et déposez votre fichier ici ou</p><p class=&quot;text-blue-400 underline&quot;>cliquez pour sélectionner un fichier</p>';">
Annuler
Expand Down
56 changes: 36 additions & 20 deletions resources/views/components/messaging/discussion-sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,41 @@ class="flex items-center justify-center">
<form method="post" action="{{ route('chats.store') }}" class="p-6" x-data="chatForm()"
x-on:submit.prevent="validateForm">
@csrf
<!-- Chat name field -->

<div class="mb-4">
<x-input-label for="chat-name" value="Nom de la discussion" />
<x-text-input id="chat-name" name="chat_name" type="text" class="block w-full mt-1"
required x-model="chatName" />
<p x-show="errors.chatName" class="text-red-500 text-sm mt-1">Le nom de la discussion
est requis.</p>
</div>
<!-- Friends list with checkboxes -->

<div class="mb-4">
<p class="font-medium text-white">Sélectionnez le/les amis à ajouter à la discussion</p>
<div class="mt-2 overflow-y-auto max-h-48 scrollbar-hide rounded p-2">
@foreach ($friends as $friend)
<div
class="flex items-center justify-between mb-2 p-2 rounded hover:bg-gray-700 transition-colors">
<div class="flex items-center">
@if ($friend->image)
<img src="{{ asset('storage/' . $friend->image) }}" alt="Avatar" class="w-8 h-8 rounded-full mr-3">
@else
<img src="{{ asset('source/assets/avatar/avatar.png') }}"
alt="Avatar" class="w-8 h-8 rounded-full mr-3">
@endif
<span class="text-white font-medium">{{ $friend->name }}</span>
<div
class="flex items-center justify-between mb-2 p-2 rounded hover:bg-gray-700 transition-colors">
<div class="flex items-center">
@if ($friend->image)
<img src="{{ asset('storage/' . $friend->image) }}" alt="Avatar"
class="w-8 h-8 rounded-full mr-3">
@else
<img src="{{ asset('source/assets/avatar/avatar.png') }}"
alt="Avatar" class="w-8 h-8 rounded-full mr-3">
@endif
<span class="text-white font-medium">{{ $friend->name }}</span>
</div>
<input type="checkbox" name="friends[]" value="{{ $friend->id }}"
class="h-5 w-5 bg-gray-400 rounded-full focus:ring-0 border-none checked:bg-gray-500"
x-model="selectedFriends">
</div>
<input type="checkbox" name="friends[]" value="{{ $friend->id }}"
class="h-5 w-5 bg-gray-400 rounded-full focus:ring-0 border-none checked:bg-gray-500"
x-model="selectedFriends">
</div>
@endforeach
<p x-show="errors.friends" class="text-red-500 text-sm mt-1">Sélectionnez au moins
un ami.</p>
</div>
</div>
<!-- Action buttons -->

<div class="mt-6 flex justify-end">
<x-secondary-button x-on:click="$dispatch('close')">
Annuler
Expand All @@ -68,8 +69,9 @@ class="h-5 w-5 bg-gray-400 rounded-full focus:ring-0 border-none checked:bg-gray
@foreach ($discussions as $discussion)
<li class="flex items-center p-2 border-b border-black overflow-hidden mr-2 cursor-pointer"
onclick="loadChat({{ $discussion->id }}, '{{ $discussion->name }}', '{{ $discussion->discussionPicture }}', {{ $discussion->members }}, {{ true }})">
<img src="{{ $discussion->discussionPicture }}" alt="Avatar" class="w-10 h-10 rounded-full mr-3 flex-shrink-0">
<!-- Ajout de flex-shrink-0 pour éviter que l'image rétrécisse -->
<img src="{{ $discussion->discussionPicture }}" alt="Avatar"
class="w-10 h-10 rounded-full mr-3 flex-shrink-0">

<div class="flex-1">
<div class="font-bold">{{ $discussion->name }}</div>
<div class="text-sm text-gray-400 whitespace-nowrap">
Expand All @@ -78,29 +80,43 @@ class="h-5 w-5 bg-gray-400 rounded-full focus:ring-0 border-none checked:bg-gray
@endif
</div>
</div>
</li>
</li>
@endforeach
</ul>
</div>


<script>
/**
* Function to validates form for chat creation
*/
function chatForm() {
return {
chatName: '',
selectedFriends: [],
errors: {
friends: false,
},
// Validates the form before submission
validateForm() {
// Check if any friends are selected
this.errors.friends = this.selectedFriends.length === 0;
// Get the button and loader elements
let createChatBtn = document.getElementById('create-chat');
let createChatLoader = document.getElementById('create-chat-loader');
// Show the loader and hide the button while validating
createChatBtn.style.display = 'none';
createChatLoader.style.display = 'block';
// Submit the form if no errors, otherwise keep the loader visible
if (!this.errors.friends) {
this.$el.submit();
}
// Hide the loader and show the button again
createChatBtn.style.display = 'block';
createChatLoader.style.display = 'none';
}
Expand Down
8 changes: 0 additions & 8 deletions resources/views/components/messaging/header.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
@php
$members = [
['name' => 'Jean Dupont', 'avatar' => 'https://via.placeholder.com/40'],
['name' => 'Marie Curie', 'avatar' => 'https://via.placeholder.com/40'],
['name' => 'Albert Einstein', 'avatar' => 'https://via.placeholder.com/40'],
];
@endphp

<div class="flex background-app border-b border-black h-12 items-center justify-between p-4 gap-x-4">
<div class="flex items-center gap-x-4">
<img src="" alt="Discussion Picture" class="w-10 h-10 rounded-full headerImage">
Expand Down
2 changes: 0 additions & 2 deletions resources/views/components/messaging/home-section.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<div class="flex flex-col items-center justify-center h-full w-full text-white bg-gray-800 bg-cover bg-center messagesBackground">
<!-- Logo -->
<img src="{{ asset('source/assets/images/logo.png') }}" alt="Logo" class="w-[30%] mb-6" />

<!-- Text description of the application -->
<p class="text-center text-xl font-semibold w-[75%]">
Bienvenue sur T-CAPS !
</p>
Expand Down
6 changes: 3 additions & 3 deletions resources/views/components/messaging/messages.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Message section with overflow and height adjusted -->
<div id="messages" class="flex-1 overflow-y-auto text-white p-4 scrollbar-hide bg-cover bg-center messagesBackground">

</div>
<div id="messages" class="flex-1 overflow-y-auto text-white p-4 scrollbar-hide bg-cover bg-center messagesBackground">

</div>

Loading

0 comments on commit 9cb9593

Please sign in to comment.