| 50 | } |
| 51 | |
| 52 | addItem(item: SearchResultItem | HistoryItem): void { |
| 53 | // We don't want to reset nor update the creation date of favorites |
| 54 | if (this.history().get(item.id)?.isFavorite) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | this.updateHistory((map) => { |
| 59 | map.set(item.id, { |
| 60 | id: item.id, |
| 61 | labelHtml: cleanUpHtml(item.labelHtml), |
| 62 | subLabelHtml: item.subLabelHtml ? cleanUpHtml(item.subLabelHtml) : undefined, |
| 63 | url: item.url, |
| 64 | isFavorite: false, |
| 65 | createdAt: Date.now(), |
| 66 | }); |
| 67 | |
| 68 | // `items` still hasn't been updated so we should use `>=`. |
| 69 | if (this.items().recent.length >= MAX_RECENT_HISTORY_SIZE) { |
| 70 | const {id} = this.items().recent.at(-1)!; |
| 71 | map.delete(id); |
| 72 | } |
| 73 | }); |
| 74 | } |
| 75 | |
| 76 | removeItem(item: SearchResultItem | HistoryItem): void { |
| 77 | this.updateHistory((map) => { |