Skip to content

Commit

Permalink
feat(CalendarList): remove ordering modal and add hidden to end of list
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory Vodyanov <[email protected]>
  • Loading branch information
GVodyanov committed Dec 5, 2024
1 parent 9bf06c7 commit 06552b7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 185 deletions.
150 changes: 97 additions & 53 deletions src/components/AppNavigation/CalendarList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

<template>
<div class="calendar-list-wrapper">
<button @click="showOrderModal = !showOrderModal">
Show modal
</button>
<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 @@ -23,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 @@ -36,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 @@ -55,10 +70,16 @@
</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 @@ -72,21 +93,17 @@
<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>

<NcModal :show.sync="showOrderModal" @close="showOrderModal = false">
<CalendarOrderModal :passed-calendars="calendars" />
</NcModal>
</div>
</template>

<script>
import { NcAppNavigationCaption, NcAppNavigationItem, NcAppNavigationSpacer, NcModal } from '@nextcloud/vue'
import { NcAppNavigationCaption, NcAppNavigationItem, NcAppNavigationSpacer } from '@nextcloud/vue'
import CalendarListItem from './CalendarList/CalendarListItem.vue'
import CalendarListNew from './CalendarList/CalendarListNew.vue'
import CalendarOrderModal from './CalendarList/CalendarOrderModal.vue'
import PublicCalendarListItem from './CalendarList/PublicCalendarListItem.vue'
import CalendarListItemLoadingPlaceholder from './CalendarList/CalendarListItemLoadingPlaceholder.vue'
import CalendarMinus from 'vue-material-design-icons/CalendarMinus.vue'
import draggable from 'vuedraggable'
import debounce from 'debounce'
import { showError } from '@nextcloud/dialogs'
import pLimit from 'p-limit'
Expand All @@ -100,14 +117,13 @@ export default {
components: {
CalendarListItem,
CalendarListNew,
CalendarOrderModal,
CalendarListItemLoadingPlaceholder,
PublicCalendarListItem,
NcModal,
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 @@ -122,6 +138,15 @@ export default {
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,
}
Expand All @@ -131,13 +156,33 @@ export default {
...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 @@ -146,42 +191,41 @@ export default {

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 @@ -191,7 +235,7 @@ export default {
} 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>
132 changes: 0 additions & 132 deletions src/components/AppNavigation/CalendarList/CalendarOrderModal.vue

This file was deleted.

0 comments on commit 06552b7

Please sign in to comment.