Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Second API change #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions search/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react'
import Masq from 'masq-lib'
import * as createMasq from 'masq-lib'

import SearchBar from './components/SearchBar'

Expand Down Expand Up @@ -48,17 +48,18 @@ class App extends Component {
}

async componentDidMount () {
this.masq = new Masq(APP.name, APP.description, APP.imageURL)

try {
this.masq = await createMasq(APP.name, APP.description, APP.imageURL)
if (this.masq.isLoggedIn()) {
await this.masq.connectToMasq()
this.setState({ loggedIn: true })
await this.getAllQueriesFromDB()
} else {
const { link } = await this.masq.logIntoMasq(false)
this.setState({ link })
this.setState({ loggedIn: false })
const link = await this.masq.getLoginLink()
this.setState({
link,
loggedIn: false
})
}
} catch (err) {
this.setState({ err })
Expand Down Expand Up @@ -95,7 +96,7 @@ class App extends Component {

this.setState({ loggingIn: true })
try {
await this.masq.logIntoMasqDone()
await this.masq.logIntoMasq(this.state.stayConnected)
this.setState({ loggedIn: true })
await this.getAllQueriesFromDB()
} catch (e) {
Expand All @@ -105,20 +106,21 @@ class App extends Component {
}

async handleClickLogout () {
const { link } = await this.masq.logIntoMasq(this.state.stayConnected)
this.setState({ link })
this.setState({ loggedIn: false, items: [] })
const link = await this.masq.getLoginLink()

this.setState({
link,
loggedIn: false,
items: []
})

await this.masq.signout()
}

async handleStayConnectedChange (event) {
const target = event.target
const stayConnected = target.checked
this.setState({ stayConnected })

// regenerate link
const { link } = await this.masq.logIntoMasq(stayConnected)
this.setState({ link })
}

render () {
Expand Down