Skip to content

Commit

Permalink
Allow changing the FMS url via settings
Browse files Browse the repository at this point in the history
We don't yet refresh on change, so after setting, you'll need to manually refresh the page to connect.
  • Loading branch information
333fred committed Sep 25, 2024
1 parent 0c46dfd commit 6b0b183
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ui/src/fms/fms-signalr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { components } from './fms-api';
const fieldMonitorHubPostfix = 'fieldMonitorHub';

export function connectFieldMonitor(
fmsUrl: `http://${string}`
fmsUrl: string
): signalR.HubConnection & FieldMonitorHub {
const connection = new signalR.HubConnectionBuilder()
.withUrl(`${fmsUrl}/${fieldMonitorHubPostfix}`)
Expand Down
9 changes: 9 additions & 0 deletions ui/src/lib/components/dialogs/SettingsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@
API Key
</TextInput>

<TextInput
bind:text={settings.fmsUrl}
placeholder="http://localhost"
onblur={updateSettings}
>
FMS URL
</TextInput>


<div class="grid gap-2 md:col-span-2 mt-2">
{#if installPrompt}
<Button
Expand Down
4 changes: 3 additions & 1 deletion ui/src/lib/settings-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Settings {
darkMode: boolean;
username: string;
key: string;
fmsUrl: string;
}

let initialSettings = browser ? window.localStorage.getItem('settings') : null;
Expand All @@ -16,7 +17,8 @@ const defaultSettings: Settings = {
developerMode: false,
darkMode: true,
username: '',
key: ''
key: '',
fmsUrl: 'http://10.0.100.5',
};

if (!initialSettings) {
Expand Down
3 changes: 2 additions & 1 deletion ui/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Red2Default,
Red3Default
} from './defaults';
import { settingsStore } from '$lib/settings-store';
let blue1: FieldMonitorData = Blue1Default;
let blue2: FieldMonitorData = Blue2Default;
Expand All @@ -23,7 +24,7 @@
let detailView = () => {};
const signalrConnection = connectFieldMonitor('http://localhost:5000');
const signalrConnection = connectFieldMonitor($settingsStore.fmsUrl);
signalrConnection.onFieldMonitorDataChanged((data) => {
for (const team of data) {
if (!team) continue;
Expand Down

0 comments on commit 6b0b183

Please sign in to comment.