Skip to content

Commit

Permalink
fix($searchView): fix some type label don't show
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjun authored and crown committed Jan 10, 2019
1 parent 968694e commit 89bdf03
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 32 deletions.
4 changes: 4 additions & 0 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"message": "RCT",
"description": "Recently closed tabs label in search list"
},
"keyword_label": {
"message": "keyword",
"description": "keyword label in search list"
},
"contentScript_unavailable": {
"message": "You cannot open a popup on this page because of browser restrictions.",
"description": "a tip when content-script is unavailable"
Expand Down
6 changes: 5 additions & 1 deletion public/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "扩展描述"
},
"contentHotKey": {
"message": "open crown extension in your current page",
"message": "在网页中打开 Crown 扩展",
"description": "在网页中唤起 Crown 扩展"
},
"searchPlaceholder": {
Expand Down Expand Up @@ -32,6 +32,10 @@
"message": "最近关闭",
"description": "最近关闭的标签页在搜索列表中的标识"
},
"keyword_label": {
"message": "关键词",
"description": "检索触发关键词在搜索列表中的标识"
},
"contentScript_unavailable": {
"message": "因为浏览器的限制, 您无法在改页面唤醒 Crown 扩展",
"description": "content-script 不可用时的提示语"
Expand Down
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async function queryRecentLyClosed(queryQueue: string[]) {
isEachEligible(queryQueue, `${item.tab.url} ${item.tab.title}`)
) {
temp.push({
type: 'closedTab',
type: 'RCT',
title: item.tab.title,
subtitle: item.tab.url,
id: item.tab.sessionId as string,
Expand Down
2 changes: 1 addition & 1 deletion src/background/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const defaultConfig: ExtensionConfig = {
keyword: 't',
desc: 'Tabs',
},
recentlyClosedTab: {
RCT: {
isDefault: false,
keyword: 'rct',
desc: 'Recently Closed Tabs',
Expand Down
7 changes: 4 additions & 3 deletions src/background/filter-search-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { queryBM, queryRecentLyClosed, queryTab } from '@/api'
import { isEachEligible } from '@/common/utils'
import { getKeys, isEachEligible } from '@/common/utils'
import store from '@/store'

const extConfig: Readonly<ExtensionConfig> = store.state.config
Expand All @@ -24,7 +24,8 @@ function searchKeyword(splitSearchStr: string[]) {
// Get an array which need to search
function filterKeyword(splitSearchStr: string[]) {
const temp: SingleSearch[] = []
Object.entries(extConfig.itemSet).some(([key, value]) => {
getKeys(extConfig.itemSet).some(key => {
const value = extConfig.itemSet[key]
if (value.keyword === splitSearchStr[0]) {
// Only search for a category
temp.length = 0
Expand Down Expand Up @@ -63,7 +64,7 @@ async function searchFromType(item: SingleSearch) {
case 'tab':
result = await queryTab(item.searchQueue)
break
case 'closedTab':
case 'RCT':
result = await queryRecentLyClosed(item.searchQueue)
break
default:
Expand Down
2 changes: 1 addition & 1 deletion src/background/handle-selected-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function handleSelectedItem(item: QueryResultItem) {
case 'tab':
updateTabStatus(item.id as number)
break
case 'closedTab':
case 'RCT':
restoreRecentTab(item.id as string)
break

Expand Down
5 changes: 4 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ function isEachEligible(arr: any[], tested: string): boolean {
return arr.every(item => new RegExp(`${item}`, 'gi').test(tested))
}

export { encodeXml, isEachEligible }
const getKeys = <T extends {}>(o: T): Array<keyof T> =>
Object.keys(o) as Array<keyof T>

export { encodeXml, isEachEligible, getKeys }
2 changes: 1 addition & 1 deletion src/components/searchView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ export default Vue.extend({
})
</script>

<style lang="stylus">
<style lang="stylus" scoped>
@import '~@/stylus/popup';
</style>
8 changes: 4 additions & 4 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

interface ChangeItemConfigPayload {
type: 'bookmark' | 'tab' | 'recentlyClosedTab'
type: 'bookmark' | 'tab' | 'RCT'
key: 'isDefault' | 'keyword'
value: string | boolean
}

export default new Vuex.Store({
strict: process.env.NODE_ENV !== 'production',
state: {
config: defaultConfig
config: defaultConfig,
},
mutations: {
changeItemConfig(state, payload: ChangeItemConfigPayload) {
state.config.itemSet[payload.type][payload.key] = payload.value
}
},
},
plugins: [ createPersistedState() ]
plugins: [createPersistedState()],
})
32 changes: 17 additions & 15 deletions src/types/crown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,11 @@ interface ItemConfig {
desc: string
}

interface ItemConfigSet {
/** The related settings of bookmark */
bookmark: ItemConfig
/** The related settings of tab */
tab: ItemConfig
/** The related settings of recently closed tab */
recentlyClosedTab: ItemConfig
}

interface ExtensionConfig {
/** Single setting */
itemSet: ItemConfigSet
}

interface SingleSearch {
type: string
searchQueue: string[]
}

interface SingleOmniboxSearch {
content: string
description: string
Expand Down Expand Up @@ -67,9 +53,11 @@ interface CMessage4 extends CMessageBasic {

type CMessage = CMessage1 | CMessage2 | CMessage3 | CMessage4

type CMessageType = 'tab' | 'bookmark' | 'RCT' | 'keyword'

interface QueryResultItem {
/** item of search result's type */
type: 'tab' | 'bookmark' | 'closedTab' | 'keyword'
type: CMessageType
/** item of search result's main text */
title: string | undefined
/** item of search result's sub text */
Expand All @@ -81,3 +69,17 @@ interface QueryResultItem {
/** item keyword */
keyword?: string
}

interface SingleSearch {
type: CMessageType
searchQueue: string[]
}

interface ItemConfigSet {
/** The related settings of bookmark */
bookmark: ItemConfig
/** The related settings of tab */
tab: ItemConfig
/** The related settings of recently closed tab */
RCT: ItemConfig
}
8 changes: 4 additions & 4 deletions src/views/Options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ export default Vue.extend({
},
isRCTDefault: {
get(): boolean {
return this.$store.state.config.itemSet.recentlyClosedTab.isDefault
return this.$store.state.config.itemSet.RCT.isDefault
},
set(value: boolean) {
this.$store.commit('changeItemConfig', {
type: 'recentlyClosedTab',
type: 'RCT',
key: 'isDefault',
value,
})
Expand Down Expand Up @@ -127,11 +127,11 @@ export default Vue.extend({
},
RCTKeyword: {
get(): string {
return this.$store.state.config.itemSet.recentlyClosedTab.keyword
return this.$store.state.config.itemSet.RCT.keyword
},
set(value: string) {
this.$store.commit('changeItemConfig', {
type: 'recentlyClosedTab',
type: 'RCT',
key: 'keyword',
value,
})
Expand Down

0 comments on commit 89bdf03

Please sign in to comment.