Skip to content

Commit 7c03da0

Browse files
committed
wip
1 parent 10d5bd8 commit 7c03da0

File tree

8 files changed

+78
-30
lines changed

8 files changed

+78
-30
lines changed

actionHandling/handler/RssFolderHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class RssFolderHandler implements AddUrlToTabsetHandler {
9191
newTab.description = desc
9292
newTab.image = img
9393
newTab.extension = UrlExtension.RSS
94-
newTab.tags = item.categories.map((c: FeedCategory) => c.term)
94+
newTab.setTags(item.categories.map((c: FeedCategory) => c.term))
9595
if (published) {
9696
newTab.created = new Date(published).getTime()
9797
}

commands/AddTabToTabsetCommand.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import _ from 'lodash'
22
import { uid } from 'quasar'
33
import AppEventDispatcher from 'src/app/AppEventDispatcher'
4-
import BrowserApi from 'src/app/BrowserApi'
54
import { FeatureIdent } from 'src/app/models/FeatureIdent'
65
import { TabReference, TabReferenceType } from 'src/content/models/TabReference'
76
import { useContentStore } from 'src/content/stores/contentStore'
@@ -146,11 +145,6 @@ export class AddTabToTabsetCommand implements Command<any> {
146145
res = new ExecutionResult(res2, 'Link was added')
147146
}
148147

149-
// add indicator icon
150-
if (this.tab.chromeTabId && this.tab.url) {
151-
BrowserApi.addIndicatorIcon(this.tab.chromeTabId, this.tab.url)
152-
}
153-
154148
// add to search index via App Dispatcher
155149
AppEventDispatcher.dispatchEvent('add-to-search', {
156150
name: this.tab.name || '',

commands/OpenTabCommand.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useNavigationService } from 'src/core/services/NavigationService'
44
import { useActionHandlers } from 'src/tabsets/actionHandling/ActionHandlers'
55
import { AddUrlToTabsetHandler } from 'src/tabsets/actionHandling/AddUrlToTabsetHandler'
66
import { Tab } from 'src/tabsets/models/Tab'
7+
import { useTabsetsStore } from 'src/tabsets/stores/tabsetsStore'
78
import { ref } from 'vue'
89

910
export class OpenTabCommand implements Command<string> {
@@ -18,6 +19,15 @@ export class OpenTabCommand implements Command<string> {
1819
handler.value.handleOpenedTab(browserTab, this.tab)
1920
//useContentStore().currentTabId = this.tab.id
2021
await chrome.tabs.highlight({ tabs: browserTab.index })
22+
if (this.tab.httpInfo && this.tab.httpInfo === 'UPDATED' && this.tab.url) {
23+
this.tab.httpInfo = ''
24+
if (useTabsetsStore().getCurrentTabset) {
25+
await useTabsetsStore().saveTabset(useTabsetsStore().getCurrentTabset!)
26+
}
27+
}
28+
if (this.tab.httpStatus === 0) {
29+
this.tab.httpStatus = 200 // ok "for now"
30+
}
2131
return Promise.resolve(new ExecutionResult('', 'opened'))
2232
} catch (err: any) {
2333
return Promise.reject(err)

commands/SelectTabsetCommand.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class SelectTabsetCommand implements Command<Tabset | undefined> {
2424
if (tabset && this.folderId) {
2525
tabset.folderActive = this.folderId
2626
await useTabsetsStore().saveTabset(tabset)
27+
useTabsetsUiStore().updateExtensionIcon()
2728
}
2829

2930
if (inBexMode()) {

dialogues/StartSessionDialog.vue

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div>
44
<q-card class="q-dialog-plugin" style="max-width: 100%">
55
<q-card-section>
6-
<div class="text-h6">Start new Session...</div>
6+
<div class="text-h6">Sessions</div>
77
</q-card-section>
88
<q-card-section>
99
<div class="text-body">You can save and hide your current tabs and start a new session.</div>
@@ -16,15 +16,14 @@
1616
</q-card-section>
1717
<q-card-section>
1818
<div>
19-
<q-input class="q-ml-md" v-model="sessionName" label="Start new Collection" />
19+
<q-select class="q-ml-md" v-model="collection" :options="collections" label="Open Collection" />
2020
</div>
2121
</q-card-section>
2222
<q-card-actions align="right">
2323
<DialogButton label="Cancel" color="accent" v-close-popup />
2424
<DialogButton
2525
label="Start"
2626
type="submit"
27-
:disable="sessionName.length === 0"
2827
:autofocus="true"
2928
@keyup.enter="display()"
3029
@wasClicked="display()"
@@ -39,14 +38,18 @@
3938
import { useDialogPluginComponent } from 'quasar'
4039
import { STRIP_CHARS_IN_USER_INPUT } from 'src/boot/constants'
4140
import DialogButton from 'src/core/dialog/buttons/DialogButton.vue'
42-
import { ref, watchEffect } from 'vue'
41+
import { Tabset } from 'src/tabsets/models/Tabset'
42+
import { useTabsetsStore } from 'src/tabsets/stores/tabsetsStore'
43+
import { onMounted, ref, watchEffect } from 'vue'
4344
4445
defineEmits([...useDialogPluginComponent.emits])
4546
4647
const { dialogRef, onDialogHide, onDialogOK } = useDialogPluginComponent()
4748
4849
const oldSessionName = ref<string>(new Date().toLocaleDateString() + ' ' + new Date().toLocaleTimeString())
4950
const sessionName = ref<string>('')
51+
const collection = ref(null)
52+
const collections = ref<object[]>([])
5053
5154
watchEffect(() => {
5255
if (sessionName.value) {
@@ -57,7 +60,16 @@ watchEffect(() => {
5760
}
5861
})
5962
63+
onMounted(() => {
64+
collections.value = [...useTabsetsStore().tabsets.values()].map((ts: Tabset) => {
65+
return {
66+
label: ts.name,
67+
value: ts.id,
68+
}
69+
})
70+
})
71+
6072
const display = () => {
61-
onDialogOK({ sessionName: sessionName.value, oldSessionName: oldSessionName.value })
73+
onDialogOK({ sessionName: sessionName.value, oldSessionName: oldSessionName.value, collection: collection.value })
6274
}
6375
</script>

models/Tab.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import _ from 'lodash'
21
import { uid } from 'quasar'
32
import { STRIP_CHARS_IN_USER_INPUT } from 'src/boot/constants'
43
import { TabReference, TabReferenceType } from 'src/content/models/TabReference'
@@ -210,12 +209,7 @@ export class Tab {
210209

211210
this.preview = TabPreview.FAVICON
212211

213-
this.tags = _.uniq(
214-
_.filter(
215-
_.map(this.tags, (t: string) => t.replace(STRIP_CHARS_IN_USER_INPUT, '')),
216-
(e: string) => e.trim() !== '',
217-
),
218-
)
212+
this.tags = []
219213

220214
if (!Tab.titleIsValid) {
221215
throw new Error(`Tab's title '${this.title}' is not valid`)
@@ -267,6 +261,14 @@ export class Tab {
267261
hasTabReference(type: TabReferenceType): boolean {
268262
return this.tabReferences.findIndex((ref: TabReference) => ref.type === type) >= 0
269263
}
264+
265+
setTags(tags: string[]) {
266+
this.tags = [...new Set(tags.map((tag: string) => tag.trim()))]
267+
}
268+
269+
addTags(tags: string[]) {
270+
this.setTags(this.tags.concat(tags))
271+
}
270272
}
271273

272274
Tab.prototype.toString = function tabToString() {

services/TabsetService2.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function useTabsetService() {
7777
const tabs: Tab[] = _.filter(
7878
_.map(chromeTabs, (t: chrome.tabs.Tab) => {
7979
const tab = new Tab(uid(), t)
80-
tab.tags.push(name)
80+
tab.addTags([name])
8181
return tab
8282
}),
8383
(t: Tab) => {
@@ -360,14 +360,15 @@ export function useTabsetService() {
360360
if (!t.tags) {
361361
t.tags = []
362362
}
363-
t.tags = t.tags.concat(
364-
_.union(
365-
_.filter(
366-
_.map(splits, (split: any) => split.trim()),
367-
(split: string) => split.length > 0,
368-
),
369-
),
370-
)
363+
t.addTags(splits)
364+
// t.tags = t.tags.concat(
365+
// _.union(
366+
// _.filter(
367+
// _.map(splits, (split: any) => split.trim()),
368+
// (split: string) => split.length > 0,
369+
// ),
370+
// ),
371+
// )
371372
}
372373
}
373374
const author = getIfAvailable(metas, 'author')
@@ -457,9 +458,9 @@ export function useTabsetService() {
457458
}
458459

459460
// add tabset's name to tab's tags
460-
tab.tags.push(ts.name)
461+
tab.addTags([ts.name])
461462
try {
462-
tab.tags.push(new URL(tab.url).hostname.replace('www.', ''))
463+
tab.addTags([new URL(tab.url).hostname.replace('www.', '')])
463464
} catch (err) {
464465
// ignore
465466
}

stores/tabsetsUiStore.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TabAndTabsetId } from 'src/tabsets/models/TabAndTabsetId'
55
import { Tabset, TabsetStatus } from 'src/tabsets/models/Tabset'
66
import { LocalStorageTabsetsPersistence } from 'src/tabsets/persistence/LocalStorageTabsetsPersistence'
77
import { useTabsetsStore } from 'src/tabsets/stores/tabsetsStore'
8+
import { useTabsStore2 } from 'src/tabsets/stores/tabsStore2'
89
import { ref } from 'vue'
910

1011
export const useTabsetsUiStore = defineStore('tabsetsUi', () => {
@@ -79,6 +80,32 @@ export const useTabsetsUiStore = defineStore('tabsetsUi', () => {
7980
lastUsedTabsets.value = _.union(lastUsedTabsets.value, favorites.value)
8081
}
8182

83+
function updateExtensionIcon() {
84+
const currentBrowserTab = useTabsStore2().currentChromeTab
85+
const currentUrl = currentBrowserTab?.url
86+
if (currentUrl) {
87+
console.log('updating extension icon', currentUrl)
88+
chrome.action.setBadgeText({ text: '' })
89+
chrome.action.setTitle({ title: 'Tabsets' })
90+
setMatchingTabsFor(currentUrl)
91+
if (matchingTabs.value.length > 0) {
92+
chrome.action.setBadgeText({ text: '' + matchingTabs.value.length })
93+
chrome.action.setBadgeBackgroundColor({ color: 'orange' })
94+
chrome.action.setTitle({ title: `The current tab is contained in ${matchingTabs.value.length} tabsets` })
95+
if (
96+
matchingTabs.value
97+
.map((ts: TabAndTabsetId) => ts.tabsetId)
98+
.indexOf(useTabsetsStore().currentTabsetId || '') >= 0
99+
) {
100+
chrome.action.setBadgeBackgroundColor({ color: 'green' })
101+
chrome.action.setTitle({
102+
title: `The current tab is contained in ${matchingTabs.value.length} tabsets, including the current one (${useTabsetsStore().currentTabsetName}).`,
103+
})
104+
}
105+
}
106+
}
107+
}
108+
82109
return {
83110
initialize,
84111
setMatchingTabsFor,
@@ -88,5 +115,6 @@ export const useTabsetsUiStore = defineStore('tabsetsUi', () => {
88115
lastUpdate,
89116
clearFromLastUsedTabsets,
90117
load,
118+
updateExtensionIcon,
91119
}
92120
})

0 commit comments

Comments
 (0)