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 >
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 )" >
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]" >
8080</template >
8181
8282<script lang="ts" setup>
83- import _ from ' lodash'
8483import { useQuasar } from ' quasar'
8584import { useActionHandlers } from ' src/tabsets/actionHandling/ActionHandlers'
8685import { AddUrlToTabsetHandler } from ' src/tabsets/actionHandling/AddUrlToTabsetHandler'
8786import { NoopAddUrlToTabsetHandler } from ' src/tabsets/actionHandling/handler/NoopAddUrlToTabsetHandler'
87+ import { ActionContext } from ' src/tabsets/actionHandling/model/ActionContext'
8888import { ActionHandlerButtonClickedHolder } from ' src/tabsets/actionHandling/model/ActionHandlerButtonClickedHolder'
8989import { useTabsetService } from ' src/tabsets/services/TabsetService2'
9090import { useTabsetsStore } from ' src/tabsets/stores/tabsetsStore'
@@ -106,39 +106,33 @@ const $q = useQuasar()
106106const { getHandler } = useActionHandlers ($q )
107107
108108const handler = ref <AddUrlToTabsetHandler >(new NoopAddUrlToTabsetHandler ())
109- const tsBadges = ref <object []>([])
109+ const defaultAction = ref <ActionContext | undefined >(undefined )
110+ const containedInTsCount = ref (0 )
110111const animateAddtabButton = ref (false )
111112const currentTabsetId = ref <string | undefined >(undefined )
113+ const alreadyInTabset = ref (false )
112114
113115watchEffect (async () => {
114116 currentTabsetId .value = await useTabsetsStore ().getCurrentTabsetId ()
115117})
116118
117119watchEffect (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
123125watchEffect (() => {
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
135129watchEffect (() => {
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
143137const 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 >
0 commit comments