Page MenuHomec4science

scenario.js
No OneTemporary

File Metadata

Created
Wed, Aug 14, 13:10

scenario.js

import axios from 'axios';
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { genericFetch, genericAdd, genericUpdate, genericRemove } from './utils';
export const useScenarioStore = defineStore('scenario', () => {
const state = ref([]);
// not process.env because we use VITE and not vue cli
const endpointURL = import.meta.env.VITE_API_URL + '/scenarios';
const fetch = genericFetch(endpointURL, state);
const fetchInterferences = async (id) => {
const interferences = ref({});
await genericFetch(`${endpointURL}/${id}/interferences`, interferences)();
return interferences;
};
const exportToJSON = async ({ id, scenarioID }, { id: playerID, name }) => {
const res = await axios.post(
`${endpointURL}/${id}/export`,
{ playerID },
{ responseType: 'blob' });
const url = window.URL.createObjectURL(res.data);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `${scenarioID}-${name}.json`);
document.body.appendChild(link);
link.click();
window.URL.revokeObjectURL(url)
document.body.removeChild(link);
};
return {
state, fetch, fetchInterferences, exportToJSON,
add: genericAdd(endpointURL, fetch),
update: genericUpdate(endpointURL, fetch),
remove: genericRemove(endpointURL, fetch)
};
});

Event Timeline