Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Jan 16, 2023
1 parent 5548686 commit c934715
Show file tree
Hide file tree
Showing 13 changed files with 570 additions and 442 deletions.
2 changes: 2 additions & 0 deletions app/Enum/Livewire/PageMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ enum PageMode: string implements Wireable
case GALLERY = 'gallery';
case MAP = 'map';
case SETTINGS = 'settings';
case LOGS = 'logs';
case DIAGNOSTICS = 'diagnostics';
}
52 changes: 52 additions & 0 deletions app/Http/Livewire/Components/Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Http\Livewire\Components;

use App\Enum\Livewire\GalleryMode;
use App\Enum\Livewire\PageMode;
use App\Http\Livewire\Traits\AlbumProperty;
use App\Http\Livewire\Traits\InteractWithModal;
use App\Models\Extensions\BaseAlbum;
use App\SmartAlbums\BaseSmartAlbum;
use Illuminate\View\View;
use Livewire\Component;

/**
* This is the "start" page of the gallery
* Integrate the list of all albums at top level.
*/
class Header extends Component
{
use InteractWithModal;
use AlbumProperty;

public ?PageMode $page_mode = null;
public ?GalleryMode $gallery_mode = null;
public string $title = '';
public bool $is_hidden = false;

public ?BaseAlbum $baseAlbum = null;
public ?BaseSmartAlbum $smartAlbum = null;


/**
* Render the header.
*
* @return View
*/
public function render(): View
{
return view('livewire.components.header');
}


/**
* Open a login modal box.
*
* @return void
*/
public function openLoginModal(): void
{
$this->openModal('forms.login');
}
}
20 changes: 20 additions & 0 deletions app/Http/Livewire/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Enum\Livewire\PageMode;
use App\Factories\AlbumFactory;
use App\Http\Controllers\IndexController;
use App\Http\Livewire\Traits\UrlChange;
use App\Models\Configs;
use App\Models\Extensions\BaseAlbum;
use App\Models\Photo;
Expand All @@ -13,13 +14,16 @@

class Index extends Component
{
use UrlChange;

public PageMode $mode;
public ?string $albumId = null;
public ?string $photoId = null;

// listeners of click events
protected $listeners = [
'openLeftMenu',
'openPage',
'reloadPage',
];

Expand Down Expand Up @@ -87,6 +91,22 @@ public function openLeftMenu(): void
$this->emitTo('components.left-menu', 'open');
}

/**
* Open page.
*
* @return void
*/
public function openPage(string $page): void
{
$this->albumId = null;
$this->photoId = null;
$this->mode = PageMode::from($page);

// update URL
$this->emitUrlChange($this->mode, $this->albumId ?? '', $this->photoId ?? '');

}

/*
** This triggers a full reloading of the page
*/
Expand Down
24 changes: 6 additions & 18 deletions app/Http/Livewire/Pages/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Controllers\IndexController;
use App\Http\Livewire\Traits\AlbumProperty;
use App\Http\Livewire\Traits\InteractWithModal;
use App\Http\Livewire\Traits\UrlChange;
use App\Models\Configs;
use App\Models\Extensions\BaseAlbum;
use App\Models\Photo;
Expand All @@ -21,6 +22,7 @@ class Gallery extends Component
* Add interaction with modal
*/
use InteractWithModal;
use UrlChange;

/**
* Because AbstractAlbum is an Interface, it is not possible to make it
Expand Down Expand Up @@ -48,7 +50,7 @@ class Gallery extends Component
/**
* @var array<int,string> listeners of click events
*/
protected $listeners = ['openAlbum', 'openPhoto', 'back', 'reloadPage' => '$refresh'];
protected $listeners = ['openAlbum', 'openPhoto', 'back'];

/**
* While in most Laravel Controller calls we use the constructor,
Expand Down Expand Up @@ -170,7 +172,7 @@ public function openAlbum(string $albumId)
{
$this->albumId = $albumId;
$this->load();
$this->emit('urlChange', route('livewire_index', ['page' => PageMode::GALLERY, 'albumId' => $this->albumId, 'photoId' => $this->photoId]));
$this->emitUrlChange(PageMode::GALLERY, $this->albumId, $this->photoId);
}

/**
Expand All @@ -185,7 +187,7 @@ public function openPhoto(string $photoId)
$this->photoId = $photoId;

// This ensures that the history has been updated
$this->emit('urlChange', route('livewire_index', ['page' => PageMode::GALLERY, 'albumId' => $this->albumId, 'photoId' => $this->photoId]));
$this->emitUrlChange(PageMode::GALLERY, $this->albumId, $this->photoId);
}

/**
Expand All @@ -205,21 +207,7 @@ public function back()
}

// This ensures that the history has been updated
$this->emit('urlChange', route('livewire_index', [
'page' => PageMode::GALLERY,
'albumId' => $this->albumId ?? '',
'photoId' => $this->photoId ?? '',
]));
}

/**
* Open a login modal box.
*
* @return void
*/
public function openLoginModal(): void
{
$this->openModal('forms.login');
$this->emitUrlChange(PageMode::GALLERY, $this->albumId ?? '', $this->photoId ?? '');
}

/**
Expand Down
15 changes: 15 additions & 0 deletions app/Http/Livewire/Pages/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Http\Livewire\Pages;

use App\Enum\Livewire\PageMode;
use App\Http\Livewire\Traits\InteractWithModal;
use Illuminate\View\View;
use Livewire\Component;

class Settings extends Component
Expand All @@ -11,4 +13,17 @@ class Settings extends Component
* Add interaction with modal
*/
use InteractWithModal;

public PageMode $mode = PageMode::SETTINGS;

/**
* Rendering of the front-end.
*
* @return View
*/
public function render(): View
{
return view('livewire.pages.settings');
}

}
31 changes: 31 additions & 0 deletions app/Http/Livewire/Traits/UrlChange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Livewire\Traits;

use App\Enum\Livewire\PageMode;
use Illuminate\Contracts\Container\BindingResolutionException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;

/**
* This trait provides a simple helper to update the URL of the browser.
*/
trait UrlChange
{
/**
* Send an event to trigger updating the URL in the browser.
*
* @param PageMode $page
* @param string $albumId
* @param string $photoId
*
* @return void
* @throws BindingResolutionException
* @throws RouteNotFoundException
*/
protected function emitUrlChange(PageMode $page, string $albumId, string $photoId): void
{
// This ensures that the history has been updated
$this->emit('urlChange', route('livewire_index', ['page' => $page, 'albumId' => $albumId, 'photoId' => $photoId]));
}

}
89 changes: 0 additions & 89 deletions resources/views/components/header.blade.php

This file was deleted.

Loading

0 comments on commit c934715

Please sign in to comment.