Skip to content

Commit

Permalink
feat(webui): better handling of library deletion
Browse files Browse the repository at this point in the history
depending on the current screen, data can be reloaded or redirection to home page
  • Loading branch information
gotson committed Jun 26, 2020
1 parent 37d790d commit 0297210
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 41 deletions.
8 changes: 1 addition & 7 deletions komga-webui/src/components/CollectionActionsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,5 @@ export default Vue.extend({
})
</script>
<style scoped>
.list-warning:hover {
background: #F44336;
}
.list-warning:hover .v-list-item__title {
color: white;
}
@import "../styles/list-warning.css";
</style>
27 changes: 25 additions & 2 deletions komga-webui/src/components/Dialogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@
:collection="deleteCollection"
@deleted="collectionDeleted"
/>

<library-delete-dialog
v-model="deleteLibraryDialog"
:library="deleteLibrary"
@deleted="libraryDeleted"
/>
</div>
</template>

<script lang="ts">
import CollectionAddToDialog from '@/components/CollectionAddToDialog.vue'
import CollectionDeleteDialog from '@/components/CollectionDeleteDialog.vue'
import { COLLECTION_CHANGED, SERIES_CHANGED } from '@/types/events'
import LibraryDeleteDialog from '@/components/LibraryDeleteDialog.vue'
import { COLLECTION_CHANGED, LIBRARY_DELETED, SERIES_CHANGED } from '@/types/events'
import Vue from 'vue'
export default Vue.extend({
name: 'Dialogs',
components: { CollectionAddToDialog, CollectionDeleteDialog },
components: { CollectionAddToDialog, CollectionDeleteDialog, LibraryDeleteDialog },
computed: {
addToCollectionDialog: {
get (): boolean {
Expand All @@ -46,6 +53,17 @@ export default Vue.extend({
deleteCollection (): CollectionDto {
return this.$store.state.deleteCollection
},
deleteLibraryDialog: {
get (): boolean {
return this.$store.state.deleteLibraryDialog
},
set (val) {
this.$store.dispatch('dialogDeleteLibraryDisplay', val)
},
},
deleteLibrary (): LibraryDto {
return this.$store.state.deleteLibrary
},
},
methods: {
collectionAdded () {
Expand All @@ -67,6 +85,11 @@ export default Vue.extend({
collectionDeleted () {
this.$eventHub.$emit(COLLECTION_CHANGED)
},
libraryDeleted () {
this.$eventHub.$emit(LIBRARY_DELETED, {
id: this.deleteLibrary.id,
} as EventLibraryDeleted)
},
},
})
</script>
Expand Down
25 changes: 2 additions & 23 deletions komga-webui/src/components/LibraryActionsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,13 @@
</v-list-item>
</v-list>
</v-menu>

<library-delete-dialog v-model="modalDeleteLibrary"
:library="library"
@deleted="navigateHome"
/>
</div>
</template>
<script lang="ts">
import LibraryDeleteDialog from '@/components/LibraryDeleteDialog.vue'
import Vue from 'vue'
export default Vue.extend({
name: 'LibraryActionsMenu',
components: { LibraryDeleteDialog },
data: function () {
return {
modalDeleteLibrary: false,
}
},
props: {
library: {
type: Object as () => LibraryDto,
Expand All @@ -63,20 +51,11 @@ export default Vue.extend({
this.$komgaLibraries.refreshMetadata(this.library)
},
promptDeleteLibrary () {
this.modalDeleteLibrary = true
},
navigateHome () {
this.$router.push({ name: 'home' })
this.$store.dispatch('dialogDeleteLibrary', this.library)
},
},
})
</script>
<style scoped>
.list-warning:hover {
background: #F44336;
}
.list-warning:hover .v-list-item__title {
color: white;
}
@import "../styles/list-warning.css";
</style>
15 changes: 15 additions & 0 deletions komga-webui/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default new Vuex.Store({
addToCollectionDialog: false,
deleteCollection: {} as CollectionDto,
deleteCollectionDialog: false,
deleteLibrary: {} as LibraryDto,
deleteLibraryDialog: false,
},
mutations: {
setAddToCollectionSeries (state, series) {
Expand All @@ -23,6 +25,12 @@ export default new Vuex.Store({
setDeleteCollectionDialog (state, dialog) {
state.deleteCollectionDialog = dialog
},
setDeleteLibrary (state, library) {
state.deleteLibrary = library
},
setDeleteLibraryDialog (state, dialog) {
state.deleteLibraryDialog = dialog
},
},
actions: {
dialogAddSeriesToCollection ({ commit }, series) {
Expand All @@ -39,5 +47,12 @@ export default new Vuex.Store({
dialogDeleteCollectionDisplay ({ commit }, value) {
commit('setDeleteCollectionDialog', value)
},
dialogDeleteLibrary ({ commit }, library) {
commit('setDeleteLibrary', library)
commit('setDeleteLibraryDialog', true)
},
dialogDeleteLibraryDisplay ({ commit }, value) {
commit('setDeleteLibraryDialog', value)
},
},
})
7 changes: 7 additions & 0 deletions komga-webui/src/styles/list-warning.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.list-warning:hover {
background: #F44336;
}

.list-warning:hover .v-list-item__title {
color: white;
}
4 changes: 4 additions & 0 deletions komga-webui/src/types/events-payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ interface EventSeriesChanged {
id: number,
libraryId: number
}

interface EventLibraryDeleted {
id: number
}
1 change: 1 addition & 0 deletions komga-webui/src/types/events.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const BOOK_CHANGED = 'book-changed'
export const SERIES_CHANGED = 'series-changed'
export const COLLECTION_CHANGED = 'collection-changed'
export const LIBRARY_DELETED = 'library-deleted'
1 change: 1 addition & 0 deletions komga-webui/src/types/komga-books.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface BookDto {
id: number,
seriesId: number,
libraryId: number,
name: string,
url: string,
number: number,
Expand Down
9 changes: 8 additions & 1 deletion komga-webui/src/views/BrowseBook.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ import { getReadProgress, getReadProgressPercentage } from '@/functions/book-pro
import { getBookTitleCompact } from '@/functions/book-title'
import { bookFileUrl, bookThumbnailUrl } from '@/functions/urls'
import { ReadStatus } from '@/types/enum-books'
import { BOOK_CHANGED } from '@/types/events'
import { BOOK_CHANGED, LIBRARY_DELETED } from '@/types/events'
import Vue from 'vue'
export default Vue.extend({
Expand All @@ -173,9 +173,11 @@ export default Vue.extend({
async created () {
this.loadBook(this.bookId)
this.$eventHub.$on(BOOK_CHANGED, this.reloadBook)
this.$eventHub.$on(LIBRARY_DELETED, this.libraryDeleted)
},
beforeDestroy () {
this.$eventHub.$off(BOOK_CHANGED, this.reloadBook)
this.$eventHub.$off(LIBRARY_DELETED, this.libraryDeleted)
},
watch: {
async book (val) {
Expand Down Expand Up @@ -234,6 +236,11 @@ export default Vue.extend({
},
},
methods: {
libraryDeleted (event: EventLibraryDeleted) {
if (event.id === this.book.libraryId) {
this.$router.push({ name: 'home' })
}
},
reloadBook (event: EventBookChanged) {
if (event.id === this.bookId) this.loadBook(this.bookId)
},
Expand Down
11 changes: 10 additions & 1 deletion komga-webui/src/views/BrowseLibraries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ import ToolbarSticky from '@/components/ToolbarSticky.vue'
import { parseQueryFilter, parseQuerySort } from '@/functions/query-params'
import { ReadStatus } from '@/types/enum-books'
import { SeriesStatus } from '@/types/enum-series'
import { COLLECTION_CHANGED, SERIES_CHANGED } from '@/types/events'
import { COLLECTION_CHANGED, LIBRARY_DELETED, SERIES_CHANGED } from '@/types/events'
import Vue from 'vue'
const cookiePageSize = 'pagesize'
Expand Down Expand Up @@ -210,10 +210,12 @@ export default Vue.extend({
created () {
this.$eventHub.$on(COLLECTION_CHANGED, this.reloadCollections)
this.$eventHub.$on(SERIES_CHANGED, this.reloadSeries)
this.$eventHub.$on(LIBRARY_DELETED, this.libraryDeleted)
},
beforeDestroy () {
this.$eventHub.$off(COLLECTION_CHANGED, this.reloadCollections)
this.$eventHub.$off(SERIES_CHANGED, this.reloadSeries)
this.$eventHub.$off(LIBRARY_DELETED, this.libraryDeleted)
},
mounted () {
if (this.$cookies.isKey(cookiePageSize)) {
Expand Down Expand Up @@ -271,6 +273,13 @@ export default Vue.extend({
},
},
methods: {
libraryDeleted (event: EventLibraryDeleted) {
if (event.id === this.libraryId) {
this.$router.push({ name: 'home' })
} else if (this.libraryId === 0) {
this.loadLibrary(this.libraryId)
}
},
setWatches () {
this.sortUnwatch = this.$watch('sortActive', this.updateRouteAndReload)
this.filterUnwatch = this.$watch('filters', this.updateRouteAndReload)
Expand Down
11 changes: 9 additions & 2 deletions komga-webui/src/views/BrowseSeries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ import ToolbarSticky from '@/components/ToolbarSticky.vue'
import { parseQueryFilter, parseQuerySort } from '@/functions/query-params'
import { seriesThumbnailUrl } from '@/functions/urls'
import { ReadStatus } from '@/types/enum-books'
import { BOOK_CHANGED, SERIES_CHANGED } from '@/types/events'
import { BOOK_CHANGED, LIBRARY_DELETED, SERIES_CHANGED } from '@/types/events'
import Vue from 'vue'
const cookiePageSize = 'pagesize'
Expand Down Expand Up @@ -319,10 +319,12 @@ export default Vue.extend({
created () {
this.$eventHub.$on(SERIES_CHANGED, this.reloadSeries)
this.$eventHub.$on(BOOK_CHANGED, this.reloadBooks)
this.$eventHub.$on(LIBRARY_DELETED, this.libraryDeleted)
},
beforeDestroy () {
this.$eventHub.$off(SERIES_CHANGED, this.reloadSeries)
this.$eventHub.$on(BOOK_CHANGED, this.reloadBooks)
this.$eventHub.$off(BOOK_CHANGED, this.reloadBooks)
this.$eventHub.$off(LIBRARY_DELETED, this.libraryDeleted)
},
mounted () {
if (this.$cookies.isKey(cookiePageSize)) {
Expand Down Expand Up @@ -391,6 +393,11 @@ export default Vue.extend({
this.setWatches()
},
libraryDeleted (event: EventLibraryDeleted) {
if (event.id === this.series.libraryId) {
this.$router.push({ name: 'home' })
}
},
reloadSeries (event: EventSeriesChanged) {
if (event.id === this.seriesId) this.loadSeries(this.seriesId)
},
Expand Down
20 changes: 15 additions & 5 deletions komga-webui/src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import EmptyState from '@/components/EmptyState.vue'
import HorizontalScroller from '@/components/HorizontalScroller.vue'
import ItemCard from '@/components/ItemCard.vue'
import { ReadStatus } from '@/types/enum-books'
import { LIBRARY_DELETED } from '@/types/events'
import Vue from 'vue'
export default Vue.extend({
Expand All @@ -107,12 +108,14 @@ export default Vue.extend({
dialogEditBookSingle: false,
}
},
created () {
this.$eventHub.$on(LIBRARY_DELETED, this.loadAll)
},
beforeDestroy () {
this.$eventHub.$off(LIBRARY_DELETED, this.loadAll)
},
mounted () {
this.loadNewSeries()
this.loadUpdatedSeries()
this.loadLatestBooks()
this.loadInProgressBooks()
this.loadOnDeckBooks()
this.loadAll()
},
watch: {
editSeriesSingle (val: SeriesDto) {
Expand Down Expand Up @@ -150,6 +153,13 @@ export default Vue.extend({
},
},
methods: {
loadAll () {
this.loadNewSeries()
this.loadUpdatedSeries()
this.loadLatestBooks()
this.loadInProgressBooks()
this.loadOnDeckBooks()
},
async loadNewSeries () {
this.newSeries = (await this.$komgaSeries.getNewSeries()).content
},
Expand Down

0 comments on commit 0297210

Please sign in to comment.