Skip to content

Commit

Permalink
Enable modern look&feel for users with "beta-access"
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Dec 16, 2024
1 parent 478b615 commit 0f176dd
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/Domain/Icon/FontAwesomePro.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ public function icons(): array

// post review
'postReviewClose' => $genericClose,

// look&feel
'lookAndFeel' => 'fa-light fa-palette',
];
}
}
24 changes: 23 additions & 1 deletion app/Feature/LookAndFeel/LookAndFeelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Coyote\Feature\LookAndFeel;

use Coyote\Services\Guest;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Expand All @@ -16,7 +17,10 @@ public function boot(): void
$view = $this->app['view'];

$view->composer('layout', function (View $view) {
$view->with(['lookAndFeelModern' => $this->lookAndFeel() === 'modern']);
$view->with([
'accessToLookAndFeel' => $this->accessToLookAndFeel(),
'lookAndFeelModern' => $this->lookAndFeel() === 'modern',
]);
});

Route::middleware(['web', 'auth'])->group(function () {
Expand All @@ -26,6 +30,9 @@ public function boot(): void
}
return response(status:404);
});
Route::post('/LookAndFeel', function (Request $request) {
$this->setLookAndFeel($request->get('lookAndFeel') === 'modern');
});
});
}

Expand Down Expand Up @@ -61,4 +68,19 @@ private function requestOverride(): ?string
}
return null;
}

private function setLookAndFeel(bool $isModern): void
{
if (!auth()->check()) {
return;
}
$guest = new Guest(auth()->user()->guest_id);
$guest->setSetting('lookAndFeel', $isModern ? 'modern' : 'legacy');
}

private function accessToLookAndFeel(): bool
{
$gate = $this->app->get(Gate::class);
return $gate->allows('beta-access');
}
}
21 changes: 21 additions & 0 deletions resources/feature/lookAndFeel/lookAndFeel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import axios from "axios";
import {createVueApp} from "../../js/vue";

const lookAndFeelSwitcher = {
methods: {
lookAndFeelSwitchModern(): void {
this.changeLookAndFeel('modern');
},
lookAndFeelSwitchLegacy(): void {
this.changeLookAndFeel('legacy');
},
changeLookAndFeel(lookAndFeel: 'modern' | 'legacy'): void {
axios.post('/LookAndFeel', {lookAndFeel})
.then(() => window.location.reload());
},
},
};

window.addEventListener('load', () => {
createVueApp('LookAndFeelSwitcher', '#lookAndFeelSwitcher', lookAndFeelSwitcher);
});
1 change: 1 addition & 0 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import './sentry.ts';
import './store/index.ts';
import './gdpr.ts';
import '../feature/stickyAside/sticky-aside.js';
import '../feature/lookAndFeel/lookAndFeel';

import '../../survey/src/survey';

Expand Down
3 changes: 2 additions & 1 deletion resources/sass/layout/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ body.padding-top {
display: flex;
align-items: center; // center image vertically

a {
a,
.dropdown-item {
color: $gray;

&:hover {
Expand Down
34 changes: 29 additions & 5 deletions resources/views/layout.twig
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@
alt="4programmers.net"
data-src-light="{{ cdn(lookAndFeelModern ? 'img/logo-modern.svg' : 'img/logo-light.svg') }}"
data-src-dark="{{ cdn(lookAndFeelModern ? 'img/logo-modern.svg' : 'img/logo-dark.svg') }}"
src="{{ __dark_theme
? cdn(lookAndFeelModern ? 'img/logo-modern.svg' : 'img/logo-dark.svg')
: cdn(lookAndFeelModern ? 'img/logo-modern.svg' : 'img/logo-light.svg')
}}"
src="{{ __dark_theme
? cdn(lookAndFeelModern ? 'img/logo-modern.svg' : 'img/logo-dark.svg')
: cdn(lookAndFeelModern ? 'img/logo-modern.svg' : 'img/logo-light.svg') }}"
/>
</a>

Expand Down Expand Up @@ -124,7 +123,8 @@
</div>

{% if auth_check() %}
<ul id="nav-auth" class="nav-auth navbar-nav order-2"></ul>
<ul id="nav-auth" class="nav-auth navbar-nav order-2">
</ul>

<div class="dropdown nav-avatar order-2">
<div class="dropdown-toggle d-block i-35 {{ not isHomepageModern ? 'img-thumbnail' }} neon-navbar-user-avatar" data-bs-toggle="dropdown" style="cursor:pointer;">
Expand All @@ -141,6 +141,30 @@
{% endif %}
</a>

{% if accessToLookAndFeel %}
<div class="dropdown-divider"></div>
<style>
.option {
opacity: 0.5;
}
.option:hover {
text-decoration: underline;
}
.option-active {
font-weight: bold;
}
</style>
<span class="dropdown-item" title="Przełącz Look&amp;Feel forum" id="lookAndFeelSwitcher">
{{ icon('lookAndFeel') }}
<span class="me-2">
Look&amp;Feel:
</span>
<span class="option {{ lookAndFeelModern ?: 'option-active' }}" @click="lookAndFeelSwitchLegacy">Początkowy</span>
/
<span class="option {{ lookAndFeelModern ?'option-active' }}" @click="lookAndFeelSwitchModern">Nowy</span>
</span>
{% endif %}

<div class="dropdown-divider"></div>

<a class="dropdown-item" href="{{ route('profile', [user('id')]) }}">
Expand Down

0 comments on commit 0f176dd

Please sign in to comment.