This repository has been archived by the owner on Apr 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* issue #78 Add suggestion search bar * issue #77 Encode download API url disabling `/file/` API * update dependencies
- Loading branch information
Lunik
authored
Nov 5, 2017
1 parent
44232b0
commit f677bbe
Showing
9 changed files
with
3,239 additions
and
2,994 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react' | ||
|
||
export default class Datalist extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
|
||
this.state = { | ||
items: [] | ||
} | ||
|
||
this.initState(props) | ||
} | ||
|
||
initState (props) { | ||
Object.assign(this.state, { | ||
items: props.items | ||
}) | ||
} | ||
|
||
componentWillReceiveProps (props) { | ||
this.initState(props) | ||
} | ||
|
||
render () { | ||
let items = this.state.items.map((item) => ( | ||
<option key={item} value={item}/> | ||
)) | ||
return ( | ||
<datalist id={this.props.id}> | ||
{items} | ||
</datalist> | ||
) | ||
} | ||
} |
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,63 @@ | ||
import React from 'react' | ||
|
||
import Datalist from './index' | ||
|
||
export default class SuggestionInput extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
|
||
this.storageID = '__SearchSuggestions' | ||
this.state = { | ||
items: [] | ||
} | ||
|
||
this.initState(props) | ||
} | ||
|
||
initState (props) { | ||
Object.assign(this.state, {}) | ||
this.load() | ||
} | ||
|
||
componentWillReceiveProps (props) { | ||
this.initState(props) | ||
} | ||
|
||
addItem (item) { | ||
if (this.state.items.indexOf(item) === -1) { | ||
let temp = this.state.items | ||
temp.push(item) | ||
|
||
this.setState({ | ||
items: temp | ||
}) | ||
|
||
this.save() | ||
} | ||
} | ||
|
||
save () { | ||
window.localStorage.setItem(this.storageID, JSON.stringify(this.state.items)) | ||
} | ||
|
||
load () { | ||
try { | ||
let stored = JSON.parse(window.localStorage.getItem(this.storageID)) | ||
|
||
if (!stored) { | ||
throw new Error('LocalStorage empty') | ||
} | ||
|
||
this.state.items = JSON.parse(window.localStorage.getItem(this.storageID)) | ||
} catch (e) { | ||
this.state.items = [] | ||
this.save() | ||
} | ||
} | ||
|
||
render () { | ||
return ( | ||
<Datalist id={this.props.id} items={this.state.items}/> | ||
) | ||
} | ||
} |
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