Make frontend request tab list on initialization

This commit is contained in:
Keavon Chambers
2021-07-15 00:07:21 -07:00
parent 2e579a3ac6
commit 0b44a17a5d
3 changed files with 16 additions and 1 deletions
@@ -51,6 +51,8 @@ import LayoutRow from "../layout/LayoutRow.vue";
import LayoutCol from "../layout/LayoutCol.vue"; import LayoutCol from "../layout/LayoutCol.vue";
import Panel from "./Panel.vue"; import Panel from "./Panel.vue";
const wasm = import("@/../wasm/pkg");
export default defineComponent({ export default defineComponent({
components: { components: {
LayoutRow, LayoutRow,
@@ -69,12 +71,14 @@ export default defineComponent({
const documentData = responseData as SetActiveDocument; const documentData = responseData as SetActiveDocument;
if (documentData) this.activeDocument = documentData.document_index; if (documentData) this.activeDocument = documentData.document_index;
}); });
(async () => (await wasm).get_open_documents_list())();
}, },
data() { data() {
return { return {
activeDocument: 0, activeDocument: 0,
documents: ["Untitled Document"], // TODO: start as an empty list documents: [] as Array<string>,
}; };
}, },
}); });
+5
View File
@@ -28,6 +28,11 @@ pub fn select_document(document: usize) -> Result<(), JsValue> {
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::SelectDocument(document)).map_err(convert_error)) EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::SelectDocument(document)).map_err(convert_error))
} }
#[wasm_bindgen]
pub fn get_open_documents_list() -> Result<(), JsValue> {
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::GetOpenDocumentsList).map_err(convert_error))
}
#[wasm_bindgen] #[wasm_bindgen]
pub fn new_document() -> Result<(), JsValue> { pub fn new_document() -> Result<(), JsValue> {
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::NewDocument).map_err(convert_error)) EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::NewDocument).map_err(convert_error))
@@ -35,6 +35,7 @@ pub enum DocumentMessage {
CloseAllDocumentsWithConfirmation, CloseAllDocumentsWithConfirmation,
CloseAllDocuments, CloseAllDocuments,
NewDocument, NewDocument,
GetOpenDocumentsList,
NextDocument, NextDocument,
PrevDocument, PrevDocument,
ExportDocument, ExportDocument,
@@ -303,6 +304,11 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
); );
responses.push_back(SelectDocument(self.active_document_index).into()); responses.push_back(SelectDocument(self.active_document_index).into());
} }
GetOpenDocumentsList => {
// Send the list of document tab names
let open_documents = self.documents.iter().map(|doc| doc.name.clone()).collect();
responses.push_back(FrontendMessage::UpdateOpenDocumentsList { open_documents }.into());
}
NextDocument => { NextDocument => {
let id = (self.active_document_index + 1) % self.documents.len(); let id = (self.active_document_index + 1) % self.documents.len();
responses.push_back(SelectDocument(id).into()); responses.push_back(SelectDocument(id).into());