Skip to content

Commit

Permalink
GH-230 Move feedback messages to their own component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 15, 2022
1 parent 036f7de commit d46de52
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 19 deletions.
2 changes: 2 additions & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
include($includePath . './screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php');
include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php');
include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php');
include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php');
include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php');
include($includePath . './screens/Overview/components/GiftItemsInfoBox/GiftItemsInfoBox.component.php');
include($includePath . './screens/Overview/components/Morale/Morale.component.php');
include($includePath . './screens/Overview/components/Morale/Morale.utils.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\FeedbackMessagesDisplay;

use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\FeedbackMessagesDisplay;

/**
* @param array $props
* @param arrayRef $props['input']
*/
function render($props) {
$messages = FeedbackMessagesDisplay\Utils\getMessagesToDisplay($props);

if (empty($messages)) {
return [
'componentHTML' => '',
];
}

$localTemplateLoader = createLocalTemplateLoader(__DIR__);
$tplBodyCache = [
'messageRow' => $localTemplateLoader('messageRow'),
];

$parsedMessages = array_map_withkeys($messages, function ($message) use (&$tplBodyCache) {
return parsetemplate(
$tplBodyCache['messageRow'],
$message
);
});

$componentHTML = implode('', $parsedMessages);

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

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

namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\FeedbackMessagesDisplay\Utils;

/**
* @param array $props
* @param arrayRef $props['input']
*/
function getMessagesToDisplay($props) {
global $_Lang;

$input = &$props['input'];

$messages = [];

if (
!empty($input['showmsg']) &&
$input['showmsg'] == 'abandon'
) {
$messages[] = [
'messageContent' => $_Lang['Abandon_ColonyAbandoned'],
'colorClass' => 'lime',
];
}

return $messages;
}

?>
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,5 @@
<tr>
<th colspan="3" class="pad5 {colorClass}">
{messageContent}
</th>
</tr>
22 changes: 3 additions & 19 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,9 @@
])['componentHTML'];

// --- System Messages Box -------------------------------------------------------------------------------
if(!empty($_GET['showmsg']))
{
$SysMsgLoop = 0;
if($_GET['showmsg'] == 'abandon')
{
$ShowSystemMsg[$SysMsgLoop]['txt'] = $_Lang['Abandon_ColonyAbandoned'];
$ShowSystemMsg[$SysMsgLoop]['col'] = 'lime';
$SysMsgLoop += 1;
}
}

if(!empty($ShowSystemMsg))
{
$parse['SystemMsgBox'] = '';
foreach($ShowSystemMsg as $SystemMsg)
{
$parse['SystemMsgBox'] .= '<tr><th colspan="3" class="pad5 '.$SystemMsg['col'].'">'.$SystemMsg['txt'].'</th></tr>';
}
}
$parse['SystemMsgBox'] = Overview\Screens\Overview\Components\FeedbackMessagesDisplay\render([
'input' => &$_GET,
])['componentHTML'];

// --- New Messages Information Box ----------------------------------------------------------------------
$parse['NewMsgBox'] = Overview\Screens\Overview\Components\NewMessagesInfo\render([
Expand Down

0 comments on commit d46de52

Please sign in to comment.