Skip to content

Commit

Permalink
fix(stackchooser): redirect to the first launched service
Browse files Browse the repository at this point in the history
  • Loading branch information
clabroche committed Mar 19, 2024
1 parent f2559fb commit aa53535
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
32 changes: 20 additions & 12 deletions fronts/app/src/components/StackChooser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
import Stack from '../models/stack'
import System from '../models/system'
import SectionVue from '../components/Section.vue'
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { computed, onMounted, reactive, ref } from 'vue'
import BackgroundStackChooser from '../components/BackgroundStackChooser.vue'
import LeftLogo from '../components/LeftLogo.vue'
import { useRouter } from 'vue-router';
import Socket from '../helpers/Socket'

export default {
name: 'StackChooser',
Expand All @@ -62,17 +63,24 @@ export default {
const router = useRouter();
/** @type {import('vue').Ref<{label: string | undefined, enabled: boolean, groups: string[] | undefined}[]>} */
const servicesToLaunch = ref([])
onMounted(async () => {
await Stack.loadServices()
servicesToLaunch.value = Stack.services.value.map(service => {
const state = localStorage.getItem(`automatic-toggle-${service.label}`)
return {
label: service.label,
enabled: state === 'true' || service.enabled || false,
groups: service.groups
}
})
})
async function reload() {
await Stack.loadServices()
servicesToLaunch.value = Stack.services.value.map(service => {
const state = localStorage.getItem(`automatic-toggle-${service.label}`)
return {
label: service.label,
enabled: state === 'true' || service.enabled || false,
groups: service.groups
}
})
if(router.currentRoute.value.name === 'stack-chooser') {
const launched = Stack.services.value.find((service) => service.enabled)
if (launched) router.push({ name: 'stack-single', params: { label: launched.label } })
}
}
onMounted(reload)
Socket.socket?.on('stack:selectConf', reload)
Socket.socket?.on('service:start', reload)

const validate = async () => {
servicesToLaunch.value.forEach((s) => {
Expand Down
2 changes: 2 additions & 0 deletions fronts/app/src/helpers/Socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Socket } from '@clabroche/common-socket-front';
import config from './config';

export default {
/** @type {Awaited<ReturnType<typeof Socket.init>> | null} */
socket: null,
async init() {
this.socket = await Socket.init(config.baseURL, 'stack-monitor', '/socket.io', () => true);
},
Expand Down
1 change: 1 addition & 0 deletions servers/server/models/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class Stack {
}
});
}
sockets.io?.emit('stack:selectConf');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion servers/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "https://corentinlabroche.fr/"
},
"scripts": {
"start": "node bin/www $STACKFILE $SERVICE",
"start": "node bin/www $STACKFILE \"$SERVICE\"",
"serve": "nodemon -e js,ts,jsx,tsx,vue,swagger.yml,swagger.yaml -x 'node ../../watch.js npm run start'",
"build": "tsup",
"test": ""
Expand Down

0 comments on commit aa53535

Please sign in to comment.