Skip to content

Commit 8a43e73

Browse files
authored
Merge pull request #32 from scyth3-c/fix-colab
fix colab flow
2 parents 65f4f66 + cc55509 commit 8a43e73

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

src/components/basecanvas.vue

+5-8
Original file line numberDiff line numberDiff line change
@@ -314,24 +314,21 @@ export default {
314314
}
315315
const codespace = params.get('codespace');
316316
317-
if(this.$store.state.visibles.colab && codespace && this.$store.state.isHost == false){
317+
318+
if(this.$store.state.visibles.colab && codespace){
319+
this.$store.state.visibles.codespace = codespace
318320
this.$store.dispatch('setColab', false)
319321
this.$store.dispatch("extract_codespace", codespace)
320322
this.$store.dispatch('toColabClient', codespace)
321323
this.$store.dispatch('socketOn', this)
322324
}
323325
324-
if(codespace && this.$store.state.visibles.codespace == "null" && this.$store.state.isHost == false){
325-
326+
if(codespace && this.$store.state.visibles.codespace == "null"){
327+
this.$store.state.visibles.codespace = codespace
326328
this.$store.dispatch('setColab', false)
327329
this.$store.dispatch("extract_codespace", codespace)
328330
this.$store.dispatch('socketOn', this)
329331
}
330-
331-
if(this.$store.state.isHost){
332-
this.$store.dispatch('socketOn', this)
333-
}
334-
335332
},
336333
mounted() {
337334
this.local_widthQuery.addEventListener('change',()=>{

src/store.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export default new Vuex.Store({
3232
headers: "iostream string",
3333
usecurl: "off",
3434
isSocketActive: false,
35-
isHost: JSON.parse(localStorage.getItem("o.isHost")) == undefined ? false : JSON.parse(localStorage.getItem("o.isHost")),
35+
36+
isClient: JSON.parse(localStorage.getItem("o.isClient")) == undefined ? false : JSON.parse(localStorage.getItem("o.isClient")),
37+
isHost: JSON.parse(localStorage.getItem("o.isHost")) == undefined ? false : JSON.parse(localStorage.getItem("o.isHost")),
38+
3639
visibles: {
3740
options: JSON.parse(localStorage.getItem("v.options")) == undefined ? true : JSON.parse(localStorage.getItem("v.options")) ,
3841
addons: JSON.parse(localStorage.getItem("v.addons")) == undefined ? true : JSON.parse(localStorage.getItem("v.addons")),
@@ -634,23 +637,26 @@ int main() {
634637
},
635638

636639
async internal_colab_clock({state,commit}, enviroment){
637-
clearTimeout(state.timer);
640+
clearTimeout(state.timer);
638641

639642
state.timer = setTimeout(async () => {
640643
let codebase = state.codeSpaces[state.actualCodeSpace].code
641644
await axios.put(`${state.API}codespace/update?id=${state.visibles.codespace}`, {
642645
code: codebase
643646
});
644-
645647
enviroment.$socketio.emit('UpdateCodeSpace', state.visibles.codespace)
646-
}, 500);
648+
}, 1500);
647649
},
648650

649-
async socketOn({state, dispatch}, enviroment){
651+
async socketOn({state}, enviroment){
652+
653+
console.log(state.visibles.colab, "--", state.visibles.codespace)
654+
650655
if(state.visibles.colab && state.visibles.codespace != "null"){
651656
enviroment.$socketio.on('actualizacion_base', async (args)=>{
652657
if(args == state.visibles.codespace){
653-
dispatch("extract_codespace", args)
658+
const code = await axios.get(`${state.API}codespace/extract?id=${args}`);
659+
state.codeSpaces[0].code = code.data.code
654660
}
655661
});
656662
}
@@ -676,11 +682,11 @@ int main() {
676682
data: { code: codeBase, codespace: state.identity, time: new Date().getDate().toString()},
677683
});
678684

679-
localStorage.setItem("o.isHost", true)
680685
localStorage.setItem("v.codespace", String(query?.data || undefined) )
681686
state.visibles.codespace = String(query?.data)
682687
state.share.codespace = window.location.origin + "?codespace="+query.data
683688
commit('setColabUrl')
689+
window.location.reload(true)
684690
},
685691

686692
toColabClient({state}, codespace){
@@ -689,16 +695,6 @@ int main() {
689695
state.visibles.colab = true
690696
},
691697

692-
async extract_codespace({state, commit}, id){
693-
const code = await axios.get(`${state.API}codespace/extract?id=${id}`);
694-
console.log(code.data)
695-
if(code?.data != undefined) {
696-
state.codeSpaces[0].code = code?.data.code
697-
} else{
698-
return;
699-
}
700-
},
701-
702698
async share({state,commit}){
703699

704700
let code = state.codeSpaces[state.actualCodeSpace].code;
@@ -721,7 +717,12 @@ int main() {
721717
state.share_id = data.data
722718
}
723719

724-
},
720+
},
721+
722+
async extract_codespace({state, commit}, id){
723+
const code = await axios.get(`${state.API}codespace/extract?id=${id}`);
724+
state.codeSpaces[0].code = code?.data.code
725+
},
725726

726727
async extract_notecode({state,commit}, id){
727728
const nota = await axios.get(`${state.API}notes/show?id=${id}`);

0 commit comments

Comments
 (0)