Skip to content

Commit

Permalink
Pass only needed parameters for template
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Nov 21, 2024
1 parent d2856f7 commit 6eebd16
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/src/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ __Package repositories__:
${docsPackages.map((packageName) => '- $packageName: <https://github.com/nyxx-discord/$packageName>').join('\n')}
''');

final String webServerAlertContent = getEnv('WEB_SERVER_ALERT_CONTENT', '<span class="bold">Experimental version</span>');

/// The GitHub account to use when no other account is specified.
final String githubAccount = getEnv('ROD_GITHUB_ACCOUNT', 'nyxx-discord');

Expand Down
15 changes: 13 additions & 2 deletions lib/src/web_app/api_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,21 @@ class WebServer {
return shelf.Response.badRequest();
}

final additionalParameters = switch (templateName) {
'navigation' => {
'clientId': clientId,
'redirectUri': clientRedirectUri,
},
'alert' => {
'inner_content': webServerAlertContent,
},
_ => {},
};


return createTwigResponse('component/$templateName.html', parameters: {
...getCustomDataFromSession(request),
'clientId': clientId,
'redirectUri': clientRedirectUri,
...additionalParameters,
});
}

Expand Down
3 changes: 3 additions & 0 deletions templates/component/alert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="alert alert-danger mt-4" role="alert">
{{inner_content}}
</div>
4 changes: 1 addition & 3 deletions templates/guilds.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
<nav hx-get="/hx?c=navigation" hx-swap="outerHTML" hx-trigger="load"></nav>

<div class="container">
<div class="alert alert-danger mt-4" role="alert">
<span class="bold">Experimental version</span>
</div>
<div hx-get="/hx?c=alert" hx-swap="outerHTML" hx-trigger="load"></div>

<div class="container">
<div class="grid">
Expand Down
4 changes: 1 addition & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
<nav hx-get="/hx?c=navigation" hx-swap="outerHTML" hx-trigger="load"></nav>

<div class="container">
<div class="alert alert-danger mt-4" role="alert">
<span class="bold">Experimental version</span>
</div>
<div hx-get="/hx?c=alert" hx-swap="outerHTML" hx-trigger="load"></div>

<div class="container">
<div class="m-1">
Expand Down

0 comments on commit 6eebd16

Please sign in to comment.