-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using Realm in renderer process with existing UI
- Loading branch information
Showing
12 changed files
with
617 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,62 @@ | ||
import * as electron from 'electron' | ||
import * as React from 'react' | ||
import * as ReactDOM from 'react-dom' | ||
import Browser from './ui/browser/browser' | ||
|
||
// FIXME: see https://github.com/realm/realm-js/issues/818 | ||
var userDataPath = electron.remote.app.getPath("userData"); | ||
process.chdir(userDataPath); | ||
import * as Realm from 'realm' | ||
|
||
// We might want to keep a strong referencce to realm when using sync | ||
var realmRef: Realm | ||
|
||
ReactDOM.render( | ||
<div> | ||
Hi there | ||
</div>, | ||
document.getElementById("app") | ||
); | ||
electron.ipcRenderer.on("open-file", (event: Event, args: { path: string }) => { | ||
const configuration: Realm.Configuration = { | ||
path: args.path | ||
}; | ||
|
||
openWithConfiguration(configuration); | ||
}); | ||
|
||
electron.ipcRenderer.on("open-url", (event: Event, args: { url: string, username: string, password: string }) => { | ||
const authURL = args.url; | ||
|
||
Realm.Sync.User.login(authURL, args.username, args.password, (error: any, user: Realm.Sync.User) => { | ||
if (user) { | ||
const configuration: Realm.Configuration = { | ||
sync: { | ||
user: user, | ||
url: args.url, | ||
validate_ssl: false | ||
} | ||
}; | ||
|
||
openWithConfiguration(configuration); | ||
} else { | ||
// TODO: display errors properly | ||
alert(error); | ||
} | ||
}); | ||
}); | ||
|
||
function openWithConfiguration(configuration: Realm.Configuration) { | ||
// TODOL this shouldn't happen so we may consider to throw an exception instead | ||
if (realmRef) { | ||
realmRef.close(); | ||
} | ||
|
||
Realm.openAsync(configuration, (error: any, realm: Realm) => { | ||
realmRef = realm; | ||
|
||
if (realm) { | ||
ReactDOM.render( | ||
<Browser realm={realm} />, | ||
document.getElementById("app") | ||
); | ||
} else { | ||
// TODO: display errors properly | ||
alert(error); | ||
} | ||
}); | ||
} |
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,51 @@ | ||
import * as React from 'react'; | ||
import * as Realm from 'realm'; | ||
import Sidebar from './sidebar/sidebar'; | ||
import Content from './content/content'; | ||
|
||
interface IBrowserProps { | ||
realm: Realm | ||
} | ||
|
||
interface IBrowserState { | ||
selectedIndex: number; | ||
} | ||
|
||
export default class Browser extends React.Component<IBrowserProps, IBrowserState> { | ||
private types: Realm.ObjectSchema[]; | ||
|
||
constructor(props: IBrowserProps) { | ||
super(props); | ||
|
||
this.state = { | ||
selectedIndex: 0 | ||
}; | ||
} | ||
|
||
sidebarSelectionChanged(index: number) { | ||
this.setState({ | ||
selectedIndex: index | ||
}); | ||
} | ||
|
||
render () { | ||
const selectedIndex = this.state.selectedIndex; | ||
const selectedType = this.props.realm.schema[selectedIndex]; | ||
|
||
return ( | ||
<div className="RealmBrowser"> | ||
<div className="RealmBrowser__container"> | ||
<Sidebar | ||
realm={this.props.realm} | ||
selectedIndex={selectedIndex} | ||
onSelectionChange={this.sidebarSelectionChanged.bind(this)} | ||
/> | ||
<Content | ||
realm={this.props.realm} | ||
type={selectedType} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
Oops, something went wrong.