From f4300bb9eb7aeea036b423fbbaa6249ac24f38d9 Mon Sep 17 00:00:00 2001 From: cardosofede Date: Fri, 4 Aug 2023 18:40:10 +0200 Subject: [PATCH] (feat) add file manager tab --- pages/file_manager/app.py | 50 ++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/pages/file_manager/app.py b/pages/file_manager/app.py index 4843ca8..56c8180 100644 --- a/pages/file_manager/app.py +++ b/pages/file_manager/app.py @@ -1,44 +1,40 @@ -import streamlit as st -from streamlit_elements import elements, mui, lazy, sync, event - from types import SimpleNamespace - import streamlit as st -from streamlit_elements import elements, mui, lazy, sync, event +from streamlit_elements import elements, mui +from ui_components.bots_file_explorer import BotsFileExplorer from ui_components.dashboard import Dashboard -from ui_components.file_explorer import FileExplorer from ui_components.editor import Editor from utils.st_utils import initialize_st_page -initialize_st_page(title="File Manager", icon="🗂️", initial_sidebar_state="expanded") -if "editor_tabs" not in st.session_state: - st.session_state.editor_tabs = {} +initialize_st_page(title="File Manager", icon="🗂️", initial_sidebar_state="collapsed") -# TODO: Use this to save the current file selected -if "selected_file" not in st.session_state: - st.session_state.selected_file = "" -if "w" not in st.session_state: +if "fe_board" not in st.session_state: board = Dashboard() - w = SimpleNamespace( + fe_board = SimpleNamespace( dashboard=board, - file_explorer=FileExplorer(board, 0, 0, 3, 7), + file_explorer=BotsFileExplorer(board, 0, 0, 3, 7), editor=Editor(board, 4, 0, 9, 7), ) - st.session_state.w = w + st.session_state.fe_board = fe_board + else: - w = st.session_state.w + fe_board = st.session_state.fe_board -for tab_name, content in st.session_state.editor_tabs.items(): - if tab_name not in w.editor._tabs: - w.editor.add_tab(tab_name, content["content"], content["language"], content["file_path"]) +# Add new tabs +for tab_name, content in fe_board.file_explorer.tabs.items(): + if tab_name not in fe_board.editor.tabs: + fe_board.editor.add_tab(tab_name, content["content"], content["language"]) -with elements("bot_config"): - with mui.Paper(style={"padding": "2rem"}, variant="outlined"): - mui.Typography("Select a file and click ✏️ to edit it or 🗑️ to delete it. Click 💾 to save your changes.", variant="body1", sx={"margin-bottom": "2rem"}) - event.Hotkey("ctrl+s", sync(), bindInputs=True, overrideDefault=True) - with w.dashboard(): - w.file_explorer() - w.editor() +# Remove deleted tabs +for tab_name in list(fe_board.editor.tabs.keys()): + if tab_name not in fe_board.file_explorer.tabs: + fe_board.editor.remove_tab(tab_name) + +with elements("file_manager"): + with mui.Paper(elevation=3, style={"padding": "2rem"}, spacing=[2, 2], container=True): + with fe_board.dashboard(): + fe_board.file_explorer() + fe_board.editor()