Skip to content

Commit fbd1e35

Browse files
committed
alignment with pro
1 parent e40546c commit fbd1e35

File tree

3 files changed

+46
-63
lines changed

3 files changed

+46
-63
lines changed
Lines changed: 27 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<template>
22
<!-- SpecialUrlAddToTabsetComponent -->
3-
<template v-if="handler.actions(currentTabsetId).length == 0 && handler.defaultAction()">
3+
<template v-if="handler.actions(currentTabsetId).length == 0 && defaultAction">
44
<q-btn
55
outline
6-
@click.stop="emits('buttonClicked', new ActionHandlerButtonClickedHolder(handler, handler.defaultAction()))"
6+
@click.stop="emits('buttonClicked', new ActionHandlerButtonClickedHolder(handler, defaultAction))"
77
class="q-ma-none q-px-sm q-py-none"
8-
:class="{ shakeWithColor: animateAddtabButton, 'cursor-pointer': !alreadyInTabset() }"
9-
:color="alreadyInTabset() ? 'grey-5' : tsBadges.length > 0 ? 'positive' : ''"
8+
:class="{ shakeWithColor: animateAddtabButton, 'cursor-pointer': !alreadyInTabset }"
9+
:color="alreadyInTabset ? 'grey-5' : containedInTsCount > 0 ? 'positive' : ''"
1010
:size="props.level === 'root' ? 'sm' : 'xs'"
1111
data-testid="saveInTabsetBtn">
12-
<div>{{ handler.defaultAction()!.label }}</div>
12+
<div>{{ defaultAction.label }}</div>
1313
<!-- <q-icon right class="q-ma-none q-pa-none" size="2em" name="o_south" />-->
1414
</q-btn>
15-
<q-tooltip class="tooltip-small" v-if="alreadyInTabset()">
15+
<q-tooltip class="tooltip-small" v-if="alreadyInTabset">
1616
Tab is already contained in tabset '{{ props.tabset?.name }}'...
1717
</q-tooltip>
18-
<q-tooltip class="tooltip-small" v-else-if="tsBadges.length > 0">
18+
<q-tooltip class="tooltip-small" v-else-if="containedInTsCount > 0">
1919
{{ tooltipAlreadyInOtherTabsets(props.tabset!.name) }}
2020
</q-tooltip>
2121
<q-tooltip class="tooltip-small" v-else>
@@ -24,30 +24,30 @@
2424
</template>
2525

2626
<!-- SpecialUrlAddToTabsetComponent handlerDefaultAction -->
27-
<template v-else-if="handler.actions(currentTabsetId).length > 0 && handler.defaultAction()">
27+
<template v-else-if="handler.actions(currentTabsetId).length > 0 && defaultAction">
2828
<!-- :disable="!handler.actions()[0]!.active(props.currentChromeTab)"-->
2929
<q-btn-dropdown
3030
style="border-radius: 5px"
31-
:class="{ shakeWithColor: animateAddtabButton, 'cursor-pointer': !alreadyInTabset() }"
32-
:color="alreadyInTabset() ? 'primary' : tsBadges.length > 0 ? 'positive' : ''"
31+
:class="{ shakeWithColor: animateAddtabButton, 'cursor-pointer': !alreadyInTabset }"
32+
:color="defaultAction!.colorFkt()"
3333
data-testid="saveInTabsetBtn"
3434
v-close-popup
3535
@click.stop="
3636
emits(
3737
'buttonClicked',
38-
new ActionHandlerButtonClickedHolder(handler, handler.defaultAction(), {
39-
filename: handler.defaultAction()!.label,
38+
new ActionHandlerButtonClickedHolder(handler, defaultAction, {
39+
filename: defaultAction.label,
4040
}),
4141
)
4242
"
4343
class="q-ma-none q-px-none q-py-none"
4444
:size="props.level === 'root' ? 'sm' : 'xs'"
45-
:dense="handler.defaultAction()!.label.length > 15"
45+
:dense="defaultAction!.label.length > 15"
4646
split
4747
outline>
4848
<template v-slot:label>
49-
<span v-if="alreadyInTabset()" style="color: #bfbfbf">{{ handler.defaultAction()!.label }}</span>
50-
<span v-else>{{ handler.defaultAction()!.label }}</span>
49+
<span v-if="alreadyInTabset" style="color: #bfbfbf">{{ defaultAction!.label }}</span>
50+
<span v-else>{{ defaultAction!.label }}</span>
5151
</template>
5252
<q-list dense style="min-width: 200px">
5353
<template v-for="l in handler.actions(currentTabsetId)">
@@ -69,7 +69,7 @@
6969
<q-tooltip
7070
class="tooltip-small"
7171
:delay="1000"
72-
v-if="!alreadyInTabset() && tsBadges.length > 0"
72+
v-if="!alreadyInTabset && containedInTsCount > 0"
7373
anchor="center left"
7474
self="center right"
7575
:offset="[10, 10]">
@@ -80,11 +80,11 @@
8080
</template>
8181

8282
<script lang="ts" setup>
83-
import _ from 'lodash'
8483
import { useQuasar } from 'quasar'
8584
import { useActionHandlers } from 'src/tabsets/actionHandling/ActionHandlers'
8685
import { AddUrlToTabsetHandler } from 'src/tabsets/actionHandling/AddUrlToTabsetHandler'
8786
import { NoopAddUrlToTabsetHandler } from 'src/tabsets/actionHandling/handler/NoopAddUrlToTabsetHandler'
87+
import { ActionContext } from 'src/tabsets/actionHandling/model/ActionContext'
8888
import { ActionHandlerButtonClickedHolder } from 'src/tabsets/actionHandling/model/ActionHandlerButtonClickedHolder'
8989
import { useTabsetService } from 'src/tabsets/services/TabsetService2'
9090
import { useTabsetsStore } from 'src/tabsets/stores/tabsetsStore'
@@ -106,39 +106,33 @@ const $q = useQuasar()
106106
const { getHandler } = useActionHandlers($q)
107107
108108
const handler = ref<AddUrlToTabsetHandler>(new NoopAddUrlToTabsetHandler())
109-
const tsBadges = ref<object[]>([])
109+
const defaultAction = ref<ActionContext | undefined>(undefined)
110+
const containedInTsCount = ref(0)
110111
const animateAddtabButton = ref(false)
111112
const currentTabsetId = ref<string | undefined>(undefined)
113+
const alreadyInTabset = ref(false)
112114
113115
watchEffect(async () => {
114116
currentTabsetId.value = await useTabsetsStore().getCurrentTabsetId()
115117
})
116118
117119
watchEffect(async () => {
118120
handler.value = getHandler(props.currentChromeTab.url, props.folder)
121+
defaultAction.value = handler.value.defaultAction()
119122
// const currentTabsetId = await useTabsetsStore().getCurrentTabsetId()
120-
// console.log('===>', JSON.stringify(handler.value.actions(currentTabsetId)), props.folder)
121123
})
122124
123125
watchEffect(() => {
124-
const tabsetIds = useTabsetService().tabsetsFor(props.currentChromeTab.url!)
125-
tsBadges.value = []
126-
_.forEach(tabsetIds, (tsId: string) => {
127-
tsBadges.value.push({
128-
label: useTabsetService().nameForTabsetId(tsId),
129-
tabsetId: tsId,
130-
encodedUrl: btoa(props.currentChromeTab.url || ''),
131-
})
132-
})
126+
containedInTsCount.value = useTabsetService().tabsetsFor(props.currentChromeTab.url!).length
133127
})
134128
135129
watchEffect(() => {
136130
animateAddtabButton.value = useUiStore().animateAddtabButton
137131
})
138132
139-
const alreadyInTabset = () => {
140-
return useTabsetService().urlExistsInCurrentTabset(props.currentChromeTab.url)
141-
}
133+
watchEffect(() => {
134+
alreadyInTabset.value = useTabsetService().urlExistsInCurrentTabset(props.currentChromeTab.url)
135+
})
142136
143137
const activeFolderNameFor = (ts: Tabset, activeFolder: string) => {
144138
const folder = useTabsetsStore().getActiveFolder(ts, activeFolder)
@@ -149,34 +143,6 @@ const tabsetNameOrChain = (tabset: Tabset) => {
149143
return tabset.folderActive ? activeFolderNameFor(tabset, tabset.folderActive) : tabset.name
150144
}
151145
152-
const tooltipAlreadyInOtherTabsets = (tabsetName: string) => {
153-
const tabsetList = _.join(
154-
_.map(tsBadges.value, (b: any) => b['label'] as keyof object),
155-
', ',
156-
)
157-
return (
158-
'The current Tab is already contained in ' +
159-
tsBadges.value.length +
160-
' other Tabsets: ' +
161-
tabsetList +
162-
'. Click to add ' +
163-
"it to '" +
164-
tabsetName +
165-
"' as well."
166-
)
167-
}
168-
169-
// const isActive = (ac: ActionContext) => {
170-
// return ac.active ? ac.active(props.currentChromeTab) : true
171-
// }
172-
//
173-
// const color = (ac: ActionContext | MenuContext) => {
174-
// if ((ac as ActionContext | MenuContext).active) {
175-
// // return (ac as (ActionContext | MenuContext))!.active(props.currentChromeTab) ? 'primary' : 'grey-5'
176-
// return 'primary'
177-
// }
178-
// return alreadyInTabset() ? 'grey-5' : tsBadges.value.length > 0 ? 'positive' : 'primary'
179-
// }
180-
181-
//const getFolder = () => useTabsetsStore().getActiveFolder(props.tabset)
146+
const tooltipAlreadyInOtherTabsets = (tabsetName: string) =>
147+
`The current Tab is already contained in ${containedInTsCount.value} other tabsets. Click to add to ${tabsetName} as well.`
182148
</script>

actionHandling/handler/DefaultAddUrlToTabsetHandler.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Tab } from 'src/tabsets/models/Tab'
1313
import { Tabset } from 'src/tabsets/models/Tabset'
1414
import { useTabsetService } from 'src/tabsets/services/TabsetService2'
1515
import { useTabsetsStore } from 'src/tabsets/stores/tabsetsStore'
16+
import { useAuthStore } from 'stores/authStore'
1617
import { Component } from 'vue'
1718

1819
export class DefaultAddUrlToTabsetHandler implements AddUrlToTabsetHandler {
@@ -27,7 +28,23 @@ export class DefaultAddUrlToTabsetHandler implements AddUrlToTabsetHandler {
2728
}
2829

2930
defaultAction(): ActionContext {
30-
return new ActionContext('Add Tab').onClicked(this.clicked)
31+
const limitReached = useAuthStore().limitExceeded('TABS', useTabsetsStore().allTabsCount).exceeded
32+
return new ActionContext('Add Tab')
33+
.setColor(() => {
34+
const tabUrl = useContentStore().getCurrentTabUrl
35+
if (tabUrl) {
36+
if (limitReached) {
37+
return 'negative'
38+
}
39+
const tabsetsCount = useTabsetService().tabsetsFor(tabUrl).length
40+
if (useTabsetService().urlExistsInCurrentTabset(tabUrl)) {
41+
return 'primary'
42+
}
43+
return tabsetsCount > 0 ? 'positive' : ''
44+
}
45+
return 'black'
46+
})
47+
.onClicked(this.clicked)
3148
}
3249

3350
actions(currentTabsetId: string | undefined): Component[] {

actionHandling/model/ActionContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class ActionContext {
1010

1111
public ok?: (payload: any) => ClickedHandler
1212

13-
public colorFkt?: () => string
13+
public colorFkt: () => string = () => ''
1414

1515
$q?: QVueGlobals
1616

0 commit comments

Comments
 (0)