-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Updated DB sync screen on new windows
- Loading branch information
1 parent
6f55ac3
commit 9bcee1e
Showing
7 changed files
with
109 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as log from 'electron-log'; | ||
import React, { useState, useEffect } from 'react'; | ||
import { useIPCValue } from 'coulomb/ipc/renderer'; | ||
import { BackendDescription } from 'coulomb/db/base'; | ||
import { ipcRenderer } from 'electron'; | ||
|
||
|
||
export type SingleDBStatusContextProps = { | ||
dbName: string | ||
}; | ||
export const SingleDBStatusContext = React.createContext<null | BackendDescription<any>>({ | ||
verboseName: '', | ||
status: {}, | ||
}); | ||
const DBStatusContextProvider: React.FC<SingleDBStatusContextProps> = function (props) { | ||
const ipcPrefix = `db-${props.dbName}`; | ||
const [backendStatus, updateBackendStatus] = useState(undefined as undefined | object); | ||
const description = useIPCValue(`${ipcPrefix}-describe`, null as null | BackendDescription<any>); | ||
|
||
console.debug("STATUS", backendStatus); | ||
console.debug("DESCRIPTION", description.value); | ||
|
||
// Listen to status updates | ||
function handleNewStatus(evt: any, newStatus: any) { | ||
log.debug("Received new status for DB", props.dbName, newStatus); | ||
updateBackendStatus(newStatus); | ||
} | ||
|
||
useEffect(() => { | ||
ipcRenderer.on(`${ipcPrefix}-status`, handleNewStatus); | ||
return function cleanup() { | ||
ipcRenderer.removeListener(`${ipcPrefix}-status`, handleNewStatus); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<SingleDBStatusContext.Provider | ||
value={description.value !== null | ||
? { ...description.value, status: backendStatus || description.value.status } | ||
: null}> | ||
{props.children} | ||
</SingleDBStatusContext.Provider> | ||
); | ||
}; | ||
|
||
export default DBStatusContextProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters