diff --git a/src/api.js b/src/api.js index 3c21718..cae0890 100644 --- a/src/api.js +++ b/src/api.js @@ -42,6 +42,12 @@ function collections() { return http.get("/collections"); } +function createCollection(name) { + return http.post("/collections", { + name, + }); +} + function follow(collection) { return http.post(`/collections/${collection.id}/follow`); } @@ -72,6 +78,7 @@ export default { authenticate, logout, collections, + createCollection, follow, unfollow, addCollectionToLink, diff --git a/src/components/Collections.vue b/src/components/Collections.vue new file mode 100644 index 0000000..6b2c53d --- /dev/null +++ b/src/components/Collections.vue @@ -0,0 +1,294 @@ + + + + + + + + + {{ collection.name }} + + + {{ t('collection.public') }} + + + + removeCollection(collection)" + type="button" + :disabled="form.inProgress() ? 'true' : null" + > + {{ t('collection.remove') }} + + + + + + + + + {{ t('collection.add_to_collection') }} + + + + + + {{ t('collection.new') }} + + + + + + + {{ collection.name }} + + + ({{ t('collection.public') }}) + + + + + + {{ collection.name }} + + + ({{ t('collection.public') }}) + + + + + + + + + + {{ t('collection.name') }} + + + + + {{ t('collection.new_cancel') }} + + + + + + + + + + {{ t('collection.add') }} + + + + + + + + diff --git a/src/components/CollectionsSelector.vue b/src/components/CollectionsSelector.vue deleted file mode 100644 index f55414c..0000000 --- a/src/components/CollectionsSelector.vue +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - - {{ collection.name }} - - - {{ t('collection.public') }} - - - - removeCollection(collection)" - type="button" - :disabled="props.disabled" - > - {{ t('collection.remove') }} - - - - - - - - {{ t('collection.add_to_collection') }} - - - - - {{ collection.name }} - - - ({{ t('collection.public') }}) - - - - - - {{ collection.name }} - - - ({{ t('collection.public') }}) - - - - - - - - - {{ t('collection.add') }} - - - - - - - - diff --git a/src/i18n.js b/src/i18n.js index 22fa8e3..57668bb 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -12,6 +12,9 @@ export const i18n = createI18n({ en: { "collection.add": "Confirm", "collection.add_to_collection": "Add to a collection", + "collection.name": "Collection name", + "collection.new": "New", + "collection.new_cancel": "Cancel", "collection.public": "public", "collection.remove": "Remove", "errors.@base.invalid_credentials": "The credentials are invalid.", @@ -85,6 +88,9 @@ export const i18n = createI18n({ fr: { "collection.add": "Confirmer", "collection.add_to_collection": "Ajouter à une collection", + "collection.name": "Nom de la collection", + "collection.new": "Nouvelle", + "collection.new_cancel": "Annuler", "collection.public": "publique", "collection.remove": "Retirer", "errors.@base.invalid_credentials": "Les identifiants sont incorrects.", diff --git a/src/models/collection.js b/src/models/collection.js new file mode 100644 index 0000000..2e0b5b4 --- /dev/null +++ b/src/models/collection.js @@ -0,0 +1,18 @@ +// This file is part of Flus Browser +// SPDX-License-Identifier: AGPL-3.0-or-later + +export default class { + id = ""; + name = ""; + description = ""; + group = ""; + isPublic = false; + + init(fetchedCollection) { + this.id = fetchedCollection.id; + this.name = fetchedCollection.name; + this.description = fetchedCollection.description; + this.group = fetchedCollection.group; + this.isPublic = fetchedCollection.is_public; + } +} diff --git a/src/models/link.js b/src/models/link.js index 857a1fe..d972329 100644 --- a/src/models/link.js +++ b/src/models/link.js @@ -82,8 +82,16 @@ export default class { } } + hasCollection(collection) { + return this.collections.some((collectionId) => { + return collectionId === collection.id; + }); + } + addCollection(collection) { - this.collections = [...this.collections, collection.id]; + if (!this.hasCollection(collection)) { + this.collections = [...this.collections, collection.id]; + } } removeCollection(collection) { diff --git a/src/screens/LinkScreen.vue b/src/screens/LinkScreen.vue index 467ce74..c792c26 100644 --- a/src/screens/LinkScreen.vue +++ b/src/screens/LinkScreen.vue @@ -48,20 +48,17 @@ {{ t("link.count_collections", link.collections.length) }} - @@ -105,9 +102,8 @@ import browser from "webextension-polyfill"; import { store } from "../store.js"; import api from "../api.js"; import http from "../http.js"; -import collectionsForm from "../form.js"; import Link from "../models/link.js"; -import CollectionsSelector from "../components/CollectionsSelector.vue"; +import Collections from "../components/Collections.vue"; import Notes from "../components/Notes.vue"; const { t, locale } = useI18n(); @@ -200,31 +196,5 @@ async function markAsReadLater() { }); } -function addCollection(collection) { - collectionsForm.startRequest(); - api.addCollectionToLink(link, collection) - .then(() => { - collectionsForm.finishRequest(); - link.addCollection(collection); - }) - .catch(() => { - collectionsForm.finishRequest(); - store.notify("error", t("errors.unknown")); - }); -} - -function removeCollection(collection) { - collectionsForm.startRequest(); - api.removeCollectionFromLink(link, collection) - .then(() => { - collectionsForm.finishRequest(); - link.removeCollection(collection); - }) - .catch(() => { - collectionsForm.finishRequest(); - store.notify("error", t("errors.unknown")); - }); -} - onMounted(refreshForCurrentTab);