Skip to content

Commit

Permalink
feat: breeze livewire-functional
Browse files Browse the repository at this point in the history
  • Loading branch information
joelbutcher committed Oct 11, 2023
1 parent f3a7489 commit 51e2e5a
Show file tree
Hide file tree
Showing 28 changed files with 561 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/Actions/Auth/Breeze/Blade/AuthenticateOauthCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\MessageBag;
use JoelButcher\Socialstream\ConnectedAccount;
use JoelButcher\Socialstream\Contracts\AuthenticatesOauthCallback;
Expand Down Expand Up @@ -36,7 +35,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$account = Socialstream::findConnectedAccountForProviderAndId($provider, $providerAccount->getId());

// Authenticated...
if (! is_null($user = Auth::user())) {
if (! is_null($user = auth()->user())) {
return $this->alreadyAuthenticated($user, $account, $provider, $providerAccount);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Actions/Auth/Breeze/HandleOauthCallbackErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Providers\RouteServiceProvider;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\MessageBag;
use JoelButcher\Socialstream\Contracts\HandlesOauthCallbackErrors;

Expand All @@ -23,7 +22,7 @@ public function handle(Request $request): ?RedirectResponse
$messageBag = new MessageBag;
$messageBag->add('socialstream', $request->get('error_description'));

return Auth::check()
return auth()->check()
? redirect(RouteServiceProvider::HOME)->withErrors(['callback' => $request->get('error_description')])
: redirect()->route('login')->withErrors($messageBag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\MessageBag;
use JoelButcher\Socialstream\ConnectedAccount;
use JoelButcher\Socialstream\Contracts\AuthenticatesOauthCallback;
Expand Down Expand Up @@ -36,7 +35,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$account = Socialstream::findConnectedAccountForProviderAndId($provider, $providerAccount->getId());

// Authenticated...
if (! is_null($user = Auth::user())) {
if (! is_null($user = auth()->user())) {
return $this->alreadyAuthenticated($user, $account, $provider, $providerAccount);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Actions/Auth/Filament/AuthenticateOauthCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\MessageBag;
use JoelButcher\Socialstream\ConnectedAccount;
use JoelButcher\Socialstream\Contracts\AuthenticatesOauthCallback;
Expand Down Expand Up @@ -36,7 +35,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$account = Socialstream::findConnectedAccountForProviderAndId($provider, $providerAccount->getId());

// Authenticated...
if (! is_null($user = Auth::user())) {
if (! is_null($user = auth()->user())) {
return $this->alreadyAuthenticated($user, $account, $provider, $providerAccount);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Actions/Auth/Filament/HandleOauthCallbackErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\MessageBag;
use JoelButcher\Socialstream\Contracts\HandlesOauthCallbackErrors;

Expand All @@ -22,7 +21,7 @@ public function handle(Request $request): ?RedirectResponse
$messageBag = new MessageBag;
$messageBag->add('socialstream', $request->get('error_description'));

return Auth::check()
return auth()->check()
? redirect()->route('filament.home')->withErrors($messageBag)
: redirect()->route(
'filament.admin.auth.login'
Expand Down
3 changes: 1 addition & 2 deletions src/Actions/Auth/Jetstream/AuthenticateOauthCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\MessageBag;
use JoelButcher\Socialstream\ConnectedAccount;
use JoelButcher\Socialstream\Contracts\AuthenticatesOauthCallback;
Expand Down Expand Up @@ -38,7 +37,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$account = Socialstream::findConnectedAccountForProviderAndId($provider, $providerAccount->getId());

// Authenticated...
if (! is_null($user = Auth::user())) {
if (! is_null($user = auth()->user())) {
return $this->alreadyAuthenticated($user, $account, $provider, $providerAccount);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Actions/Auth/Jetstream/HandleOauthCallbackErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\MessageBag;
use JoelButcher\Socialstream\Contracts\HandlesOauthCallbackErrors;
use Laravel\Fortify\Features as FortifyFeatures;
Expand All @@ -23,7 +22,7 @@ public function handle(Request $request): ?RedirectResponse
$messageBag = new MessageBag;
$messageBag->add('socialstream', $request->get('error_description'));

return Auth::check()
return auth()->check()
? redirect(config('fortify.home'))->dangerBanner($request->get('error_description'))
: redirect()->route(
FortifyFeatures::enabled(FortifyFeatures::registration()) ? 'register' : 'login'
Expand Down
4 changes: 2 additions & 2 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function handle(InstallManager $installManager): ?int
{
$installManager->driver(match (true) {
$this->getStarterKit() === InstallStarterKit::Filament => 'filament',
$this->getStarterKit() === InstallStarterKit::Breeze &&
$this->getStack() === BreezeInstallStack::Livewire => 'livewire-breeze',
($this->getStarterKit() === InstallStarterKit::Breeze &&
$this->getStack() === BreezeInstallStack::Livewire) => 'livewire-breeze',
default => $this->getStarterKit()->value.'-'.$this->getStack()->value,
})->install(
$this->option('composer'),
Expand Down
5 changes: 2 additions & 3 deletions src/Http/Livewire/SetPasswordForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace JoelButcher\Socialstream\Http\Livewire;

use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use JoelButcher\Socialstream\Contracts\SetsUserPasswords;
use Livewire\Component;
Expand All @@ -26,7 +25,7 @@ public function setPassword(SetsUserPasswords $setter): void
{
$this->resetErrorBag();

$setter->set(Auth::user(), $this->state);
$setter->set(auth()->user(), $this->state);

$this->state = [
'password' => '',
Expand All @@ -43,7 +42,7 @@ public function setPassword(SetsUserPasswords $setter): void
*/
public function getUserProperty(): mixed
{
return Auth::user();
return auth()->user();
}

/**
Expand Down
72 changes: 72 additions & 0 deletions src/Installer/Drivers/Breeze/FunctionalLivewireDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace JoelButcher\Socialstream\Installer\Drivers\Breeze;

use Illuminate\Filesystem\Filesystem;
use JoelButcher\Socialstream\Installer\Enums\BreezeInstallStack;
use JoelButcher\Socialstream\Installer\Enums\InstallOptions;

class FunctionalLivewireDriver extends BreezeDriver
{
/**
* Specify the stack used by this installer.
*/
protected static function stack(): BreezeInstallStack
{
return BreezeInstallStack::FunctionalLivewire;
}

protected static function directoriesToCreateForStack(): array
{
return [
resource_path('views/livewire/pages/auth/auth'),
resource_path('views/livewire/profile'),
];
}

/**
* Copy all the app files required for the stack.
*/
protected function copyAppFiles(): static
{
return $this;
}

/**
* Copy the auth views to the app "resources" directory for the given stack.
*/
protected function copyAuthViews(InstallOptions ...$options): static
{
copy(__DIR__.'/../../../../stubs/breeze/livewire-functional/resources/views/livewire/pages/auth/login.blade.php', resource_path('views/livewire/pages/auth/login.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire-functional/resources/views/livewire/pages/auth/register.blade.php', resource_path('views/livewire/pages/auth/register.blade.php'));

return $this;
}

/**
* Copy the profile views to the app "resources" directory for the given stack.
*/
protected function copyProfileViews(InstallOptions ...$options): static
{
copy(__DIR__.'/../../../../stubs/breeze/livewire-common/resources/views/profile.blade.php', resource_path('views/profile.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire-functional/resources/views/livewire/profile/delete-user-form.blade.php', resource_path('views/livewire/profile/delete-user-form.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire-functional/resources/views/livewire/profile/set-password-form.blade.php', resource_path('views/livewire/profile/set-password-form.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire-functional/resources/views/livewire/profile/connected-accounts-form.blade.php', resource_path('views/livewire/profile/connected-accounts-form.blade.php'));

return $this;
}

/**
* Copy the Socialstream components to the app "resources" directory for the given stack.
*/
protected function copySocialstreamComponents(InstallOptions ...$options): static
{
(new Filesystem)->copyDirectory(__DIR__.'/../../../../stubs/breeze/default/resources/views/components/socialstream-icons', resource_path('views/components/socialstream-icons'));

copy(__DIR__.'/../../../../stubs/breeze/default/resources/views/components/action-link.blade.php', resource_path('views/components/action-link.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/default/resources/views/components/connected-account.blade.php', resource_path('views/components/connected-account.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire-common/resources/views/components/socialstream.blade.php', resource_path('views/components/socialstream.blade.php'));

return $this;
}
}
4 changes: 2 additions & 2 deletions src/Installer/Drivers/Breeze/LivewireDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function copyAuthViews(InstallOptions ...$options): static
*/
protected function copyProfileViews(InstallOptions ...$options): static
{
copy(__DIR__.'/../../../../stubs/breeze/livewire/resources/views/profile.blade.php', resource_path('views/profile.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire-common/resources/views/profile.blade.php', resource_path('views/profile.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire/resources/views/livewire/profile/delete-user-form.blade.php', resource_path('views/livewire/profile/delete-user-form.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire/resources/views/livewire/profile/set-password-form.blade.php', resource_path('views/livewire/profile/set-password-form.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire/resources/views/livewire/profile/connected-accounts-form.blade.php', resource_path('views/livewire/profile/connected-accounts-form.blade.php'));
Expand All @@ -65,7 +65,7 @@ protected function copySocialstreamComponents(InstallOptions ...$options): stati

copy(__DIR__.'/../../../../stubs/breeze/default/resources/views/components/action-link.blade.php', resource_path('views/components/action-link.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/default/resources/views/components/connected-account.blade.php', resource_path('views/components/connected-account.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire/resources/views/components/socialstream.blade.php', resource_path('views/components/socialstream.blade.php'));
copy(__DIR__.'/../../../../stubs/breeze/livewire-common/resources/views/components/socialstream.blade.php', resource_path('views/components/socialstream.blade.php'));

return $this;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Installer/Enums/BreezeInstallStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ enum BreezeInstallStack: string
{
case Blade = 'blade';
case Livewire = 'livewire';
case FunctionalLivewire = 'livewire-functional';
case React = 'react';
case Vue = 'vue';

public function label(): string
{
return match ($this) {
self::Blade => 'Blade with Alpine',
self::Livewire => 'Livewire with Alpine',
self::Livewire => 'Livewire (Volt Class API) with Alpine',
self::FunctionalLivewire => 'Livewire (Volt Functional API) with Alpine',
self::React => 'React with Inertia',
self::Vue => 'Vue with Inertia',
};
Expand Down
7 changes: 7 additions & 0 deletions src/Installer/InstallManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Manager;
use JoelButcher\Socialstream\Installer\Drivers\Breeze\BladeDriver;
use JoelButcher\Socialstream\Installer\Drivers\Breeze\FunctionalLivewireDriver as BreezeLivewireFunctionalDriver;
use JoelButcher\Socialstream\Installer\Drivers\Breeze\LivewireDriver as BreezeLivewireDriver;
use JoelButcher\Socialstream\Installer\Drivers\Breeze\ReactInertiaDriver;
use JoelButcher\Socialstream\Installer\Drivers\Breeze\VueInertiaDriver;
Expand Down Expand Up @@ -32,6 +33,12 @@ public function createBreezeLivewireDriver(): BreezeLivewireDriver
return $this->container->make(BreezeLivewireDriver::class);
}

public function createBreezeLivewireFunctionalDriver(): BreezeLivewireFunctionalDriver
{
return $this->container->make(BreezeLivewireFunctionalDriver::class);
}


public function createBreezeReactDriver(): ReactInertiaDriver
{
return $this->container->make(ReactInertiaDriver::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Http\Requests\ProfileUpdateRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\View\View;

Expand Down Expand Up @@ -48,7 +47,7 @@ public function destroy(Request $request): RedirectResponse

$user = $request->user();

Auth::logout();
auth()->logout();

$user->connectedAccounts->each->delete();
$user->delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
use Inertia\Response;
Expand Down Expand Up @@ -51,7 +50,7 @@ public function destroy(Request $request): RedirectResponse

$user = $request->user();

Auth::logout();
auth()->logout();

$user->connectedAccounts->each->delete();
$user->delete();
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 51e2e5a

Please sign in to comment.