Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ui now set the default WS address to the page origin #543

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-crabs-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nuster/ui": patch
---

feat: when maintenance is cleared, scroll is send to top
5 changes: 5 additions & 0 deletions .changeset/stale-games-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nuster/ui": patch
---

fix: cycle is now patched if you click back on the same cycle
5 changes: 5 additions & 0 deletions .changeset/strange-kiwis-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nuster/ui": patch
---

feat: websocket default url is current page Origin
10 changes: 5 additions & 5 deletions packages/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Interact with `@nuster/turbine`.

Use the environment variables to connect to turbine.

| Environement variable name | value expected | Default value | Description |
| -------------------------- | -------------- | ---------------- | ---------------------------------- |
| TURBINE_ADDRESS | `host:port` | `localhost:4080` | Turbine api address |
| TURBINE_WS_ADDRESS | `host:port` | `localhost:4080` | Turbine realtime websocket address |
| PORT | `number` | `4081` | Port on which app is served |
| Environement variable name | value expected | Default value | Description |
| -------------------------- | -------------- | ------------------- | ---------------------------------- |
| TURBINE_ADDRESS | `host:port` | `localhost:4080` | Turbine api address |
| TURBINE_WS_ADDRESS | `host:port` | Current page Origin | Turbine realtime websocket address |
| PORT | `number` | `4081` | Port on which app is served |

## Getting Started

Expand Down
7 changes: 5 additions & 2 deletions packages/ui/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
<link rel="apple-touch-icon" href="/icons/pwa-192.png" />

<meta name="google" content="notranslate" />
<meta name="description" content="Nuster Webapp" />

<meta name="robots" content="noindex" />
<meta name="googlebot" content="noindex" />

<title>Nuster</title>
<meta name="description" content="Nuster Webapp" />

%sveltekit.head%
</head>
<body>
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/routes/(connected)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@

const realtimeConnect = async () =>
{
if(!browser) return;

websocketState = "connecting";

const isSecure = window.location.protocol === "https:";

websocket = new WebSocket(`${isSecure ? "wss": "ws"}://${data.websocketAddress || 'localhost:4080'}/ws/`);
websocket = new WebSocket(`${isSecure ? "wss": "ws"}://${data.websocketAddress || new URL(window.origin).host}/ws/`);

websocket.onerror = function() {
websocketState = "disconnected";
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/src/routes/(connected)/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
let selectedPremadeIndex: number | undefined = undefined;
let cycleData: ProgramBlockRunnerHydrated | undefined;
let listShrinked = false;
let pathCycleButton: HTMLButtonElement;

/// — Reactives statements
$: if(form !== undefined && form?.patchCycle?.success === true) { cycleData = undefined; selectedPremadeIndex = undefined; }
Expand Down Expand Up @@ -61,13 +62,17 @@
{#each data.cyclePremades as premade, index}
{@const isPrimaryPremade = premade.cycle === "default"}

<form action="?/patchCycle" method="post" use:enhance>
<button class="hidden" bind:this={pathCycleButton} />
</form>

<form action="?/prepareCycle" method="post" use:enhance>
<input type="hidden" name="cycle_type" value={premade.cycle} />
<input type="hidden" name="profile_id" value={premade.profile?.id} />

<SelectableButton
selected={selectedPremadeIndex === index}
on:click={() => { selectedPremadeIndex = selectedPremadeIndex == index ? undefined : index; }}
on:click={(e) => { if(selectedPremadeIndex == index) { e.preventDefault(); pathCycleButton.click(); } else { selectedPremadeIndex = index; }}}
>
<Flex gap={4} items="center">
{#if premade.profile}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const actions = {

const clearRequest = await fetch(`http://${env.TURBINE_ADDRESS}/v1/maintenances/${maintenanceName}`, { method: "DELETE" });

if(clearRequest.status !== 200 || clearRequest.ok)
if(clearRequest.status !== 200 || !clearRequest.ok)
return fail(500, { clearMaintenance: { error: "Failed to clear maintenance" }});

return { clearMaintenance: { success: true }};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import MaintenanceImageParser from "$lib/components/markdown/MaintenanceImageParser.svelte";
import Button from "$lib/components/buttons/Button.svelte";
import { enhance } from "$app/forms";
import type { PageData } from "./$types";
import type { ActionData, PageData } from "./$types";
import Wrapper from "$lib/components/Wrapper.svelte";

export let data: PageData;
export let form: ActionData;

$: if(form?.clearMaintenance.success === true) { document.getElementsByTagName("main").item(0)?.scrollTo({ top: 0, behavior: "smooth" }); form = null; }

</script>

<Wrapper>
Expand All @@ -19,7 +23,7 @@
<p>{$_('maintenance.tasks.' + data.maintenance.name + '.desc')}</p>

{#if data.maintenance.operationDate}
<p class="font-medium">
<p class="font-semibold text-amber-500">
{$_('maintenance.last_operation')}:
<span class="font-normal">{$date(new Date(data.maintenance.operationDate), { format: "medium"})} — {$time(new Date(data.maintenance.operationDate), { format: "medium"})}</span>
</p>
Expand Down
Loading