1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pixelfed_ynh.git synced 2024-09-03 20:06:04 +02:00

Merge pull request #928 from pixelfed/frontend-ui-refactor

Add Curated Discover
This commit is contained in:
daniel 2019-03-02 00:22:18 -07:00 committed by GitHub
commit 2a1d4124be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 80 deletions

View file

@ -60,23 +60,34 @@ class DiscoverController extends Controller
->whereSlug($slug) ->whereSlug($slug)
->firstOrFail(); ->firstOrFail();
// todo refactor this mess $posts = Cache::remember('discover:category-'.$tag->id.':posts', now()->addMinutes(15), function() use ($tag) {
$tagids = $tag->hashtags->pluck('id')->toArray(); $tagids = $tag->hashtags->pluck('id')->toArray();
$sids = StatusHashtag::whereIn('hashtag_id', $tagids)->orderByDesc('status_id')->take(500)->pluck('status_id')->toArray(); $sids = StatusHashtag::whereIn('hashtag_id', $tagids)->orderByDesc('status_id')->take(500)->pluck('status_id')->toArray();
$posts = Status::whereIn('id', $sids)->whereNull('uri')->whereType('photo')->whereNull('in_reply_to_id')->whereNull('reblog_of_id')->orderByDesc('created_at')->paginate(21); $posts = Status::whereScope('public')->whereIn('id', $sids)->whereNull('uri')->whereType('photo')->whereNull('in_reply_to_id')->whereNull('reblog_of_id')->orderByDesc('created_at')->take(39)->get();
$tag->posts_count = $tag->posts()->count(); return $posts;
});
$tag->posts_count = Cache::remember('discover:category-'.$tag->id.':posts_count', now()->addMinutes(30), function() use ($tag) {
return $tag->posts()->whereScope('public')->count();
});
return view('discover.tags.category', compact('tag', 'posts')); return view('discover.tags.category', compact('tag', 'posts'));
} }
public function showPersonal(Request $request) public function showPersonal(Request $request)
{ {
$profile = Auth::user()->profile; $profile = Auth::user()->profile;
// todo refactor this mess
$tags = Hashtag::whereHas('posts')->orderByRaw('rand()')->take(5)->get(); $tags = Cache::remember('profile-'.$profile->id.':hashtags', now()->addMinutes(15), function() use ($profile){
$following = $profile->following->pluck('id'); return $profile->hashtags()->groupBy('hashtag_id')->inRandomOrder()->take(8)->get();
$following = $following->push($profile->id)->toArray(); });
$posts = Status::withCount(['likes','comments'])->whereNotIn('profile_id', $following)->whereHas('media')->whereType('photo')->orderByDesc('created_at')->paginate(21); $following = Cache::remember('profile:following:'.$profile->id, now()->addMinutes(60), function() use ($profile) {
$posts->post_count = Status::whereNotIn('profile_id', $following)->whereHas('media')->whereType('photo')->count(); $res = Follower::whereProfileId($profile->id)->pluck('following_id');
return $res->push($profile->id)->toArray();
});
$posts = Cache::remember('profile-'.$profile->id.':hashtag-posts', now()->addMinutes(5), function() use ($profile, $following) {
$posts = Status::whereScope('public')->withCount(['likes','comments'])->whereNotIn('profile_id', $following)->whereHas('media')->whereType('photo')->orderByDesc('created_at')->take(39)->get();
$posts->post_count = Status::whereScope('public')->whereNotIn('profile_id', $following)->whereHas('media')->whereType('photo')->count();
return $posts;
});
return view('discover.personal', compact('posts', 'tags')); return view('discover.personal', compact('posts', 'tags'));
} }
} }

View file

@ -279,4 +279,16 @@ class Profile extends Model
{ {
return $this->hasMany(Circle::class); return $this->hasMany(Circle::class);
} }
public function hashtags()
{
return $this->hasManyThrough(
Hashtag::class,
StatusHashtag::class,
'profile_id',
'id',
'id',
'hashtag_id'
);
}
} }

View file

@ -18,10 +18,12 @@ background: linear-gradient(to right, #FFC371, #FF5F6D); /* W3C, IE 10+/ Edge, F
<div class="container"> <div class="container">
<div class="pt-4 d-flex justify-content-between align-items-center"> <div class="pt-4 d-flex justify-content-between align-items-center">
<p> <p>
@if($tags->count() > 0)
<span class="font-weight-lighter pr-3">Related hashtags:</span> <span class="font-weight-lighter pr-3">Related hashtags:</span>
@foreach($tags as $hashtag) @foreach($tags as $hashtag)
<a class="btn btn-outline-secondary btn-sm py-0 pr-2" href="{{$hashtag->url()}}">#{{$hashtag->name}}</a> <a class="btn btn-outline-secondary btn-sm py-0 pr-2" href="{{$hashtag->url()}}">#{{$hashtag->name}}</a>
@endforeach @endforeach
@endif
</p> </p>
<p class="font-weight-lighter"> <p class="font-weight-lighter">
{{$posts->post_count}} posts {{$posts->post_count}} posts
@ -50,27 +52,6 @@ background: linear-gradient(to right, #FFC371, #FF5F6D); /* W3C, IE 10+/ Edge, F
@endforeach @endforeach
</div> </div>
</div> </div>
<div class="d-flex justify-content-center pagination-container mt-4">
{{$posts->links()}}
</div>
</div> </div>
@endsection @endsection
@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
$('.pagination-container').hide();
$('.pagination').hide();
let elem = document.querySelector('.tag-timeline');
let infScroll = new InfiniteScroll( elem, {
path: '.pagination__next',
append: '.tag-timeline',
status: '.page-load-status',
history: true,
});
});
</script>
@endpush

View file

@ -2,7 +2,7 @@
@section('content') @section('content')
<div class="profile-header bg-light {{$tag->bgd ?? 'bgd-2'}}"> <div class="profile-header bg-light bgd-2">
<div class="container py-5"> <div class="container py-5">
<div class="row"> <div class="row">
<div class="col-12 col-md-3"> <div class="col-12 col-md-3">
@ -24,10 +24,12 @@
<div class="container"> <div class="container">
<div class="pt-4 d-flex justify-content-between align-items-center"> <div class="pt-4 d-flex justify-content-between align-items-center">
<p> <p>
@if($tag->hashtags->count() > 0)
<span class="font-weight-lighter pr-3">Related hashtags:</span> <span class="font-weight-lighter pr-3">Related hashtags:</span>
@foreach($tag->hashtags as $hashtag) @foreach($tag->hashtags as $hashtag)
<a class="btn btn-outline-secondary btn-sm py-0 pr-2" href="{{$hashtag->url()}}">#{{$hashtag->name}}</a> <a class="btn btn-outline-secondary btn-sm py-0 pr-2" href="{{$hashtag->url()}}">#{{$hashtag->name}}</a>
@endforeach @endforeach
@endif
</p> </p>
<p class="font-weight-lighter"> <p class="font-weight-lighter">
{{$tag->posts_count}} posts {{$tag->posts_count}} posts
@ -56,9 +58,6 @@
@endforeach @endforeach
</div> </div>
</div> </div>
<div class="d-flex justify-content-center pagination-container mt-4">
{{$posts->links()}}
</div>
</div> </div>
@endsection @endsection
@ -84,21 +83,3 @@
} }
</style> </style>
@endpush @endpush
@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
$('.pagination-container').hide();
$('.pagination').hide();
let elem = document.querySelector('.tag-timeline');
let infScroll = new InfiniteScroll( elem, {
path: '.pagination__next',
append: '.tag-timeline',
status: '.page-load-status',
history: true,
});
});
</script>
@endpush

View file

@ -44,31 +44,7 @@
@endforeach @endforeach
</div> </div>
</div> </div>
<div class="d-flex justify-content-center pagination-container mt-4">
{{$posts->links()}}
</div>
</div> </div>
@endsection @endsection
@push('meta')
<meta property="og:description" content="Discover {{$tag->name}}">
@endpush
@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
$('.pagination-container').hide();
$('.pagination').hide();
let elem = document.querySelector('.tag-timeline');
let infScroll = new InfiniteScroll( elem, {
path: '.pagination__next',
append: '.tag-timeline',
status: '.page-load-status',
history: true,
});
});
</script>
@endpush

View file

@ -59,6 +59,8 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('/home', 'HomeController@index')->name('home'); Route::get('/home', 'HomeController@index')->name('home');
Route::get('discover/c/{slug}', 'DiscoverController@showCategory');
Route::get('discover/personal', 'DiscoverController@showPersonal');
Route::get('discover', 'DiscoverController@home')->name('discover'); Route::get('discover', 'DiscoverController@home')->name('discover');
Route::group(['prefix' => 'api'], function () { Route::group(['prefix' => 'api'], function () {
@ -91,6 +93,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('shares/profile/{username}/status/{id}', 'PublicApiController@statusShares'); Route::get('shares/profile/{username}/status/{id}', 'PublicApiController@statusShares');
Route::get('status/{id}/replies', 'InternalApiController@statusReplies'); Route::get('status/{id}/replies', 'InternalApiController@statusReplies');
Route::post('moderator/action', 'InternalApiController@modAction'); Route::post('moderator/action', 'InternalApiController@modAction');
Route::get('discover/categories', 'InternalApiController@discoverCategories');
}); });
Route::group(['prefix' => 'local'], function () { Route::group(['prefix' => 'local'], function () {
Route::get('i/follow-suggestions', 'ApiController@followSuggestions'); Route::get('i/follow-suggestions', 'ApiController@followSuggestions');