Skip to content

Commit 6d9e07c

Browse files
feat(stores): modify stores structures
BREAKING CHANGE: change getters and global variables name is_cloud_running -> cloud_store.is_running
1 parent 53a0e79 commit 6d9e07c

File tree

8 files changed

+65
-72
lines changed

8 files changed

+65
-72
lines changed

components/Launcher.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<vue-recaptcha ref="recaptcha" :sitekey="site_key" :loadRecaptchaScript="true"
99
@expired="is_captcha_validated = false" @verify="submit_recaptcha" align-self="center" />
1010
</v-col>
11-
<v-col v-if="!is_cloud_running && is_connexion_launched">
11+
<v-col v-if="!cloud_store.is_running">
1212
<Loading />
1313
</v-col>
1414
</v-row>
@@ -20,7 +20,7 @@ import { VueRecaptcha } from "vue-recaptcha"
2020
2121
const websocket_store = use_websocket_store()
2222
const cloud_store = use_cloud_store()
23-
const { is_cloud_running, is_captcha_validated, is_connexion_launched } = storeToRefs(cloud_store)
23+
const { is_captcha_validated } = storeToRefs(cloud_store)
2424
2525
const site_key = useRuntimeConfig().public.RECAPTCHA_SITE_KEY
2626

components/PackagesVersions.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const props = defineProps({
2222
const { route_prefix } = props
2323
2424
const cloud_store = use_cloud_store()
25-
const { is_cloud_running } = storeToRefs(cloud_store)
2625
2726
const packages_versions = ref([])
2827
@@ -34,20 +33,20 @@ async function get_packages_versions () {
3433
})
3534
}
3635
37-
watch(is_cloud_running, (value) => {
36+
watch(cloud_store.is_running, (value) => {
3837
if (value === true) {
3938
get_packages_versions()
4039
}
4140
})
4241
4342
onMounted(() => {
44-
if (is_cloud_running.value === true) {
43+
if (cloud_store.is_running === true) {
4544
get_packages_versions()
4645
}
4746
})
4847
4948
onActivated(() => {
50-
if (is_cloud_running.value === true) {
49+
if (cloud_store.is_running === true) {
5150
get_packages_versions()
5251
}
5352
})

components/RemoteRenderingView.client.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useElementSize } from '@vueuse/core'
1414
const viewer_store = use_viewer_store()
1515
const { picking_mode } = storeToRefs(viewer_store)
1616
const websocket_store = use_websocket_store()
17-
const { client, is_client_created } = storeToRefs(websocket_store)
17+
const { client } = storeToRefs(websocket_store)
1818
1919
function get_x_y (event) {
2020
if (picking_mode.value === true) {
@@ -77,7 +77,7 @@ onMounted(async () => {
7777
})
7878
7979
function connect () {
80-
if (!is_client_created.value) { return }
80+
if (!websocket_store.is_running) { return }
8181
console.log('connecting', client.value)
8282
const session = client.value.getConnection().getSession()
8383
view.setSession(session)

components/Wrapper.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<v-col>
55
<Header :tool_name="tool_name" :cards_list="cards_list" />
66
</v-col>
7-
<v-col v-if="!is_cloud_running">
7+
<v-col v-if="!cloud_store.is_running">
88
<Launcher />
99
</v-col>
10-
<v-col v-if="is_cloud_running">
10+
<v-col v-if="cloud_store.is_running">
1111
<Stepper />
1212
</v-col>
13-
<v-col v-if="is_cloud_running">
13+
<v-col v-if="cloud_store.is_running">
1414
<PackagesVersions :route_prefix="route_prefix" />
1515
</v-col>
1616
</v-row>
@@ -19,7 +19,6 @@
1919

2020
<script setup>
2121
const cloud_store = use_cloud_store()
22-
const { is_cloud_running } = storeToRefs(cloud_store)
2322
2423
const props = defineProps({
2524
cards_list: { type: Array, required: true },

composables/api_fetch.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
export function api_fetch (request_url, request_options, { request_error_function, response_function, response_error_function } = {}) {
22
const errors_store = use_errors_store()
3-
const cloud_store = use_cloud_store()
43
const geode_store = use_geode_store()
54

65
geode_store.start_request()
76
return useFetch(request_url,
87
{
9-
baseURL: cloud_store.geode_url,
8+
baseURL: geode_store.base_url,
109
...request_options,
1110
onRequestError ({ error }) {
1211
geode_store.stop_request()

stores/cloud.js

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,11 @@ export const use_cloud_store = defineStore('cloud', {
77
is_connexion_launched: false,
88
}),
99
getters: {
10-
geode_url: (state) => {
11-
const public_runtime_config = useRuntimeConfig().public
12-
var geode_url = `${public_runtime_config.GEODE_PROTOCOL}://${public_runtime_config.API_URL}:${public_runtime_config.GEODE_PORT}`
13-
if (process.env.NODE_ENV == 'production') {
14-
geode_url = geode_url + `/${state.ID}/geode`
15-
}
16-
return geode_url
17-
},
18-
viewer_url: (state) => {
19-
const public_runtime_config = useRuntimeConfig().public
20-
var viewer_url = `${public_runtime_config.VIEWER_PROTOCOL}://${public_runtime_config.API_URL}:${public_runtime_config.VIEWER_PORT}`
21-
if (process.env.NODE_ENV == 'production') {
22-
viewer_url = viewer_url + `/${state.ID}/viewer`
23-
}
24-
viewer_url = viewer_url + '/ws'
25-
return viewer_url
26-
},
27-
is_cloud_running: () => {
28-
return use_geode_store().is_client_created && use_websocket_store().is_client_created
10+
is_running: () => {
11+
return use_geode_store().is_running && use_websocket_store().is_running
2912
},
30-
cloud_busy: () => {
31-
const api_busy = use_geode_store().api_busy
32-
const websocket_busy = use_geode_store().websocket_busy
33-
const cloud_busy = api_busy || websocket_busy
34-
return cloud_busy
13+
is_busy: () => {
14+
return use_geode_store().is_busy || use_websocket_store().is_busy
3515
}
3616

3717
},
@@ -46,8 +26,8 @@ export const use_cloud_store = defineStore('cloud', {
4626
const { data, error } = await useFetch(`${this.geode_url}/ping`, { method: 'POST' })
4727
console.log("error", error)
4828
if (data.value !== null) {
49-
geode_store.is_client_created = true
50-
return this.ping_task()
29+
geode_store.is_running = true
30+
return geode_store.ping_task()
5131
} else {
5232
return this.create_backend()
5333
}
@@ -62,27 +42,12 @@ export const use_cloud_store = defineStore('cloud', {
6242
if (data.value !== null) {
6343
this.ID = data.value.ID
6444
localStorage.setItem('ID', data.value.ID)
65-
geode_store.is_client_created = true
66-
return this.ping_task()
45+
geode_store.is_running = true
46+
return geode_store.ping_task()
6747
} else {
6848
console.log("error : ", error)
6949
errors_store.server_error = true
7050
}
7151
},
72-
73-
ping_task () {
74-
setInterval(() => this.do_ping(), 10 * 1000)
75-
},
76-
async do_ping () {
77-
const geode_store = use_geode_store()
78-
const errors_store = use_errors_store()
79-
const { data, error } = await useFetch(`${this.geode_url}/ping`, { method: 'POST' })
80-
if (data.value !== null) {
81-
geode_store.is_client_created = true
82-
} else {
83-
errors_store.server_error = true
84-
console.log("error : ", error)
85-
}
86-
}
8752
}
8853
})

stores/geode.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
export const use_geode_store = defineStore('geode', {
22
state: () => ({
33
request_counter: 0,
4-
is_client_created: false
4+
is_running: false
55
}),
66
getters: {
7-
api_busy: (state) => {
7+
base_url: () => {
8+
const cloud_store = use_cloud_store()
9+
const public_runtime_config = useRuntimeConfig().public
10+
var geode_url = `${public_runtime_config.GEODE_PROTOCOL}://${public_runtime_config.API_URL}:${public_runtime_config.GEODE_PORT}`
11+
if (process.env.NODE_ENV == 'production') {
12+
geode_url = geode_url + `/${cloud_store.ID}/geode`
13+
}
14+
return geode_url
15+
},
16+
is_busy: (state) => {
817
return state.request_counter > 0
918
}
1019
},
1120
actions: {
21+
ping_task () {
22+
setInterval(() => this.do_ping(), 10 * 1000)
23+
},
24+
async do_ping () {
25+
const errors_store = use_errors_store()
26+
const { data, error } = await useFetch(`${this.base_url}/ping`, { method: 'POST' })
27+
if (data.value !== null) {
28+
this.is_running = true
29+
} else {
30+
errors_store.server_error = true
31+
console.log("error : ", error)
32+
}
33+
},
1234
start_request () {
1335
this.request_counter++
1436
},

stores/websocket.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,32 @@ export const use_websocket_store = defineStore('websocket', {
1616
client: {},
1717
config: null,
1818
request_counter: 0,
19-
is_client_created: false
19+
is_running: false
2020
}),
2121
getters: {
22-
websocket_busy: (state) => {
22+
base_url: () => {
23+
const cloud_store = use_cloud_store()
24+
const public_runtime_config = useRuntimeConfig().public
25+
var viewer_url = `${public_runtime_config.VIEWER_PROTOCOL}://${public_runtime_config.API_URL}:${public_runtime_config.VIEWER_PORT}`
26+
if (process.env.NODE_ENV == 'production') {
27+
viewer_url = viewer_url + `/${cloud_store.ID}/viewer`
28+
}
29+
viewer_url = viewer_url + '/ws'
30+
return viewer_url
31+
},
32+
is_busy: (state) => {
2333
return state.request_counter > 0
2434
}
2535
},
2636
actions: {
2737
ws_connect () {
2838
const config = { application: 'cone' };
29-
const cloud_store = use_cloud_store()
30-
config.sessionURL = cloud_store.viewer_url
39+
config.sessionURL = this.base_url
3140

3241
const { client } = this
33-
if (this.is_client_created && client.isConnected()) {
42+
if (this.is_running && client.isConnected()) {
3443
client.disconnect(-1);
35-
this.is_client_created = false;
44+
this.is_running = false;
3645
}
3746
let clientToConnect = client;
3847
if (_.isEmpty(clientToConnect)) {
@@ -74,7 +83,7 @@ export const use_websocket_store = defineStore('websocket', {
7483
// Now that the client is ready let's setup the server for us
7584
this.ws_initialize_server()
7685
this.client.getRemote().vtk.reset().catch(console.error);
77-
this.is_client_created = true;
86+
this.is_running = true;
7887
})
7988
.catch((error) => {
8089
console.error(error);
@@ -94,11 +103,11 @@ export const use_websocket_store = defineStore('websocket', {
94103
this.client.getRemote().vtk.reset_camera().catch(console.error);
95104
}
96105
},
97-
},
98-
start_request () {
99-
this.request_counter++
100-
},
101-
stop_request () {
102-
this.request_counter--
106+
start_request () {
107+
this.request_counter++
108+
},
109+
stop_request () {
110+
this.request_counter--
111+
}
103112
}
104113
})

0 commit comments

Comments
 (0)