Skip to content

Commit

Permalink
Enhance App.js with notebook reference and improved Spark app ID hand…
Browse files Browse the repository at this point in the history
…ling

- Added useRef for notebook reference to facilitate direct interaction with the Notebook component.
- Updated Spark app ID handling to ensure it is set correctly when an active Spark application is detected.
- Minor refactoring for improved clarity and maintainability of the code.
  • Loading branch information
xuwenyihust committed Dec 10, 2024
1 parent 1ae461f commit 965c75d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import LoginForm from './components/auth/LoginForm';
import Sidebar from './components/sidebar/Sidebar';
import Notebook from './components/notebook/Notebook';
Expand Down Expand Up @@ -60,6 +60,8 @@ const App = () => {
const [workspaceFiles, setWorkspaceFiles] = useState([]);
const [refreshKey, setRefreshKey] = useState(0);

const notebookRef = useRef(null);

// Auth
useEffect(() => {
const storedUsername = localStorage.getItem('username');
Expand Down Expand Up @@ -147,8 +149,8 @@ const App = () => {
setNotebook(notebookData);

// Update Spark badge if there's an active Spark app
if (sparkApp) {
setSparkAppId(sparkApp.spark_app_id);
if (sparkApp && sparkApp.spark_app_id) {
notebookRef.current?.setSparkAppId(sparkApp.spark_app_id);
}

setShowHistoryServer(false);
Expand Down Expand Up @@ -224,6 +226,7 @@ const App = () => {
username={username}
useremail={useremail}/>
<Notebook
ref={notebookRef}
showNotebook={showNotebook}
notebook={notebook}
notebookState={notebookState}
Expand Down

0 comments on commit 965c75d

Please sign in to comment.