created the browse page

This commit is contained in:
Ghostie 2025-01-05 15:30:54 -05:00
parent cc3fc9e7fa
commit ca797a59a8
9 changed files with 131 additions and 9 deletions

View File

@ -23,9 +23,9 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
- [ ] Check when waiting for approval
- [ ] Handle Rejection
- [x] Likes
- [ ] Comments
- [x] Comments
- [ ] Boosts
- [ ] Tags
- [x] Tags
- [ ] Pinned Posts
- [-] Social features
@ -37,6 +37,7 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
- [ ] Mark account as private (in federation manual approval is needed)
- [ ] Allow custom CSS
- [ ] Profile audio
- [ ] Top 8 friends
- [x] Friends (they are known as follows in the activitypub protocol)
- [x] Add friends
- [x] Remove friends
@ -44,9 +45,9 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
- [x] Create posts
- [x] Delete posts
- [x] Like posts
- [ ] Comment posts
- [x] Comment posts
- [ ] Boost posts
- [ ] Post tags
- [x] Post tags
- [ ] Blog
- [ ] Bulletin
- [ ] Groups

View File

@ -7,6 +7,8 @@ use App\Actions\ActionsFriends;
use App\Models\User;
use App\Models\Actor;
use App\Models\Note;
use App\Models\Hashtag;
use GuzzleHttp\Client;
@ -21,6 +23,22 @@ class HomeController extends Controller
return view ("home", compact ("latest_users"));
}
public function browse ()
{
$latest_users = User::latest ()->take (8)->get ();
$popular_hashtags = Hashtag::withCount ("get_notes")->orderBy ("get_notes_count", "desc")->take (16)->get ()->shuffle ();
$popular_notes = Note::withCount ([ "get_likes" => function ($query) {
$query->where ("created_at", ">=", now ()->subDay ());
}])->where ("in_reply_to", null)->orderBy ("get_likes_count", "desc")->take (8)->get ();
return view ("browse", compact ("latest_users", "popular_hashtags", "popular_notes"));
}
public function tag ($tag)
{
dd ($tag);
}
public function search ()
{
$query = request ()->get ("query");

View File

@ -134,7 +134,7 @@ class User extends Authenticatable
$friends_id[] = Actor::where ("actor_id", $friend)->first ()->id;
}
$notes = Note::whereIn ("actor_id", $friends_id)->where ("in_reply_to", null)->orderBy ("created_at", "desc")->get ();
$notes = Note::whereIn ("actor_id", $friends_id)->orderBy ("created_at", "desc")->get ();
return $notes;
}

View File

@ -3730,3 +3730,20 @@ audio {
width: 80px;
transition: 0.5s width;
}
ul.cloud {
list-style: none;
padding-left: 0;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
ul.cloud a {
display: block;
padding: 0.125rem 0.25rem;
text-decoration: none;
position: relative;
}

View File

@ -0,0 +1,76 @@
@extends ("partials.layout")
@section ("title", "Explore")
@section ("content")
<div class="simple-container">
<h1>Browse Users</h1>
<div class="new-people">
<div class="top">
<h4>Active Users</h4>
<a href="#" class="more">[random]</a>
</div>
<div class="inner">
@foreach ($latest_users as $user)
<x-user_block :user="$user" />
@endforeach
</div>
</div>
<h1>Popular Hashtags</h1>
<div class="new-people">
<div class="top">
<h4>Hashtags</h4>
</div>
<div class="inner">
<ul class="cloud">
@foreach ($popular_hashtags as $hashtag)
<li>
<a href="{{ route ('tags', [ 'tag' => substr ($hashtag->name, 1) ]) }}"
data-weight="{{ $hashtag->get_notes_count }}">
{{ $hashtag->name }}
</a>
</li>
@endforeach
</ul>
</div>
</div>
<h1>Trending Posts</h1>
<small>The posts with the most likes in the last 24 hours</small>
<table class="comments-table" cellspacing="0" cellpadding="3" bordercollor="#ffffff" border="1">
<tbody>
@foreach ($popular_notes as $post)
<x-comment_block :post="$post" :actor="$post->get_actor ()->first ()" />
@endforeach
</tbody>
</table>
</div>
<script>
document.addEventListener ("DOMContentLoaded", () => {
const links = document.querySelectorAll ("ul.cloud a");
let max_weight = 0;
links.forEach ((link) => {
const weight = parseInt (link.getAttribute ("data-weight"));
if (weight > max_weight) {
max_weight = weight;
}
});
links.forEach ((link) => {
const weight = parseInt (link.getAttribute ("data-weight"));
const size = Math.round ((weight / max_weight) * 210);
link.style.fontSize = `${size}%`;
});
})
</script>
@endsection

View File

@ -83,7 +83,7 @@ else
<p>
<b>Tags:</b>
@foreach ($post->get_hashtags ()->get () as $hashtag)
<a href="#">
<a href="{{ route ('tags', [ 'tag' => substr ($hashtag->name, 1) ]) }}">
<span class="tag">{{ $hashtag->name }}</span>
</a>
@endforeach

View File

@ -39,7 +39,7 @@
</li>
<li>
<a href="#">&nbsp;Browse </a>
<a href="{{ route ('browse') }}">&nbsp;Browse </a>
</li>
<li>

View File

@ -33,6 +33,7 @@
<img loading="lazy" src="/resources/img/green_person.png" alt="online"> ONLINE!
</p>
@endif
<p><b>Joined: </b> {{ $user->created_at->diffForHumans () }}</p>
</div>
@endif
@ -277,7 +278,16 @@
</b>
</p>
<div class="friends-grid"></div>
<div class="friends-grid">
@foreach ($user->mutual_friends () as $key => $friend)
@if ($key > 8)
@break
@endif
@php $friend = \App\Models\Actor::where ('actor_id', $friend)->first (); @endphp
<x-user_block :user="$friend" />
@endforeach
</div>
</div>
</div>

View File

@ -36,7 +36,7 @@ Route::get ("/post/{note}", [ PostController::class, "show" ])->name ("posts.sho
Route::delete ("/post/{note}", [ PostController::class, "delete" ])->name ("posts.delete")->middleware ("auth");
// other routes
Route::get ("/browse", [ HomeController::class, "browse" ])->name ("browse"); // TODO: This
Route::get ("/browse", [ HomeController::class, "browse" ])->name ("browse");
Route::get ("/tags/{tag}", [ HomeController::class, "tag" ])->name ("tags"); // TODO: This
Route::get ("/search", [ HomeController::class, "search" ])->name ("search");
Route::get ("/requests", [ HomeController::class, "requests" ])->name ("requests")->middleware ("auth");