Skip to content

Commit

Permalink
Merge pull request #19 from 333fred/fms-url-settings
Browse files Browse the repository at this point in the history
Allow changing the FMS url via settings
  • Loading branch information
bherbst authored Sep 25, 2024
2 parents 0c46dfd + 547e9f0 commit c7beb4e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 1 addition & 3 deletions ui/src/fms/fms-signalr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import type { components } from './fms-api';

const fieldMonitorHubPostfix = 'fieldMonitorHub';

export function connectFieldMonitor(
fmsUrl: `http://${string}`
): signalR.HubConnection & FieldMonitorHub {
export function connectFieldMonitor(fmsUrl: string): signalR.HubConnection & FieldMonitorHub {
const connection = new signalR.HubConnectionBuilder()
.withUrl(`${fmsUrl}/${fieldMonitorHubPostfix}`)
.withHubProtocol(new MessagePackHubProtocol())
Expand Down
4 changes: 4 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,10 @@
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 c7beb4e

Please sign in to comment.