Update Submissions and add fields
This commit is contained in:
@@ -16,6 +16,17 @@ class GameSelector extends Component
|
||||
|
||||
public const int REQUIRED_CHARS = 3;
|
||||
|
||||
/**
|
||||
* Which section we can change selection mode.
|
||||
*/
|
||||
public const array CHANGE_SECTION_MODE = [ 'utilities', 'documents' ];
|
||||
|
||||
/**
|
||||
* Selection mode between game|platform|none.
|
||||
* @var string
|
||||
*/
|
||||
public string $selectionMode = 'game';
|
||||
|
||||
/**
|
||||
* If we are in new game mode.
|
||||
* @var bool
|
||||
@@ -70,9 +81,25 @@ class GameSelector extends Component
|
||||
*/
|
||||
public bool $dropdown = false;
|
||||
|
||||
public function mount( ?int $gameId = null, ?string $newGameTitle = null, ?int $newGamePlatform = null, ?int $newGameGenre = null ): void
|
||||
/**
|
||||
* In platform mode.
|
||||
* @var int|null
|
||||
*/
|
||||
public ?int $platformModeId = null;
|
||||
|
||||
/**
|
||||
* In platform mode.
|
||||
* @var string|null
|
||||
*/
|
||||
public ?string $platformModeName = null;
|
||||
|
||||
public ?string $section = null;
|
||||
|
||||
public function mount( ?int $gameId = null, ?string $newGameTitle = null, ?int $newGamePlatform = null, ?int $newGameGenre = null, ?string $section, ?int $platformOnlyId ): void
|
||||
{
|
||||
|
||||
$this->section = $section;
|
||||
|
||||
// If we selected an existent game.
|
||||
if( $gameId ){
|
||||
$game = Game::with(['platform','genre'])->find($gameId);
|
||||
@@ -93,6 +120,36 @@ class GameSelector extends Component
|
||||
$this->gamePlatformId = is_numeric($newGamePlatform) ? (int) $newGamePlatform : null;
|
||||
$this->gameGenreId = is_numeric($newGameGenre) ? (int) $newGameGenre : null;
|
||||
}
|
||||
|
||||
if( in_array( $section, self::CHANGE_SECTION_MODE ) ) {
|
||||
if ($platformOnlyId) {
|
||||
$this->selectionMode = 'platform';
|
||||
$this->platformModeId = $platformOnlyId;
|
||||
$platform = Platform::find($platformOnlyId);
|
||||
if ($platform) {
|
||||
$this->platformModeName = $platform->name;
|
||||
} else {
|
||||
$this->platformModeId = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setSelectionMode(string $mode): void
|
||||
{
|
||||
if( !in_array( $this->section, self::CHANGE_SECTION_MODE ) )
|
||||
return;
|
||||
|
||||
$this->selectionMode = $mode;
|
||||
|
||||
if( $mode !== 'game' ){
|
||||
$this->clearGame();
|
||||
$this->newGame = false;
|
||||
}
|
||||
if( $mode !== 'platform' ){
|
||||
$this->platformModeId = null;
|
||||
$this->platformModeName = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,6 +191,15 @@ class GameSelector extends Component
|
||||
|
||||
}
|
||||
|
||||
public function selectPlatformOnly( int $id ): void
|
||||
{
|
||||
$platform = Platform::find($id);
|
||||
if( $platform ){
|
||||
$this->platformModeId = $platform->id;
|
||||
$this->platformModeName = $platform->name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear existent game selection.
|
||||
* @return void
|
||||
@@ -179,6 +245,10 @@ class GameSelector extends Component
|
||||
}
|
||||
$data['hasOldNewGame'] = old('new-game-title') || old('new-game-platform') || old('new-game-genre');
|
||||
|
||||
$data['canChangeSelection'] = in_array( $this->section, self::CHANGE_SECTION_MODE );
|
||||
if( in_array( $this->section, self::CHANGE_SECTION_MODE ) )
|
||||
$data['platforms'] = Platform::orderBy('name')->get();
|
||||
|
||||
return view('livewire.game-selector', $data );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user