Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default tab in settings with update to Feed to Recent #631

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ba72e03
added default tab in settings and web.
msamgan Sep 19, 2024
b355839
added test.
msamgan Sep 19, 2024
8a674b4
removed trending from the default tab options.
msamgan Sep 19, 2024
c04aca9
updated the / route
msamgan Sep 20, 2024
73d3330
Resoled requested changes.
msamgan Sep 20, 2024
9c2e5f7
made following tab as default.
msamgan Sep 20, 2024
0526fa1
updated requested changes.
msamgan Sep 21, 2024
0c21679
Renamed 'feed' to 'Recent.'
msamgan Sep 21, 2024
9653df6
Merge branch 'main' of https://github.com/msamgan/pinkary.com into fe…
msamgan Sep 21, 2024
58a3e39
Merge branch 'main' of https://github.com/msamgan/pinkary.com into fe…
msamgan Sep 22, 2024
98dc884
Merge Main
msamgan Sep 24, 2024
7c99874
Added the default feed to the home button.
msamgan Oct 5, 2024
de8bb08
reset unwanted format.
msamgan Oct 5, 2024
4549992
merged main.
msamgan Oct 5, 2024
73be1e4
Merge branch 'main' into feat/default-tab-454
msamgan Oct 14, 2024
41e525a
added default tab in settings and web.
msamgan Sep 19, 2024
fb8b46b
added test.
msamgan Sep 19, 2024
dc0f0dd
removed trending from the default tab options.
msamgan Sep 19, 2024
711bd00
updated the / route
msamgan Sep 20, 2024
f9d3cb4
Resoled requested changes.
msamgan Sep 20, 2024
68bccac
made following tab as default.
msamgan Sep 20, 2024
7aa7e22
updated requested changes.
msamgan Sep 21, 2024
ea59a93
Renamed 'feed' to 'Recent.'
msamgan Sep 21, 2024
cdb42ec
Added the default feed to the home button.
msamgan Oct 5, 2024
f50af1a
reset unwanted format.
msamgan Oct 5, 2024
876b31e
resolved conflict.
msamgan Oct 22, 2024
ddf9d9a
PSR
msamgan Oct 22, 2024
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
24 changes: 24 additions & 0 deletions app/Enums/Feeds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum Feeds: string
{
case Recent = 'recent';
case Following = 'following';

/**
* Get the values of the enum.
*
* @return array<string, string>
*/
public static function toArray(): array
{
return [
self::Recent->value => 'Recent',
self::Following->value => 'Following',
];
}
}
2 changes: 2 additions & 0 deletions app/Http/Requests/UserUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Http\Requests;

use App\Enums\Feeds;
use App\Enums\UserMailPreference;
use App\Models\User;
use App\Rules\NoBlankCharacters;
Expand Down Expand Up @@ -39,6 +40,7 @@ public function rules(): array
'mail_preference_time' => [Rule::enum(UserMailPreference::class)],
'bio' => ['nullable', 'string', 'max:255'],
'prefers_anonymous_questions' => ['required', 'boolean'],
'default_tab' => [Rule::enum(Feeds::class)],
];
}
}
4 changes: 2 additions & 2 deletions app/Livewire/Home/Feed.php → app/Livewire/Home/Recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Livewire\Attributes\On;
use Livewire\Component;

final class Feed extends Component
final class Recent extends Component
{
use HasLoadMore;

Expand Down Expand Up @@ -50,7 +50,7 @@ public function render(): View
->builder()
->simplePaginate($this->perPage);

return view('livewire.feed', [
return view('livewire.recent', [
'questions' => $questions,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/Filament/CitadelPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function panel(Panel $panel): Panel
->default()
->id('citadel')
->path('citadel')
->homeUrl(fn (): string => route('home.feed'))
->homeUrl(fn (): string => route('home.recent'))
->spa()
->favicon(asset('/img/ico.svg'))
->brandLogo(asset('/img/logo-text.svg'))
Expand Down
20 changes: 20 additions & 0 deletions database/migrations/2024_09_19_125543_add_default_tab_to_users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table): void {
$table->string('default_tab')->default('following')->after('mail_preference_time');
});
}
};
2 changes: 1 addition & 1 deletion resources/views/about.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>
<nav class="fixed top-0 z-20 flex w-full justify-end gap-2 border-b dark:border-slate-200/10 border-slate-900/10 dark:bg-slate-950/20 bg-slate-100/20 p-4 shadow-2xl backdrop-blur-md">
<a
href="{{ route('home.feed') }}"
href="{{ route('home.recent') }}"
wire:navigate
>
<x-primary-colorless-button class="flex items-center justify-center gap-2 dark:border-white border-slate-900">
Expand Down
8 changes: 4 additions & 4 deletions resources/views/components/home-menu.blade.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div class="mb-8 flex justify-between space-x-2">
<a
href="{{ route('home.feed') }}"
class="{{ request()->routeIs('home.feed') ? 'bg-pink-600 text-slate-100' : 'dark:text-slate-500 text-slate-400 dark:hover:text-slate-100 hover:text-slate-800 dark:bg-slate-900 bg-slate-50 ' }} inline-flex flex-1 items-center justify-center whitespace-nowrap rounded-md border dark:border-transparent border-slate-200 px-3 py-2 text-sm font-medium leading-4 transition duration-150 ease-in-out focus:outline-none"
title="{{ __('Feed') }}"
href="{{ route('home.recent') }}"
class="{{ request()->routeIs('home.recent') ? 'bg-pink-600 text-slate-100' : 'dark:text-slate-500 text-slate-400 dark:hover:text-slate-100 hover:text-slate-800 dark:bg-slate-900 bg-slate-50 ' }} inline-flex flex-1 items-center justify-center whitespace-nowrap rounded-md border dark:border-transparent border-slate-200 px-3 py-2 text-sm font-medium leading-4 transition duration-150 ease-in-out focus:outline-none"
title="{{ __('Recent') }}"
wire:navigate
wire:transition
>
<x-heroicon-o-home
class="h-6 w-6 xsm:mr-2" />
<span class="hidden xsm:inline">{{ __('Feed') }}</span>
<span class="hidden xsm:inline">{{ __('Recent') }}</span>
</a>

<a
Expand Down
2 changes: 1 addition & 1 deletion resources/views/hashtag/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="w-full max-w-md overflow-hidden rounded-lg px-2 dark:shadow-md sm:px-0">
<x-home-menu></x-home-menu>

<livewire:home.feed :hashtag="$hashtag" />
<livewire:home.recent :hashtag="$hashtag" />
</div>
</div>
</x-app-layout>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<x-home-menu></x-home-menu>

@auth
<livewire:questions.create :toId="auth()->id()" />
<livewire:questions.create :toId="auth()->id()"/>
@endauth

<livewire:home.feed />
<livewire:home.recent/>
</div>
</div>
</x-app-layout>
2 changes: 1 addition & 1 deletion resources/views/layouts/guest.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class="dark:bg-slate-950 bg-slate-100 bg-center bg-repeat font-sans dark:text-sl

<div>
<a
href="{{ route('home.feed') }}"
href="{{ route('home.recent') }}"
wire:navigate
class="mt-20 flex justify-center"
>
Expand Down
8 changes: 4 additions & 4 deletions resources/views/layouts/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class="flex items-center space-x-2.5"
@auth
<a
title="Home"
href="{{ route('home.feed') }}"
href="{{ route('home.recent') }}"
class=""
wire:navigate
>
Expand Down Expand Up @@ -133,10 +133,10 @@ class="inline-flex items-center rounded-md border dark:border-transparent border
</form>
@else
<x-dropdown-link
:href="route('home.feed')"
:class="request()->routeIs('home.feed') ? 'dark:bg-slate-800 bg-slate-200' : ''"
:href="route('home.recent')"
:class="request()->routeIs('home.recent') ? 'dark:bg-slate-800 bg-slate-200' : ''"
>
{{ __('Feed') }}
{{ __('Recent') }}
</x-dropdown-link>

<x-dropdown-link
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@php
use App\Enums\Feeds;
use App\Enums\UserMailPreference;
use Illuminate\Contracts\Auth\MustVerifyEmail;
@endphp
Expand Down Expand Up @@ -164,6 +165,25 @@ class="mt-2"
/>
</div>

<div>
<x-input-label
for="default_tab"
:value="__('What tab would you like to see by default?')"
/>
<x-select-input
id="default_tab"
name="default_tab"
class="mt-1 block w-full"
:options="Feeds::toArray()"
:value="old('default_tab', $user->default_tab)"
required
/>
<x-input-error
class="mt-2"
:messages="$errors->get('default_tab')"
/>
</div>

<div class="flex items-center gap-4">
<x-primary-button>{{ __('Save') }}</x-primary-button>
</div>
Expand Down
11 changes: 10 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@

Route::view('/about', 'about')->name('about');

Route::view('/', 'home/feed')->name('home.feed');
Route::get('/', function () {
$tab = 'recent';
if (auth()->check()) {
$tab = type(auth()->user())->as(App\Models\User::class)->default_tab;
}

return to_route('home.'.$tab);
})->name('home');

Route::view('/recent', 'home/recent')->name('home.recent');
Route::redirect('/for-you', '/following')->name('home.for_you');
Route::view('/following', 'home/following')->name('home.following');
Route::view('/trending', 'home/trending-questions')->name('home.trending');
Expand Down
1 change: 1 addition & 0 deletions tests/Http/Citadel/Questions/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$this->actingAs(User::factory()->create([
'email' => '[email protected]',
]));

$this->get(QuestionResource::getUrl('index'))->assertSuccessful();
});

Expand Down
42 changes: 42 additions & 0 deletions tests/Http/Home/DefaultTabTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

use App\Enums\Feeds;
use App\Models\User;

it('have a default tab', function () {
$newUser = User::factory()->create();
expect($newUser->default_tab)->toBeString();
});

it('unauthorized user redirects to feed', function () {
$response = $this->get(route('home'));
$response->assertRedirect(route('home.recent'));
});

it('default tab is following for new user', function () {
$newUser = User::factory()->create();
$response = $this->actingAs($newUser)->get(route('home'));
$response->assertRedirect(route('home.following'));
});

it('/ redirects to the selected default feed.', function () {
$newUser = User::factory()->create();
$response = $this->actingAs($newUser)->get(route('home'));

$defaultTab = $newUser->default_tab;

$response->assertRedirect(route('home.'.$defaultTab));
});

it('can update the default tab to following', function () {
$newUser = User::factory()->create();

$newUser->default_tab = Feeds::Following->value;
$newUser->save();

$response = $this->actingAs($newUser)->get(route('home'));

$response->assertRedirect(route('home.following'));
});
12 changes: 6 additions & 6 deletions tests/Http/Home/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

declare(strict_types=1);

use App\Livewire\Home\Feed;
use App\Livewire\Home\Recent;
use App\Livewire\Questions\Create;
use App\Models\Question;
use App\Models\User;
use Livewire\Livewire;

it('can see the "feed" view', function () {
$response = $this->get(route('home.feed'));
$response = $this->get(route('home.recent'));

$response->assertOk()
->assertSee('Feed')
->assertSeeLivewire(Feed::class);
->assertSee('Recent')
->assertSeeLivewire(Recent::class);
});

it('can see the question create component when logged in', function () {
$response = $this->actingAs(User::factory()->create())
->get(route('home.feed'));
->get(route('home.recent'));

$response->assertOk()
->assertSeeLivewire(Create::class);
Expand All @@ -29,7 +29,7 @@

Question::factory()->create(['answer' => 'question 2 without hashtags']);

$component = Livewire::test(Feed::class, ['hashtag' => 'hashtag']);
$component = Livewire::test(Recent::class, ['hashtag' => 'hashtag']);

$component
->assertViewHas('questions', fn (Illuminate\Pagination\Paginator $paginator): bool => $paginator
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

$this->assertAuthenticated();

$response->assertRedirect(route('home.feed', absolute: false));
$response->assertRedirect(route('home', absolute: false));
});

test('users are rate limited', function () {
Expand Down
3 changes: 3 additions & 0 deletions tests/Http/Profile/EditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use App\Enums\Feeds;
use App\Jobs\UpdateUserAvatar;
use App\Models\User;
use Illuminate\Auth\Notifications\VerifyEmail;
Expand Down Expand Up @@ -40,6 +41,7 @@
'email' => '[email protected]',
'mail_preference_time' => 'daily',
'prefers_anonymous_questions' => false,
'default_tab' => Feeds::Following->value,
]);

$response
Expand All @@ -53,6 +55,7 @@
$this->assertSame('testuser', $user->username);
$this->assertNull($user->email_verified_at);
$this->assertFalse($user->prefers_anonymous_questions);
$this->assertSame(Feeds::Following->value, $user->default_tab);
});

test('email provider must be authorized', function () {
Expand Down
Loading