Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable5.0] Fix calendar lists not being orderable any more #6556

Open
wants to merge 1 commit into
base: stable5.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 99 additions & 50 deletions src/components/AppNavigation/CalendarList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
-->

<template>
<draggable v-model="calendars"
:disabled="disableDragging"
v-bind="{swapThreshold: 0.30, delay: 500, delayOnTouchOnly: true, touchStartThreshold: 3}"
draggable=".draggable-calendar-list-item"
@update="update">
<div class="calendar-list-wrapper">
<CalendarListNew />
<template v-if="!isPublic">
<CalendarListItem v-for="calendar in sortedCalendars.personal"
:key="calendar.id"
class="draggable-calendar-list-item"
:calendar="calendar" />
<draggable v-model="sortedCalendars.personal"
:disabled="disableDragging"
v-bind="{swapThreshold: 0.30, delay: 500, delayOnTouchOnly: true, touchStartThreshold: 3}"
draggable=".draggable-calendar-list-item"

Check warning on line 13 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L13

Added line #L13 was not covered by tests
@update="updateInput">
<CalendarListItem v-for="calendar in sortedCalendars.personal"
:key="calendar.id"
class="draggable-calendar-list-item"
:calendar="calendar" />
</draggable>
</template>
<template v-else>
<PublicCalendarListItem v-for="calendar in sortedCalendars.personal"
Expand All @@ -24,10 +26,16 @@

<NcAppNavigationCaption v-if="sortedCalendars.shared.length" :name="$t('calendar', 'Shared calendars')" />
<template v-if="!isPublic">
<CalendarListItem v-for="calendar in sortedCalendars.shared"
:key="calendar.id"
class="draggable-calendar-list-item"
:calendar="calendar" />
<draggable v-model="sortedCalendars.shared"
:disabled="disableDragging"
v-bind="{swapThreshold: 0.30, delay: 500, delayOnTouchOnly: true, touchStartThreshold: 3}"
draggable=".draggable-calendar-list-item"
@update="updateInput">
<CalendarListItem v-for="calendar in sortedCalendars.shared"
:key="calendar.id"
class="draggable-calendar-list-item"
:calendar="calendar" />
</draggable>

Check warning on line 38 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L37-L38

Added lines #L37 - L38 were not covered by tests
</template>
<template v-else>
<PublicCalendarListItem v-for="calendar in sortedCalendars.shared"
Expand All @@ -37,10 +45,16 @@

<NcAppNavigationCaption v-if="sortedCalendars.deck.length" :name="$t('calendar', 'Deck')" />
<template v-if="!isPublic">
<CalendarListItem v-for="calendar in sortedCalendars.deck"
:key="calendar.id"
class="draggable-calendar-list-item"
:calendar="calendar" />
<draggable v-model="sortedCalendars.deck"
:disabled="disableDragging"
v-bind="{swapThreshold: 0.30, delay: 500, delayOnTouchOnly: true, touchStartThreshold: 3}"
draggable=".draggable-calendar-list-item"
@update="updateInput">
<CalendarListItem v-for="calendar in sortedCalendars.deck"
:key="calendar.id"
class="draggable-calendar-list-item"
:calendar="calendar" />
</draggable>
</template>
<template v-else>
<PublicCalendarListItem v-for="calendar in sortedCalendars.deck"
Expand All @@ -54,12 +68,18 @@
<template #icon>
<CalendarMinus :size="20" />
</template>
<template>

Check warning on line 71 in src/components/AppNavigation/CalendarList.vue

View workflow job for this annotation

GitHub Actions / NPM lint

`<template>` require directive
<div v-if="!isPublic">
<CalendarListItem v-for="calendar in sortedCalendars.hidden"
:key="calendar.id"
class="draggable-calendar-list-item"
:calendar="calendar" />
<draggable v-model="sortedCalendars.hidden"
:disabled="disableDragging"
v-bind="{swapThreshold: 0.30, delay: 500, delayOnTouchOnly: true, touchStartThreshold: 3}"
draggable=".draggable-calendar-list-item"
@update="updateInput">
<CalendarListItem v-for="calendar in sortedCalendars.hidden"
:key="calendar.id"
class="draggable-calendar-list-item"
:calendar="calendar" />
</draggable>
</div>
<div v-else>
<PublicCalendarListItem v-for="calendar in sortedCalendars.hidden"
Expand All @@ -70,10 +90,10 @@
</NcAppNavigationItem>

<!-- The header slot must be placed here, otherwise vuedraggable adds undefined as item to the array -->
<template #footer>
<template>

Check warning on line 93 in src/components/AppNavigation/CalendarList.vue

View workflow job for this annotation

GitHub Actions / NPM lint

`<template>` require directive
<CalendarListItemLoadingPlaceholder v-if="loadingCalendars" />
</template>
</draggable>
</div>
</template>

<script>
Expand All @@ -99,11 +119,11 @@
CalendarListNew,
CalendarListItemLoadingPlaceholder,
PublicCalendarListItem,
draggable,
NcAppNavigationCaption,
NcAppNavigationItem,
NcAppNavigationSpacer,
CalendarMinus,
draggable,

Check warning on line 126 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L126

Added line #L126 was not covered by tests
},
props: {
isPublic: {
Expand All @@ -118,21 +138,51 @@
data() {
return {
calendars: [],
/**
* Calendars sorted by personal, shared, deck, and hidden
*/

Check warning on line 143 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L141-L143

Added lines #L141 - L143 were not covered by tests
sortedCalendars: {
personal: [],
shared: [],
deck: [],
hidden: [],
},
disableDragging: false,
showOrderModal: false,
}
},
computed: {
...mapStores(useCalendarsStore),
...mapState(useCalendarsStore, {
serverCalendars: 'sortedCalendarsSubscriptions',
}),
/**
* Calendars sorted by personal, shared, deck, and hidden
*
* @return {Map}
*/
sortedCalendars() {
const sortedCalendars = {
loadingKeyCalendars() {
return this._uid + '-loading-placeholder-calendars'
},
},
watch: {

Check warning on line 163 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L162-L163

Added lines #L162 - L163 were not covered by tests
serverCalendars(val) {
this.calendars = val
},
calendars() {
this.sortCalendars()
},
},
mounted() {
this.calendarsStore.$onAction(({ name, args, after }) => {
if (name === 'toggleCalendarEnabled') {
after(() => {
const calendar = this.calendars.find((calendar) => calendar.id === args[0].calendar.id)
calendar.enabled = args[0].calendar.enabled
this.sortCalendars()
this.update()

Check warning on line 178 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L177-L178

Added lines #L177 - L178 were not covered by tests
})
}
})
},
methods: {
sortCalendars() {
this.sortedCalendars = {
personal: [],
shared: [],
deck: [],
Expand All @@ -141,42 +191,41 @@

this.calendars.forEach((calendar) => {
if (!calendar.enabled) {
sortedCalendars.hidden.push(calendar)
this.sortedCalendars.hidden.push(calendar)
return
}

if (calendar.isSharedWithMe) {
sortedCalendars.shared.push(calendar)
this.sortedCalendars.shared.push(calendar)
return
}

if (calendar.url.includes('app-generated--deck--board')) {
sortedCalendars.deck.push(calendar)
this.sortedCalendars.deck.push(calendar)
return
}

sortedCalendars.personal.push(calendar)
this.sortedCalendars.personal.push(calendar)
})

return sortedCalendars
},
loadingKeyCalendars() {
return this._uid + '-loading-placeholder-calendars'
},
},
watch: {
serverCalendars(val) {
this.calendars = val
},
},
methods: {
update: debounce(async function() {
updateInput: debounce(async function() {
await this.update()
}, 2500),
async update() {

Check warning on line 214 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L213-L214

Added lines #L213 - L214 were not covered by tests
this.disableDragging = true
const newOrder = this.calendars.reduce((newOrderObj, currentItem, currentIndex) => {
const currentCalendars = [
...this.sortedCalendars.personal,
...this.sortedCalendars.shared,
...this.sortedCalendars.deck,
...this.sortedCalendars.hidden,
]
const newOrder = currentCalendars.reduce((newOrderObj, currentItem, currentIndex) => {
newOrderObj[currentItem.id] = currentIndex
return newOrderObj
}, {})

this.calendars = currentCalendars

Check warning on line 228 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L228

Added line #L228 was not covered by tests
try {
await limit(() => this.calendarsStore.updateCalendarListOrder({ newOrder }))
} catch (err) {
Expand All @@ -186,7 +235,7 @@
} finally {
this.disableDragging = false
}
}, 2500),
},

Check warning on line 238 in src/components/AppNavigation/CalendarList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/CalendarList.vue#L238

Added line #L238 was not covered by tests
},
}
</script>
Loading