Skip to content

Commit

Permalink
feat(panel): improve fav word process
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Aug 26, 2018
1 parent 47f8f1b commit b632a28
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/components/WordPage/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ export class WordPageMain extends React.Component<WordPageMainInnerProps, WordPa
console.warn(err)
}
}

const wordText = searchURL.searchParams.get('text')
if (wordText) {
const text = decodeURIComponent(wordText)
this.fetchData({
...this.lastFetchDataConfig,
filters: {
word: [text]
},
})
this.setState({ searchText: text })
}
}

renderEdit = (_, record: Word): React.ReactNode => {
Expand Down
17 changes: 15 additions & 2 deletions src/content/redux/modules/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export function isInNotebook (info: SelectionInfo): DispatcherThunk {

export function openWordEditor (): DispatcherThunk {
return (dispatch, getState) => {
const { config, dictionaries } = getState()
const { config, dictionaries, widget } = getState()
if (config.editOnFav) {
if (isSaladictPopupPage) {
// Not enough space to open word editor on popup page
Expand All @@ -492,7 +492,20 @@ export function openWordEditor (): DispatcherThunk {
dispatch(wordEditorShouldShow(true))
}
} else {
dispatch(addToNotebook(dictionaries.searchHistory[0]))
if (widget.isFav) {
try {
message.send<MsgOpenUrl>({
type: MsgType.OpenURL,
url: 'notebook.html?text=' +
encodeURIComponent(dictionaries.searchHistory[0].text),
self: true,
})
} catch (err) {
console.warn(err)
}
} else {
dispatch(addToNotebook(dictionaries.searchHistory[0]))
}
}
}
}
Expand Down

0 comments on commit b632a28

Please sign in to comment.