Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Controllers/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function show(Article $article): View
/** @var User $user */
$user = Auth::user();

views($article)->record();
views($article)->cooldown(now()->addHours(2))->record();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Que résoud cette action et quel comportement tu reçois et comment devrait-il normalement se comporter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

views($article)->record();
la première ligne comptabilise chaque vue sans restriction, tandis que views($article)->cooldown(now()->addHours(2))->record(); impose une attente de 2 heures entre les enregistrements de vues pour le même article.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si 50 personnes regardent l'article au bout de 10 minutes il n'enregistre pas les 50 records ? Ou tu dis qu'il va enregistrer les 50 records après 2h

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non c'est pour dire que un utilisateur ne pourrait voir le post deux fois de suite, genre sa vue sera mis en cache de tel sorte que si il voit un poste, en actualisant le navigateur, on considérera que il a déjà vu le post , la le nombre de vue ne sera pas incrémenté cela pendant les deux prochaines heures. donc la vue de post par cette utilisateur sera gelée.


/** @var Article $article */
$article = Cache::remember('post-'.$article->id, now()->addHour(), fn () => $article);
Expand Down Expand Up @@ -66,4 +66,4 @@ public function edit(Article $article): View

return view('articles.edit', compact('article'));
}
}
}
4 changes: 2 additions & 2 deletions app/Http/Livewire/Discussions/AddComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function saveComment(): void
->duration(5000)
->send();

$this->reset();
$this->reset('body');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est la même chose. Le reset réinitialise toutes les variables du formulaire

}

public function render(): View
{
return view('livewire.discussions.add-comment');
}
}
}
13 changes: 13 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,16 @@ function route_to_reply_able(mixed $replyAble): string
route('discussions.show', $replyAble->slug());
}
}

if(! function_exists('getAvatar')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas nécessaire

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici je voulais faire une illustration afin de simuler l'utilisation du onerror, ce n'était pas définitif.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faut supprimer cette fonction du coup on ne garde pas du coup qui n'est pas utile

/**
* @param $title
* @param bool $rounded
*
* @return string
*/
function getAvatar($title,bool $rounded=false): string
{
return 'https://ui-avatars.com/api/?name=' . urlencode($title). '&background=random&bold=true&format=svg&size=512&rounded='.$rounded;
}
}
4 changes: 2 additions & 2 deletions resources/views/articles/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha
<div>
<h2 class="text-xs leading-5 tracking-wide uppercase text-skin-base">{{ __('Article suivant') }}</h2>
<div class="mt-3 flex items-start space-x-2">
<img class="h-10 w-10 object-cover shadow-lg rounded-md" src="{{ $next->getFirstMediaUrl('media') ?? asset('images/socialcard.png') }}" alt="{{ $next->slug }}">
<img class="h-10 w-10 object-cover shadow-lg rounded-md" src="{{ $next->getFirstMediaUrl('media') ?? asset('images/socialcard.png') }}" alt="{{ $next->slug }}" onerror="this.onerror=null;this.src='{{ getAvatar($next->title) }}'">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le onerror c'est quoi son utilité vu que il y'a déjà une condition? C'est la condition qu'il faut revoir

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le onerror gère les erreurs de chargement d'image et utilise une image alternative si le chargement échoue, ce qui améliore l'expérience utilisateur en fournissant une option de secours. car j'ai remarque sur la plateforme des images n'ayant pas chargé donc n'existant pas, et la place c'est le title de l'image qui s'affichait et cela détruisait l'ui

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est la condition qu'il faut corriger dans ce cas parce que si un article n'a pas d'image il y'a un placeholder normalement

<div class="flex flex-col space-y-1">
<a class="text-base font-medium leading-4 text-skin-inverted hover:text-skin-primary-hover line-clamp-2" href="{{ route('articles.show', $next) }}">{{ $next->title }}</a>
<span class="text-sm text-skin-muted">{{ __(':time min de lecture', ['time' => $next->readTime()]) }}</span>
Expand All @@ -264,7 +264,7 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha
<div>
<h2 class="text-xs leading-5 tracking-wide uppercase text-skin-base">{{ __('Article précédent') }}</h2>
<div class="mt-3 flex items-start space-x-2">
<img class="h-10 w-10 object-cover shadow-lg rounded-md" src="{{ $previous->getFirstMediaUrl('media') ?? asset('images/socialcard.png') }}" alt="{{ $previous->slug }}">
<img class="h-10 w-10 object-cover shadow-lg rounded-md" src="{{ $previous->getFirstMediaUrl('media') ?? asset('images/socialcard.png') }}" alt="{{ $previous->slug }}" onerror="this.onerror=null;this.src='{{ getAvatar($previous->title) }}'">
<div class="flex flex-col space-y-1">
<a class="text-base font-medium leading-4 text-skin-inverted hover:text-skin-primary-hover line-clamp-2" href="{{ route('articles.show', $previous) }}">{{ $previous->title }}</a>
<span class="text-sm text-skin-muted">{{ __(':time min de lecture', ['time' => $previous->readTime()]) }}</span>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/articles/card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
>
<a href="{{ route('articles.show', $article) }}" class="group">
<div class="aspect-w-3 aspect-h-2">
<img class="object-cover shadow-lg rounded-lg group-hover:opacity-75" src="{{ $article->getFirstMediaUrl('media') }}" alt="{{ $article->title }}" />
<img class="object-cover shadow-lg rounded-lg group-hover:opacity-75" src="{{ $article->getFirstMediaUrl('media') }}" alt="{{ $article->title }}" onerror="this.onerror=null;this.src='{{ getAvatar($article->title) }}'" />
</div>
</a>
<div
Expand Down