Skip to content

Commit

Permalink
Pass dark theme to neon from coyote
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Apr 30, 2024
1 parent 88b06bd commit b0826b5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Providers/Neon/ServiceProvider.php
Expand Up @@ -25,7 +25,7 @@ public function register(): void
new JobOffers(),
new StaticEvents(),
new LaravelVisitor($this->app),
true,
new Laravel\CoyoteSystem($this->app),
));
}

Expand Down
4 changes: 2 additions & 2 deletions neon/src/Application.php
Expand Up @@ -12,7 +12,7 @@ public function __construct(
private Persistence\JobOffers $jobOffers,
private Persistence\Events $events,
private Domain\Visitor $visitor,
private bool $darkTheme,
private Persistence\System $system,
)
{
}
Expand All @@ -27,7 +27,7 @@ public function html(string $csrf): string
$this->jobOffers->fetchJobOffers(), // todo this is untested
$this->visitor,
$csrf,
$this->darkTheme);
$this->system->darkTheme());
return $view->html();
}
}
32 changes: 32 additions & 0 deletions neon/src/Laravel/CoyoteSystem.php
@@ -0,0 +1,32 @@
<?php
namespace Neon\Laravel;

use Coyote\Services\Guest;
use Illuminate\Foundation\Application;
use Neon\Persistence\System;

readonly class CoyoteSystem implements System
{
public function __construct(private Application $application)
{
}

// This logic is copied-and-pasted from ViewServiceProvider,
// please, in the future extract common pieces between them.
// we don't mind coupling with coyote here.

public function darkTheme(): bool
{
/** @var Guest $guest */
$guest = $this->application[Guest::class];
return $guest->getSetting('lastColorScheme',
$this->legacyLastColorScheme()) === 'dark';
}

private function legacyLastColorScheme(): ?string
{
/** @var Guest $guest */
$guest = $this->application[Guest::class];
return $guest->getSetting('dark.theme', true) ? 'dark' : 'light';
}
}
7 changes: 7 additions & 0 deletions neon/src/Persistence/System.php
@@ -0,0 +1,7 @@
<?php
namespace Neon\Persistence;

interface System
{
public function darkTheme(): bool;
}

0 comments on commit b0826b5

Please sign in to comment.