Skip to content

Commit

Permalink
GH-139 Move speed options renderer into a separate component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed May 27, 2022
1 parent a688604 commit bd82c99
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 7 deletions.
11 changes: 4 additions & 7 deletions fleet1.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,10 @@
}
$_Lang['Insert_SpeedInput'] = $_Set_DefaultSpeed;

foreach ($SpeedsAvailable as $Selector) {
$Text = $Selector * 10;
$isSpeedSelected = ($_Set_DefaultSpeed == $Selector);

$_Lang['Insert_Speeds'][] = "<a href=\"#\" class=\"setSpeed ".($isSpeedSelected ? 'setSpeed_Selected setSpeed_Current' : '')."\" data-speed=\"{$Selector}\">{$Text}</a>";
}
$_Lang['Insert_Speeds'] = implode('<span class="speedBreak">|</span>', $_Lang['Insert_Speeds']);
$_Lang['Insert_Speeds'] = FlightControl\Screens\SendWizardStepTwo\Components\SpeedSelector\render([
'speedOptions' => $SpeedsAvailable,
'selectedOption' => $_Set_DefaultSpeed,
])['componentHTML'];

// Create Colony List and Shortcuts List (dropdown)
$OtherPlanets = SortUserPlanets($_User);
Expand Down
2 changes: 2 additions & 0 deletions modules/flightControl/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
include($includePath . './screens/SendWizardStepOne/components/FlightsList/utils/prerenderFriendlyAcsListElement.utils.php');
include($includePath . './screens/SendWizardStepOne/components/FlightsList/utils/prerenderOwnListElement.utils.php');

include($includePath . './screens/SendWizardStepTwo/components/SpeedSelector/SpeedSelector.component.php');

include($includePath . './screens/Shortcuts/Shortcuts.screen.php');
include($includePath . './screens/Shortcuts/components/ListManagement/ListManagement.component.php');
include($includePath . './screens/Shortcuts/components/ShortcutManagementForm/ShortcutManagementForm.component.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace UniEngine\Engine\Modules\FlightControl\Screens\SendWizardStepTwo\Components\SpeedSelector;

// Arguments
// - $props (Object)
// - speedOptions (object)
// - selectedOption (String)
//
// Returns: Object
// - componentHTML (String)
//
function render ($props) {
$speedOptions = $props['speedOptions'];
$selectedOption = $props['selectedOption'];

$localTemplateLoader = createLocalTemplateLoader(__DIR__);
$tplBodyCache = [
'optionBody' => trim($localTemplateLoader('optionBody')),
'optionsSeparator' => trim($localTemplateLoader('optionsSeparator')),
];

$optionsListElements = array_map_withkeys($speedOptions, function ($speedOption) use ($selectedOption, &$tplBodyCache) {
$label = $speedOption * 10;
$isSpeedSelected = ($selectedOption == $speedOption);

return parsetemplate($tplBodyCache['optionBody'], [
'isSelectedOptionClasses' => (
$isSpeedSelected ?
'setSpeed_Selected setSpeed_Current' :
''
),
'optionValue' => $speedOption,
'optionLabel' => $label,
]);
});

$elementsListHTML = implode($tplBodyCache['optionsSeparator'], $optionsListElements);

return [
'componentHTML' => $elementsListHTML,
];
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="#" class="setSpeed {isSelectedOptionClasses}" data-speed="{optionValue}">{optionLabel}</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span class="speedBreak">|</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
5 changes: 5 additions & 0 deletions modules/flightControl/screens/SendWizardStepTwo/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>

0 comments on commit bd82c99

Please sign in to comment.