This commit is contained in:
Gabriel Pastori
2023-11-28 14:15:46 -03:00
parent 2f97ad16f5
commit 3a08a0014a
16 changed files with 3235 additions and 15 deletions

View File

@@ -85,7 +85,8 @@ export const useAppStore = defineStore('app', {
this.instancesList = []
this.instancesKeys = {}
this.connectionsList = []
window.localStorage.clear();
this.saveLocalStorage()
},
async reconnect() {

65
src/store/doc.js Normal file
View File

@@ -0,0 +1,65 @@
// Utilities
import { defineStore } from 'pinia'
export const useDocStore = defineStore('doc', {
getters: {
lang: (state) => state.language,
},
state: () => ({
language: 'pt_br',
languages: [],
docs: {},
}),
actions: {
async setLang(lang) {
this.language = lang;
},
async loadDocs() {
try {
const { languages, docs } = getFileTree();
this.languages = languages;
this.docs = docs;
} catch (error) {
console.log(error);
}
},
async loadDoc(path) {
try {
debugger;
const { language } = this;
const doc = this.docs[path]
const content = await doc[language]();
return {
content,
language,
};
} catch (error) {
console.log(error);
throw new Error('Documento não encontrado');
}
}
}
})
// Function to get the file tree from @doc
function getFileTree() {
const tree = import.meta.glob('@docs/**/*.{md,mdx}', { as: 'raw'})
const docsFiles = {}
const languages = new Set()
Object.entries(tree).forEach(([path, imprt]) => {
const [, , lang, ...rest] = path.split('/')
languages.add(lang)
const filename = rest.join('/').replace(/\.mdx?$/, '')
docsFiles[filename] = docsFiles[filename] || {}
docsFiles[filename][lang] = imprt
})
return {
languages: Array.from(languages),
docs: docsFiles,
}
}