Skip to content

Commit

Permalink
implemented following (AKA discover) & fyp using new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
pablouser1 committed Aug 28, 2024
1 parent 96aa280 commit ec61147
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 7 deletions.
23 changes: 23 additions & 0 deletions app/Controllers/FollowingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace App\Controllers;

use App\Helpers\ErrorHandler;
use App\Helpers\Misc;
use App\Helpers\Wrappers;
use App\Models\FeedTemplate;

class FollowingController {
public static function get() {
$cursor = Misc::getCursor();

$api = Wrappers::api();
$following = $api->following();
$following->feed($cursor);
if ($following->ok()) {
$feed = $following->getFeed();
Wrappers::latte('following', new FeedTemplate('Following / Discover', $feed));
} else {
ErrorHandler::showMeta($following->error());
}
}
}
33 changes: 33 additions & 0 deletions app/Controllers/ForYouController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace App\Controllers;

use App\Helpers\ErrorHandler;
use App\Helpers\Misc;
use App\Helpers\Wrappers;
use App\Models\FeedTemplate;
use App\Models\RSSTemplate;

class ForYouController {
public static function get() {
$api = Wrappers::api();
$fyp = $api->foryou();
$fyp->feed();
if ($fyp->ok()) {
$feed = $fyp->getFeed();
Wrappers::latte('foryou', new FeedTemplate('For you', $feed));
} else {
ErrorHandler::showMeta($fyp->error());
}
}

public static function rss() {
$api = Wrappers::api();
$fyp = $api->foryou();
$fyp->feed();
if ($fyp->ok()) {
$feed = $fyp->getFeed();
Misc::rss('For you');
Wrappers::latte('rss', new RSSTemplate('For you', 'For you Page', '', Misc::url('/foryou'), $feed->items));
}
}
}
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@

$router->get('/music/([^/]+)', 'MusicController@get');

// For you
$router->mount('/foryou', function () use ($router) {
$router->get('/', 'ForYouController@get');
$router->get('/rss', 'ForYouController@rss');
});

$router->get('/following', 'FollowingController@get');

// -- Settings -- //
$router->mount('/settings', function () use ($router) {
$router->get('/', 'SettingsController@index');
Expand Down
39 changes: 39 additions & 0 deletions templates/views/following.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{layout '../layouts/default.latte'}

{block header}
<p class="title">Discover</p>
{/block}

{block content}
<div class="columns is-multiline is-vcentered">
{foreach $feed->items as $item}
<div class="column is-one-quarter">
{embed '../components/card.latte'}
{block content}
<div class="media">
<!-- Show image if exists -->
{if !empty($item->info->detail->avatarLarger)}
<div class="media-left">
<figure class="image is-96x96">
<img loading="lazy" width="96" height="96" src="{url_stream($item->info->detail->avatarLarger)}" />
</figure>
</div>
{/if}
<div class="media-content">
<p class="title">{$item->info->detail->nickname}</p>
<p class="subtitle">{$item->info->detail->uniqueId}</p>
</div>
</div>
<div class="content">
<p>{$item->info->detail->signature}</p>
</div>
{/block}
{block footer}
<a href="{url_user($item->info->detail->uniqueId)}" class="card-footer-item">Go</a>
{/block}
{/embed}
</div>
{/foreach}
</div>
{include '../components/themes/common/controls.latte', feed: $feed}
{/block}
12 changes: 12 additions & 0 deletions templates/views/foryou.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{layout '../layouts/default.latte'}

{var $has_rss = true}

{block header}
<p class="title">For you</p>
<p class="subtitle">{include '../components/rss.latte'}</p>
{/block}

{block content}
{include '../components/feed.latte'}
{/block}
10 changes: 10 additions & 0 deletions templates/views/home.latte
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@
</div>
{/block}
{/embed}
<div class="columns is-centered is-mobile mt-2">
<div class="column is-narrow">
<p>For you</p>
<a class="button is-success" href="{path('/foryou')}">Go</a>
</div>
<div class="column is-narrow">
<p>Following</p>
<a class="button is-success" href="{path('/following')}">Go</a>
</div>
</div>
{/block}

0 comments on commit ec61147

Please sign in to comment.