Skip to content

Commit d46de52

Browse files
committed
GH-230 Move feedback messages to their own component
1 parent 036f7de commit d46de52

File tree

6 files changed

+83
-19
lines changed

6 files changed

+83
-19
lines changed

modules/overview/_includes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
include($includePath . './screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php');
2828
include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php');
2929
include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php');
30+
include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php');
31+
include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php');
3032
include($includePath . './screens/Overview/components/GiftItemsInfoBox/GiftItemsInfoBox.component.php');
3133
include($includePath . './screens/Overview/components/Morale/Morale.component.php');
3234
include($includePath . './screens/Overview/components/Morale/Morale.utils.php');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\FeedbackMessagesDisplay;
4+
5+
use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\FeedbackMessagesDisplay;
6+
7+
/**
8+
* @param array $props
9+
* @param arrayRef $props['input']
10+
*/
11+
function render($props) {
12+
$messages = FeedbackMessagesDisplay\Utils\getMessagesToDisplay($props);
13+
14+
if (empty($messages)) {
15+
return [
16+
'componentHTML' => '',
17+
];
18+
}
19+
20+
$localTemplateLoader = createLocalTemplateLoader(__DIR__);
21+
$tplBodyCache = [
22+
'messageRow' => $localTemplateLoader('messageRow'),
23+
];
24+
25+
$parsedMessages = array_map_withkeys($messages, function ($message) use (&$tplBodyCache) {
26+
return parsetemplate(
27+
$tplBodyCache['messageRow'],
28+
$message
29+
);
30+
});
31+
32+
$componentHTML = implode('', $parsedMessages);
33+
34+
return [
35+
'componentHTML' => $componentHTML,
36+
];
37+
}
38+
39+
?>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\FeedbackMessagesDisplay\Utils;
4+
5+
/**
6+
* @param array $props
7+
* @param arrayRef $props['input']
8+
*/
9+
function getMessagesToDisplay($props) {
10+
global $_Lang;
11+
12+
$input = &$props['input'];
13+
14+
$messages = [];
15+
16+
if (
17+
!empty($input['showmsg']) &&
18+
$input['showmsg'] == 'abandon'
19+
) {
20+
$messages[] = [
21+
'messageContent' => $_Lang['Abandon_ColonyAbandoned'],
22+
'colorClass' => 'lime',
23+
];
24+
}
25+
26+
return $messages;
27+
}
28+
29+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
header("Location: ../index.php");
4+
5+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<tr>
2+
<th colspan="3" class="pad5 {colorClass}">
3+
{messageContent}
4+
</th>
5+
</tr>

overview.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,9 @@
9898
])['componentHTML'];
9999

100100
// --- System Messages Box -------------------------------------------------------------------------------
101-
if(!empty($_GET['showmsg']))
102-
{
103-
$SysMsgLoop = 0;
104-
if($_GET['showmsg'] == 'abandon')
105-
{
106-
$ShowSystemMsg[$SysMsgLoop]['txt'] = $_Lang['Abandon_ColonyAbandoned'];
107-
$ShowSystemMsg[$SysMsgLoop]['col'] = 'lime';
108-
$SysMsgLoop += 1;
109-
}
110-
}
111-
112-
if(!empty($ShowSystemMsg))
113-
{
114-
$parse['SystemMsgBox'] = '';
115-
foreach($ShowSystemMsg as $SystemMsg)
116-
{
117-
$parse['SystemMsgBox'] .= '<tr><th colspan="3" class="pad5 '.$SystemMsg['col'].'">'.$SystemMsg['txt'].'</th></tr>';
118-
}
119-
}
101+
$parse['SystemMsgBox'] = Overview\Screens\Overview\Components\FeedbackMessagesDisplay\render([
102+
'input' => &$_GET,
103+
])['componentHTML'];
120104

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

0 commit comments

Comments
 (0)