Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Store search history in state
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Oct 5, 2022
1 parent 36cd098 commit 85d91c7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
4 changes: 0 additions & 4 deletions interface/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ const defaultSettings: LibSettings = {
codesLayout: 0,
},

searchHistory: {
latest: null,
},

searchFilter: {
name: true,
description: false,
Expand Down
1 change: 1 addition & 0 deletions interface/stores/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const defaultState: LibState = {
authenticated: false,
importData: null,
updateAvailable: false,
searchHistory: "",
}

export const state = writable<LibState>(sessionStorage.state ? JSON.parse(sessionStorage.state) : defaultState)
Expand Down
5 changes: 1 addition & 4 deletions interface/utils/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare global {
authenticated: boolean
importData: null | string
updateAvailable: boolean
searchHistory: string
}

interface LibSearchQuery {
Expand Down Expand Up @@ -61,10 +62,6 @@ declare global {
codesLayout: number
}

searchHistory: {
latest: string
}

searchFilter: {
name: boolean
description: boolean
Expand Down
6 changes: 3 additions & 3 deletions interface/windows/codes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ export const generateCodeElements = (data: LibImportFile) => {
}, 500)

// latest search from history
const latestSearch = settings.searchHistory.latest
const latestSearch = state.searchHistory

if (latestSearch !== null && latestSearch.trim() !== "") {
const searchBar: HTMLInputElement = document.querySelector(".search")
searchBar.value = settings.searchHistory.latest
searchBar.value = state.searchHistory

search()
}
Expand Down Expand Up @@ -255,7 +255,7 @@ export const search = () => {
document.querySelector(".searchResult").textContent = input
} else {
// save results
settings.searchHistory.latest = input
state.searchHistory = input
setSettings(settings)
}
}
Expand Down

0 comments on commit 85d91c7

Please sign in to comment.