From ba72e03740a63924f3bca4265b12d87462133a59 Mon Sep 17 00:00:00 2001 From: msamgan Date: Thu, 19 Sep 2024 10:52:31 -0400 Subject: [PATCH 01/21] added default tab in settings and web. --- app/Enums/HomePageTabs.php | 26 ++++++++++++++++ app/Http/Requests/UserUpdateRequest.php | 2 ++ ..._09_19_125543_add_default_tab_to_users.php | 30 +++++++++++++++++++ .../update-profile-information-form.blade.php | 21 ++++++++++++- routes/web.php | 8 ++++- tests/Http/LoginTest.php | 2 +- tests/Unit/Models/UserTest.php | 1 + 7 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 app/Enums/HomePageTabs.php create mode 100644 database/migrations/2024_09_19_125543_add_default_tab_to_users.php diff --git a/app/Enums/HomePageTabs.php b/app/Enums/HomePageTabs.php new file mode 100644 index 000000000..f471102ce --- /dev/null +++ b/app/Enums/HomePageTabs.php @@ -0,0 +1,26 @@ + + */ + public static function toArray(): array + { + return [ + self::Feed->value => 'Feed', + self::Following->value => 'Following', + self::Trending->value => 'Trending', + ]; + } +} diff --git a/app/Http/Requests/UserUpdateRequest.php b/app/Http/Requests/UserUpdateRequest.php index efb795f96..d59c06a7b 100644 --- a/app/Http/Requests/UserUpdateRequest.php +++ b/app/Http/Requests/UserUpdateRequest.php @@ -4,6 +4,7 @@ namespace App\Http\Requests; +use App\Enums\HomePageTabs; use App\Enums\UserMailPreference; use App\Models\User; use App\Rules\NoBlankCharacters; @@ -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(HomePageTabs::class)], ]; } } diff --git a/database/migrations/2024_09_19_125543_add_default_tab_to_users.php b/database/migrations/2024_09_19_125543_add_default_tab_to_users.php new file mode 100644 index 000000000..9e94eb987 --- /dev/null +++ b/database/migrations/2024_09_19_125543_add_default_tab_to_users.php @@ -0,0 +1,30 @@ +string('default_tab')->default('feed')->after('mail_preference_time'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table): void { + $table->dropColumn('default_tab'); + }); + } +}; diff --git a/resources/views/profile/partials/update-profile-information-form.blade.php b/resources/views/profile/partials/update-profile-information-form.blade.php index 0b3ad1cc1..85cd4abba 100644 --- a/resources/views/profile/partials/update-profile-information-form.blade.php +++ b/resources/views/profile/partials/update-profile-information-form.blade.php @@ -1,5 +1,5 @@ @php - use App\Enums\UserMailPreference; + use App\Enums\HomePageTabs;use App\Enums\UserMailPreference; use Illuminate\Contracts\Auth\MustVerifyEmail; @endphp @@ -164,6 +164,25 @@ class="mt-2" /> +
+ + + +
+
{{ __('Save') }}
diff --git a/routes/web.php b/routes/web.php index 8c040f4d9..f24517e99 100644 --- a/routes/web.php +++ b/routes/web.php @@ -18,7 +18,13 @@ Route::view('/about', 'about')->name('about'); -Route::view('/', 'home/feed')->name('home.feed'); +Route::get('/', function () { + return auth()->check() + ? redirect(route('home.'.auth()->user()->default_tab)) // @phpstan-ignore-line + : redirect(route('home.feed')); +})->name('home'); + +Route::view('/feed', 'home/feed')->name('home.feed'); 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'); diff --git a/tests/Http/LoginTest.php b/tests/Http/LoginTest.php index 984ae2f3c..313849437 100644 --- a/tests/Http/LoginTest.php +++ b/tests/Http/LoginTest.php @@ -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 () { diff --git a/tests/Unit/Models/UserTest.php b/tests/Unit/Models/UserTest.php index d78363916..ae5b5a480 100644 --- a/tests/Unit/Models/UserTest.php +++ b/tests/Unit/Models/UserTest.php @@ -30,6 +30,7 @@ 'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at', + 'default_tab', ]); }); From b3558391dec7607c5963aa23674048e102f0eda8 Mon Sep 17 00:00:00 2001 From: msamgan Date: Thu, 19 Sep 2024 11:28:11 -0400 Subject: [PATCH 02/21] added test. --- tests/Http/Home/DefaultTabTest.php | 53 ++++++++++++++++++++++++++++++ tests/Http/Profile/EditTest.php | 25 ++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/Http/Home/DefaultTabTest.php diff --git a/tests/Http/Home/DefaultTabTest.php b/tests/Http/Home/DefaultTabTest.php new file mode 100644 index 000000000..1cf2e346c --- /dev/null +++ b/tests/Http/Home/DefaultTabTest.php @@ -0,0 +1,53 @@ +create(); + expect($newUser->default_tab)->toBeString(); +}); + +it('unauthorized user redirects to feed', function () { + $response = $this->get(route('home')); + $response->assertRedirect(route('home.feed')); +}); + +it('default tab is feed for new user', function () { + $newUser = User::factory()->create(); + $response = $this->actingAs($newUser)->get(route('home')); + $response->assertRedirect(route('home.feed')); +}); + +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 = HomePageTabs::Following->value; + $newUser->save(); + + $response = $this->actingAs($newUser)->get(route('home')); + + $response->assertRedirect(route('home.following')); +}); + +it('can update the default tab to trending', function () { + $newUser = User::factory()->create(); + + $newUser->default_tab = HomePageTabs::Trending->value; + $newUser->save(); + + $response = $this->actingAs($newUser)->get(route('home')); + + $response->assertRedirect(route('home.trending')); +}); diff --git a/tests/Http/Profile/EditTest.php b/tests/Http/Profile/EditTest.php index 605777452..cfe3be8d8 100644 --- a/tests/Http/Profile/EditTest.php +++ b/tests/Http/Profile/EditTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use App\Enums\HomePageTabs; use App\Jobs\UpdateUserAvatar; use App\Models\User; use Illuminate\Auth\Notifications\VerifyEmail; @@ -40,6 +41,7 @@ 'email' => 'test@example.com', 'mail_preference_time' => 'daily', 'prefers_anonymous_questions' => false, + 'default_tab' => HomePageTabs::Following->value, ]); $response @@ -346,6 +348,29 @@ expect($user->refresh()->prefers_anonymous_questions)->toBeFalse(); }); +test('default_tab can be updated', function () { + $user = User::factory()->create([ + 'default_tab' => HomePageTabs::Feed->value, + ]); + + $response = $this + ->actingAs($user) + ->patch('/profile', [ + 'name' => 'Test User', + 'username' => 'testuser', + 'email' => $user->email, + 'mail_preference_time' => 'daily', + 'prefers_anonymous_questions' => false, + 'default_tab' => HomePageTabs::Following->value, + ]); + + $response + ->assertSessionHasNoErrors() + ->assertRedirect('/profile'); + + expect($user->refresh()->default_tab)->toBe(HomePageTabs::Following->value); +}); + test('user can upload an avatar', function () { Storage::fake('public'); From 8a674b45b0276fb8fd9716e31286f338d3e79c8c Mon Sep 17 00:00:00 2001 From: msamgan Date: Thu, 19 Sep 2024 11:55:30 -0400 Subject: [PATCH 03/21] removed trending from the default tab options. --- app/Enums/HomePageTabs.php | 2 -- .../update-profile-information-form.blade.php | 3 ++- tests/Http/Home/DefaultTabTest.php | 11 ----------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/app/Enums/HomePageTabs.php b/app/Enums/HomePageTabs.php index f471102ce..77e79b345 100644 --- a/app/Enums/HomePageTabs.php +++ b/app/Enums/HomePageTabs.php @@ -8,7 +8,6 @@ enum HomePageTabs: string { case Feed = 'feed'; case Following = 'following'; - case Trending = 'trending'; /** * Get the values of the enum. @@ -20,7 +19,6 @@ public static function toArray(): array return [ self::Feed->value => 'Feed', self::Following->value => 'Following', - self::Trending->value => 'Trending', ]; } } diff --git a/resources/views/profile/partials/update-profile-information-form.blade.php b/resources/views/profile/partials/update-profile-information-form.blade.php index 85cd4abba..b9c542112 100644 --- a/resources/views/profile/partials/update-profile-information-form.blade.php +++ b/resources/views/profile/partials/update-profile-information-form.blade.php @@ -1,5 +1,6 @@ @php - use App\Enums\HomePageTabs;use App\Enums\UserMailPreference; + use App\Enums\HomePageTabs; + use App\Enums\UserMailPreference; use Illuminate\Contracts\Auth\MustVerifyEmail; @endphp diff --git a/tests/Http/Home/DefaultTabTest.php b/tests/Http/Home/DefaultTabTest.php index 1cf2e346c..6ed1f92b4 100644 --- a/tests/Http/Home/DefaultTabTest.php +++ b/tests/Http/Home/DefaultTabTest.php @@ -40,14 +40,3 @@ $response->assertRedirect(route('home.following')); }); - -it('can update the default tab to trending', function () { - $newUser = User::factory()->create(); - - $newUser->default_tab = HomePageTabs::Trending->value; - $newUser->save(); - - $response = $this->actingAs($newUser)->get(route('home')); - - $response->assertRedirect(route('home.trending')); -}); From c04aca9241d99cca589602e1af45e1120831020a Mon Sep 17 00:00:00 2001 From: Mohammed Samgan Khan Date: Fri, 20 Sep 2024 12:04:29 -0400 Subject: [PATCH 04/21] updated the / route Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> --- routes/web.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/routes/web.php b/routes/web.php index f24517e99..01bed5934 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,9 +19,12 @@ Route::view('/about', 'about')->name('about'); Route::get('/', function () { - return auth()->check() - ? redirect(route('home.'.auth()->user()->default_tab)) // @phpstan-ignore-line - : redirect(route('home.feed')); + $tab = 'feed'; + if (auth()->check()) { + $tab = type(auth()->user())->as(User::class)->default_tab; + } + + return to_route('home.'.$tab); })->name('home'); Route::view('/feed', 'home/feed')->name('home.feed'); From 73d33300a394eaf55a0558eeea6bc764a8dbf593 Mon Sep 17 00:00:00 2001 From: msamgan Date: Fri, 20 Sep 2024 12:14:03 -0400 Subject: [PATCH 05/21] Resoled requested changes. --- routes/web.php | 2 +- tests/Http/Profile/EditTest.php | 24 +----------------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/routes/web.php b/routes/web.php index 01bed5934..93037efe0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -21,7 +21,7 @@ Route::get('/', function () { $tab = 'feed'; if (auth()->check()) { - $tab = type(auth()->user())->as(User::class)->default_tab; + $tab = type(auth()->user())->as(App\Models\User::class)->default_tab; } return to_route('home.'.$tab); diff --git a/tests/Http/Profile/EditTest.php b/tests/Http/Profile/EditTest.php index cfe3be8d8..a8104f664 100644 --- a/tests/Http/Profile/EditTest.php +++ b/tests/Http/Profile/EditTest.php @@ -55,6 +55,7 @@ $this->assertSame('testuser', $user->username); $this->assertNull($user->email_verified_at); $this->assertFalse($user->prefers_anonymous_questions); + $this->assertSame(HomePageTabs::Following->value, $user->default_tab); }); test('email provider must be authorized', function () { @@ -348,29 +349,6 @@ expect($user->refresh()->prefers_anonymous_questions)->toBeFalse(); }); -test('default_tab can be updated', function () { - $user = User::factory()->create([ - 'default_tab' => HomePageTabs::Feed->value, - ]); - - $response = $this - ->actingAs($user) - ->patch('/profile', [ - 'name' => 'Test User', - 'username' => 'testuser', - 'email' => $user->email, - 'mail_preference_time' => 'daily', - 'prefers_anonymous_questions' => false, - 'default_tab' => HomePageTabs::Following->value, - ]); - - $response - ->assertSessionHasNoErrors() - ->assertRedirect('/profile'); - - expect($user->refresh()->default_tab)->toBe(HomePageTabs::Following->value); -}); - test('user can upload an avatar', function () { Storage::fake('public'); From 9c2e5f7237ea5f51f0021529b93b60fff7e6a79e Mon Sep 17 00:00:00 2001 From: msamgan Date: Fri, 20 Sep 2024 12:57:02 -0400 Subject: [PATCH 06/21] made following tab as default. --- .../migrations/2024_09_19_125543_add_default_tab_to_users.php | 2 +- tests/Http/Home/DefaultTabTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/database/migrations/2024_09_19_125543_add_default_tab_to_users.php b/database/migrations/2024_09_19_125543_add_default_tab_to_users.php index 9e94eb987..e08f03703 100644 --- a/database/migrations/2024_09_19_125543_add_default_tab_to_users.php +++ b/database/migrations/2024_09_19_125543_add_default_tab_to_users.php @@ -14,7 +14,7 @@ public function up(): void { Schema::table('users', function (Blueprint $table): void { - $table->string('default_tab')->default('feed')->after('mail_preference_time'); + $table->string('default_tab')->default('following')->after('mail_preference_time'); }); } diff --git a/tests/Http/Home/DefaultTabTest.php b/tests/Http/Home/DefaultTabTest.php index 6ed1f92b4..7167da4b2 100644 --- a/tests/Http/Home/DefaultTabTest.php +++ b/tests/Http/Home/DefaultTabTest.php @@ -15,10 +15,10 @@ $response->assertRedirect(route('home.feed')); }); -it('default tab is feed for new user', function () { +it('default tab is following for new user', function () { $newUser = User::factory()->create(); $response = $this->actingAs($newUser)->get(route('home')); - $response->assertRedirect(route('home.feed')); + $response->assertRedirect(route('home.following')); }); it('/ redirects to the selected default feed.', function () { From 0526fa1de376cf3750abe55e5418f79249046c98 Mon Sep 17 00:00:00 2001 From: msamgan Date: Sat, 21 Sep 2024 15:27:36 -0400 Subject: [PATCH 07/21] updated requested changes. --- app/Enums/{HomePageTabs.php => Feeds.php} | 2 +- app/Http/Requests/UserUpdateRequest.php | 4 ++-- .../2024_09_19_125543_add_default_tab_to_users.php | 10 ---------- .../partials/update-profile-information-form.blade.php | 4 ++-- tests/Http/Home/DefaultTabTest.php | 4 ++-- tests/Http/Profile/EditTest.php | 6 +++--- 6 files changed, 10 insertions(+), 20 deletions(-) rename app/Enums/{HomePageTabs.php => Feeds.php} (93%) diff --git a/app/Enums/HomePageTabs.php b/app/Enums/Feeds.php similarity index 93% rename from app/Enums/HomePageTabs.php rename to app/Enums/Feeds.php index 77e79b345..5b34cc1fe 100644 --- a/app/Enums/HomePageTabs.php +++ b/app/Enums/Feeds.php @@ -4,7 +4,7 @@ namespace App\Enums; -enum HomePageTabs: string +enum Feeds: string { case Feed = 'feed'; case Following = 'following'; diff --git a/app/Http/Requests/UserUpdateRequest.php b/app/Http/Requests/UserUpdateRequest.php index d59c06a7b..771023974 100644 --- a/app/Http/Requests/UserUpdateRequest.php +++ b/app/Http/Requests/UserUpdateRequest.php @@ -4,7 +4,7 @@ namespace App\Http\Requests; -use App\Enums\HomePageTabs; +use App\Enums\Feeds; use App\Enums\UserMailPreference; use App\Models\User; use App\Rules\NoBlankCharacters; @@ -40,7 +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(HomePageTabs::class)], + 'default_tab' => [Rule::enum(Feeds::class)], ]; } } diff --git a/database/migrations/2024_09_19_125543_add_default_tab_to_users.php b/database/migrations/2024_09_19_125543_add_default_tab_to_users.php index e08f03703..b3738b768 100644 --- a/database/migrations/2024_09_19_125543_add_default_tab_to_users.php +++ b/database/migrations/2024_09_19_125543_add_default_tab_to_users.php @@ -17,14 +17,4 @@ public function up(): void $table->string('default_tab')->default('following')->after('mail_preference_time'); }); } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table): void { - $table->dropColumn('default_tab'); - }); - } }; diff --git a/resources/views/profile/partials/update-profile-information-form.blade.php b/resources/views/profile/partials/update-profile-information-form.blade.php index b9c542112..8c9c2553a 100644 --- a/resources/views/profile/partials/update-profile-information-form.blade.php +++ b/resources/views/profile/partials/update-profile-information-form.blade.php @@ -1,5 +1,5 @@ @php - use App\Enums\HomePageTabs; + use App\Enums\Feeds; use App\Enums\UserMailPreference; use Illuminate\Contracts\Auth\MustVerifyEmail; @endphp @@ -174,7 +174,7 @@ class="mt-2" id="default_tab" name="default_tab" class="mt-1 block w-full" - :options="HomePageTabs::toArray()" + :options="Feeds::toArray()" :value="old('default_tab', $user->default_tab)" required /> diff --git a/tests/Http/Home/DefaultTabTest.php b/tests/Http/Home/DefaultTabTest.php index 7167da4b2..e0229aa61 100644 --- a/tests/Http/Home/DefaultTabTest.php +++ b/tests/Http/Home/DefaultTabTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use App\Enums\HomePageTabs; +use App\Enums\Feeds; use App\Models\User; it('have a default tab', function () { @@ -33,7 +33,7 @@ it('can update the default tab to following', function () { $newUser = User::factory()->create(); - $newUser->default_tab = HomePageTabs::Following->value; + $newUser->default_tab = Feeds::Following->value; $newUser->save(); $response = $this->actingAs($newUser)->get(route('home')); diff --git a/tests/Http/Profile/EditTest.php b/tests/Http/Profile/EditTest.php index a8104f664..412a18622 100644 --- a/tests/Http/Profile/EditTest.php +++ b/tests/Http/Profile/EditTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use App\Enums\HomePageTabs; +use App\Enums\Feeds; use App\Jobs\UpdateUserAvatar; use App\Models\User; use Illuminate\Auth\Notifications\VerifyEmail; @@ -41,7 +41,7 @@ 'email' => 'test@example.com', 'mail_preference_time' => 'daily', 'prefers_anonymous_questions' => false, - 'default_tab' => HomePageTabs::Following->value, + 'default_tab' => Feeds::Following->value, ]); $response @@ -55,7 +55,7 @@ $this->assertSame('testuser', $user->username); $this->assertNull($user->email_verified_at); $this->assertFalse($user->prefers_anonymous_questions); - $this->assertSame(HomePageTabs::Following->value, $user->default_tab); + $this->assertSame(Feeds::Following->value, $user->default_tab); }); test('email provider must be authorized', function () { From 0c21679cf0cab45f7e2a42f78781ca5c54bcfa6a Mon Sep 17 00:00:00 2001 From: msamgan Date: Sat, 21 Sep 2024 16:38:44 -0400 Subject: [PATCH 08/21] Renamed 'feed' to 'Recent.' --- app/Enums/Feeds.php | 4 ++-- app/Livewire/Home/{Feed.php => Recent.php} | 4 ++-- .../Filament/CitadelPanelProvider.php | 2 +- resources/views/about.blade.php | 2 +- .../views/components/home-menu.blade.php | 8 ++++---- resources/views/hashtag/show.blade.php | 2 +- .../home/{feed.blade.php => recent.blade.php} | 4 ++-- resources/views/layouts/guest.blade.php | 2 +- resources/views/layouts/navigation.blade.php | 8 ++++---- .../{feed.blade.php => recent.blade.php} | 0 routes/web.php | 4 ++-- tests/Http/Citadel/Questions/IndexTest.php | 1 + tests/Http/Home/DefaultTabTest.php | 2 +- tests/Http/Home/FeedTest.php | 12 +++++------ tests/Unit/Livewire/Home/FeedTest.php | 20 +++++++++---------- tests/Unit/Livewire/Questions/ShowTest.php | 2 +- 16 files changed, 39 insertions(+), 38 deletions(-) rename app/Livewire/Home/{Feed.php => Recent.php} (93%) rename resources/views/home/{feed.blade.php => recent.blade.php} (74%) rename resources/views/livewire/{feed.blade.php => recent.blade.php} (100%) diff --git a/app/Enums/Feeds.php b/app/Enums/Feeds.php index 5b34cc1fe..2cc4e0cf3 100644 --- a/app/Enums/Feeds.php +++ b/app/Enums/Feeds.php @@ -6,7 +6,7 @@ enum Feeds: string { - case Feed = 'feed'; + case Recent = 'recent'; case Following = 'following'; /** @@ -17,7 +17,7 @@ enum Feeds: string public static function toArray(): array { return [ - self::Feed->value => 'Feed', + self::Recent->value => 'Recent', self::Following->value => 'Following', ]; } diff --git a/app/Livewire/Home/Feed.php b/app/Livewire/Home/Recent.php similarity index 93% rename from app/Livewire/Home/Feed.php rename to app/Livewire/Home/Recent.php index 0fc81c04b..a053a6bc2 100644 --- a/app/Livewire/Home/Feed.php +++ b/app/Livewire/Home/Recent.php @@ -11,7 +11,7 @@ use Livewire\Attributes\On; use Livewire\Component; -final class Feed extends Component +final class Recent extends Component { use HasLoadMore; @@ -50,7 +50,7 @@ public function render(): View ->builder() ->simplePaginate($this->perPage); - return view('livewire.feed', [ + return view('livewire.recent', [ 'questions' => $questions, ]); } diff --git a/app/Providers/Filament/CitadelPanelProvider.php b/app/Providers/Filament/CitadelPanelProvider.php index 41a15929f..5bb97abb4 100644 --- a/app/Providers/Filament/CitadelPanelProvider.php +++ b/app/Providers/Filament/CitadelPanelProvider.php @@ -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')) diff --git a/resources/views/about.blade.php b/resources/views/about.blade.php index 5e5dff700..c639fdd39 100644 --- a/resources/views/about.blade.php +++ b/resources/views/about.blade.php @@ -4,7 +4,7 @@