Skip to content

Commit

Permalink
Merge chrome-extension into edge-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Apr 2, 2024
2 parents d5f4649 + e6e14a8 commit 4c5447c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 114 deletions.
138 changes: 35 additions & 103 deletions src/components/layouts/SidePanelPageTabList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,28 @@

<!-- supporting drag & drop when not on mobile -->
<template v-if="!props.preventDragAndDrop"
v-for="column in getColumns()">

<!-- drag & drop and columns -->
<q-expansion-item v-if="showTabsetWithColumns()"
header-class="q-ma-none q-pa-none q-pl-sm q-pr-md bg-grey-1 text-blue-grey-10"
:default-opened="isOpen(column)"
@update:model-value="(val:boolean) => columnChanged(column, val)"
:label="column.title || column.id"
switch-toggle-side
expand-icon-toggle
dense-toggle>

<template v-slot:header>
<q-item-section
class="q-mt-xs">
<q-item-label class="text-blue-grey-8">
{{ column.title }}
</q-item-label>
<q-item-label class="text-caption text-grey-5">
{{ tabsForColumn(column).length }} of {{ props.tabsCount }} tab{{ props.tabsCount === 1 ? '' : 's' }}
</q-item-label>
</q-item-section>
</template>

<vue-draggable-next
class="q-ma-none"
:list="tabsForColumn(column) as Array<IndexedTab>"
:group="{ name: 'tabs', pull: 'clone' }"
@change="(event:any) => handleDragAndDrop(event, column)">

<SidePanelTabListHelper v-for="tab in tabsForColumn(column)"
:tab="tab.tab as Tab"
:index="tab.index"
:type="props.type"
:sorting="props.sorting"
:preventDragAndDrop="false"
:tabset="props.tabset"
:show-tabsets="props.showTabsets"
:hide-menu="props.hideMenu"/>
</vue-draggable-next>
</q-expansion-item>

<!-- drag & drop, but no columns -->
<template v-else>

<vue-draggable-next
class="q-ma-none"
:list="tabsForColumn(column) as Array<IndexedTab>"
:group="{ name: 'tabs', pull: 'clone' }"
@change="(event:any) => handleDragAndDrop(event, column)">

<SidePanelTabListHelper v-for="tab in tabsForColumn(column) as Array<IndexedTab>"
:tab="tab.tab as Tab"
:indent="props.indent"
:index="tab.index"
:type="props.type"
:sorting="props.sorting"
:preventDragAndDrop="false"
:tabset="props.tabset"
:show-tabsets="props.showTabsets"
:hide-menu="props.hideMenu"/>
</vue-draggable-next>
</template>
v-for="column in getColumns()"> <!-- there's only one (default) column now -->

<vue-draggable-next
class="q-ma-none"
:list="tabsForColumn() as Array<IndexedTab>"
:group="{ name: 'tabs', pull: 'clone' }"
@change="(event:any) => handleDragAndDrop(event, column)">

<SidePanelTabListHelper v-for="tab in tabsForColumn() as Array<IndexedTab>"
:tab="tab.tab as Tab"
:indent="props.indent"
:index="tab.index"
:type="props.type"
:sorting="props.sorting"
:preventDragAndDrop="false"
:tabset="props.tabset"
:show-tabsets="props.showTabsets"
:hide-menu="props.hideMenu"/>
</vue-draggable-next>
</template>

<!-- no drag & drop on mobile -->
<!-- TODO columns -->
<template v-else>
<SidePanelTabListHelper
v-for="tab in tabs"
Expand Down Expand Up @@ -121,15 +76,15 @@ const handleDragAndDrop = (event: any, column: TabsetColumn) => {
console.log("event!", event)
if (moved) {
console.log(`moved event: '${moved.element.tab.id}' ${moved.oldIndex} -> ${moved.newIndex}`)
const tabsInColumn = tabsForColumn(column)
const tabsInColumn = tabsForColumn()
const movedElement: Tab = tabsInColumn[moved.oldIndex].tab
const realNewIndex = tabsInColumn[moved.newIndex].index
console.log(` '${movedElement.id}' ${moved.oldIndex} -> ${realNewIndex}`)
TabsetService.moveTo(movedElement.id, realNewIndex, column)
}
if (added) {
console.log(`added event: '${added.element.tab.id}' ${added.oldIndex} -> ${added.newIndex}, ${column.title || column.id}`)
const tabsInColumn = tabsForColumn(column)
const tabsInColumn = tabsForColumn()
const movedElement: Tab = added.element.tab
const realNewIndex = added.newIndex < tabsInColumn.length ?
tabsInColumn[added.newIndex].index : 0
Expand All @@ -156,46 +111,23 @@ watchEffect(() => {
* props.tabset.columns can be []
*/
const getColumns = () => {
if (!props.tabset || !props.tabset.columns || props.tabset.columns.length === 0) {
return [new TabsetColumn(SPECIAL_ID_FOR_NO_GROUP_ASSIGNED, '')]
}
const columnsFromTabs = _.uniq(_.map(props.tabset.tabs, t => t.columnId ? t.columnId : "undefined"))
console.log("columnsFromTabs", columnsFromTabs)
if (columnsFromTabs.length === 1 && columnsFromTabs[0] === "undefined") {
return [new TabsetColumn(SPECIAL_ID_FOR_NO_GROUP_ASSIGNED, props.tabset.columns[0].title ? props.tabset.columns[0].title : 'tabs w/o group')]
}
if (columnsFromTabs.length > props.tabset.columns.length) {
return props.tabset.columns.concat([new TabsetColumn(SPECIAL_ID_FOR_NO_GROUP_ASSIGNED, 'tabs w/o group')])
}
return props.tabset.columns
}
const tabsForColumn = (column: TabsetColumn): IndexedTab[] => {
const tfc = _.filter(
_.map(tabs.value as Tab[], (t: Tab, index: number) => new IndexedTab(index, t)), (it: IndexedTab) => {
if (column.id === SPECIAL_ID_FOR_NO_GROUP_ASSIGNED) {
return it.tab.columnId === SPECIAL_ID_FOR_NO_GROUP_ASSIGNED || !it.tab.columnId
}
return it.tab.columnId === column.id
})
return tfc
//if (!props.tabset || !props.tabset.columns || props.tabset.columns.length === 0) {
return [new TabsetColumn(SPECIAL_ID_FOR_NO_GROUP_ASSIGNED, '')]
//}
// const columnsFromTabs = _.uniq(_.map(props.tabset.tabs, t => t.columnId ? t.columnId : "undefined"))
// console.log("columnsFromTabs", columnsFromTabs)
// if (columnsFromTabs.length === 1 && columnsFromTabs[0] === "undefined") {
// return [new TabsetColumn(SPECIAL_ID_FOR_NO_GROUP_ASSIGNED, props.tabset.columns[0].title ? props.tabset.columns[0].title : 'tabs w/o group')]
// }
// if (columnsFromTabs.length > props.tabset.columns.length) {
// return props.tabset.columns.concat([new TabsetColumn(SPECIAL_ID_FOR_NO_GROUP_ASSIGNED, 'tabs w/o group')])
// }
// return props.tabset.columns
}
const showTabsetWithColumns = () => {
const cols = getColumns()
//console.log("getcolumns", cols)
if (cols.length === 1) {
return cols[0].id !== SPECIAL_ID_FOR_NO_GROUP_ASSIGNED
}
return getColumns().length > 0
}
const columnChanged = (column: TabsetColumn, val: boolean) => {
column.open = val
useTabsetService().saveCurrentTabset()
}
const tabsForColumn = (): IndexedTab[] =>
_.map(tabs.value as Tab[], (t: Tab, index: number) => new IndexedTab(index, t))
const isOpen = (column: TabsetColumn) => column.open
</script>

Expand Down
43 changes: 32 additions & 11 deletions src/services/persistence/FirestorePersistenceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ function spacesCollection() {
return collection(FirebaseServices.getFirestore(), "users", useAuthStore().user.uid, "spaces")
}

function entityDoc(entityId: string) {
return doc(FirebaseServices.getFirestore(), "users", useAuthStore().user.uid, "entities", entityId)
}

function entitiesCollection() {
return collection(FirebaseServices.getFirestore(), "users", useAuthStore().user.uid, "entities")
}

class FirestorePersistenceService implements PersistenceService {

private indexedDB: typeof IndexedDbPersistenceService = null as unknown as typeof IndexedDbPersistenceService
Expand Down Expand Up @@ -101,6 +109,29 @@ class FirestorePersistenceService implements PersistenceService {
await deleteDoc(spaceDoc(entityId))
}

// === Entities ======================================

saveEntity(entity: Entity) {
setDoc(entityDoc(entity.id), JSON.parse(JSON.stringify(entity)))
}

async findEntityById(entityId: string): Promise<Entity> {
const ts = await getDoc(entityDoc(entityId))
return Promise.resolve(ts.data() as Entity)
}

async getEntities(): Promise<Entity[]> {
const entities: Entity[] = []
const fromDb = await getDocs(entitiesCollection())
fromDb.forEach((doc: any) => {
let newItem = doc.data() as Entity
newItem.id = doc.id;
//useSpacesStore().addSpace(newItem)
entities.push(newItem)
})
return Promise.resolve(entities);
}

/**
* === ... ========================================
*/
Expand Down Expand Up @@ -242,7 +273,7 @@ class FirestorePersistenceService implements PersistenceService {
try {
const ts = await getDoc(tabsetDoc(tabsetId))
console.log("reloaded tabset", ts.data())
useTabsStore().tabsets.set(ts.data()['id'], ts.data())
useTabsStore().tabsets.set(ts.data()!['id'], ts.data() as Tabset)
} catch (err) {
console.warn("could not reload tabset with id", tabsetId, err)
}
Expand Down Expand Up @@ -327,16 +358,6 @@ class FirestorePersistenceService implements PersistenceService {
}
}

saveEntity (entity: Entity): void {
}

findEntityById(id: string): Promise<Entity> {
return Promise.resolve(new Entity("0","..."));
}

getEntities(): Promise<Entity[]> {
return Promise.resolve([]);
}
}

export default new FirestorePersistenceService()

0 comments on commit 4c5447c

Please sign in to comment.