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 3 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/HomePageTabs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum HomePageTabs: string
msamgan marked this conversation as resolved.
Show resolved Hide resolved
{
case Feed = 'feed';
msamgan marked this conversation as resolved.
Show resolved Hide resolved
case Following = 'following';

/**
* Get the values of the enum.
*
* @return array<string, string>
*/
public static function toArray(): array
{
return [
self::Feed->value => 'Feed',
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\HomePageTabs;
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(HomePageTabs::class)],
];
}
}
30 changes: 30 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,30 @@
<?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('feed')->after('mail_preference_time');
msamgan marked this conversation as resolved.
Show resolved Hide resolved
});
}

/**
* Reverse the migrations.
*/
public function down(): void
msamgan marked this conversation as resolved.
Show resolved Hide resolved
{
Schema::table('users', function (Blueprint $table): void {
$table->dropColumn('default_tab');
});
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@php
use App\Enums\HomePageTabs;
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="HomePageTabs::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
8 changes: 7 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
MrPunyapal marked this conversation as resolved.
Show resolved Hide resolved
: redirect(route('home.feed'));
})->name('home');
msamgan marked this conversation as resolved.
Show resolved Hide resolved

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');
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\HomePageTabs;
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.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'));
});
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
25 changes: 25 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\HomePageTabs;
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' => HomePageTabs::Following->value,
]);

$response
Expand Down Expand Up @@ -346,6 +348,29 @@
expect($user->refresh()->prefers_anonymous_questions)->toBeFalse();
});

test('default_tab can be updated', function () {
msamgan marked this conversation as resolved.
Show resolved Hide resolved
$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');

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Models/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'two_factor_secret',
'two_factor_recovery_codes',
'two_factor_confirmed_at',
'default_tab',
]);
});

Expand Down