Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions components/authentication/AuthenticationForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type Form = {
confirm_password: string
}

const config = useRuntimeConfig();
const rest = useRestApi();
const authModalOpen = useAuthenticationModal();
const settings = useSettings();
Expand Down Expand Up @@ -120,8 +119,8 @@ function login () {
notify({
group: "error",
title: "Error",
text: err.message
}, 4000); // 4s
text: `Login failed. ${err.message}.`
}, 10000);
});
}

Expand All @@ -143,8 +142,8 @@ function signup () {
notify({
group: "error",
title: "Error",
text: err.message
}, 4000); // 4s
text: `Registration failed. ${err.message}.`
}, 10000);
});
}
</script>
Expand Down
8 changes: 8 additions & 0 deletions components/torrent/TorrentActionCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
import { LinkIcon, CalendarIcon, CircleStackIcon, UserCircleIcon, HashtagIcon, TagIcon } from "@heroicons/vue/24/solid";
import { PropType } from "vue";
import { TorrentResponse } from "torrust-index-types-lib";
import { notify } from "notiwind-ts";
import {
fileSize,
downloadTorrent,
Expand Down Expand Up @@ -199,6 +200,13 @@ function deleteTorrent () {
rest.value.torrent.deleteTorrent(props.torrent.info_hash)
.then(() => {
emit("deleted");
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to delete the torrent. ${err.message}.`
}, 10000);
});
}
</script>
10 changes: 8 additions & 2 deletions components/torrent/TorrentListTorrentDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
<script setup lang="ts">
import { Ref } from "vue";
import { TorrentResponse } from "torrust-index-types-lib";
import { useRuntimeConfig } from "#app";
import { notify } from "notiwind-ts";
import { onMounted, ref, useRestApi } from "#imports";

const config = useRuntimeConfig();
const rest = useRestApi();

const torrent: Ref<TorrentResponse> = ref(null);
Expand All @@ -36,6 +35,13 @@ onMounted(() => {
rest.value.torrent.getTorrentInfo(props.infoHash)
.then((data) => {
torrent.value = data;
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to get the torrent information. ${err.message}.`
}, 10000);
});
});
</script>
Expand Down
36 changes: 36 additions & 0 deletions composables/states.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PublicSettings, Category, TokenResponse, TorrentTag } from "torrust-index-types-lib";
import { Rest } from "torrust-index-api-lib";
import { useRuntimeConfig, useState } from "#app";
import { notify } from "notiwind-ts";

export const useRestApi = () => useState<Rest>("rest-api", () => new Rest(useRuntimeConfig().public.apiBase));
export const useCategories = () => useState<Array<Category>>("categories", () => new Array<Category>());
Expand All @@ -13,20 +14,41 @@ export function getSettings () {
useRestApi().value.settings.getPublicSettings()
.then((publicSettings) => {
useSettings().value = publicSettings;
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to get public settings. ${err.message}.`
}, 10000);
});
}

export function getCategories () {
useRestApi().value.category.getCategories()
.then((res) => {
useCategories().value = res;
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to get categories. ${err.message}.`
}, 10000);
});
}

export function getTags () {
useRestApi().value.tag.getTags()
.then((res) => {
useTags().value = res;
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to get tags. ${err.message}.`
}, 10000);
});
}

Expand All @@ -37,6 +59,13 @@ export async function loginUser (login: string, password: string) {
})
.then((user) => {
useUser().value = user;
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to login. ${err.message}.`
}, 10000);
});
}

Expand All @@ -54,5 +83,12 @@ export async function getUser () {
return await useRestApi().value.user.renewToken()
.then((user) => {
useUser().value = user;
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to get user info. ${err.message}.`
}, 10000);
});
}
10 changes: 9 additions & 1 deletion pages/admin/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<script setup lang="ts">
import { Ref } from "vue";
import { Settings } from "torrust-index-types-lib";
import { getSettings, onMounted, ref, useRestApi, useRoute, watch } from "#imports";
import { notify } from "notiwind-ts";
import { onMounted, ref, useRestApi } from "#imports";

const tabs = [
"backend",
Expand All @@ -50,6 +51,13 @@ function getAdminSettings () {
rest.value.settings.getSettings()
.then((v) => {
settings.value = v;
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to get the backend settings. ${err.message}.`
}, 10000);
});
}

Expand Down
21 changes: 18 additions & 3 deletions pages/admin/settings/categories.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div class="mx-auto flex flex-col gap-2 max-w-md">
<div class="flex flex-col max-w-md gap-2 mx-auto">
<div class="flex flex-col gap-2">
<template v-for="category in categories">
<div class="p-2 flex justify-between bg-base-100 rounded">
<div class="flex justify-between p-2 rounded bg-base-100">
<span class="text-base-content">{{ category.name }} ({{ category.num_torrents }})</span>
<button class="text-error-content hover:text-error" @click="deleteCategory(category.name)">
Delete
Expand All @@ -11,7 +11,7 @@
</template>
</div>
<div class="flex gap-2">
<input v-model="newCategory" class="input input-bordered w-full" type="text">
<input v-model="newCategory" class="w-full input input-bordered" type="text">
<button class="btn btn-primary" :class="{ 'loading': addingCategory }" :disabled="addingCategory || !newCategory" @click="addCategory">
Add category
</button>
Expand All @@ -21,6 +21,7 @@

<script setup lang="ts">
import { ref } from "vue";
import { notify } from "notiwind-ts";
import { getCategories, useCategories, useRestApi } from "#imports";

const categories = useCategories();
Expand All @@ -37,6 +38,13 @@ function addCategory () {
.then(() => {
getCategories();
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to add the category. ${err.message}.`
}, 10000);
})
.finally(() => {
addingCategory.value = false;
});
Expand All @@ -48,6 +56,13 @@ function deleteCategory (category: string) {
rest.category.deleteCategory(category)
.then(() => {
getCategories();
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to delete the category. ${err.message}.`
}, 10000);
});
}
}
Expand Down
17 changes: 16 additions & 1 deletion pages/admin/settings/tags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
<script setup lang="ts">
import { ref } from "vue";
import { TorrentTag } from "torrust-index-types-lib";
import { computed, getTags, useRestApi, useTags } from "#imports";
import { notify } from "notiwind-ts";
import { getTags, useRestApi, useTags } from "#imports";

const tags = useTags();
const rest = useRestApi().value;
Expand All @@ -38,6 +39,13 @@ function addTag () {
.then(() => {
getTags();
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to add the tag. ${err.message}.`
}, 10000);
})
.finally(() => {
addingTag.value = false;
});
Expand All @@ -49,6 +57,13 @@ function deleteTag (tag: TorrentTag) {
rest.tag.deleteTag(tag.tag_id)
.then(() => {
getTags();
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to delete the tag. ${err.message}.`
}, 10000);
});
}
}
Expand Down
9 changes: 7 additions & 2 deletions pages/torrent/[infoHash].vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ import { ChevronLeftIcon } from "@heroicons/vue/24/solid";
import { Ref } from "vue";
import { TorrentResponse } from "torrust-index-types-lib";
import { useRoute, useRuntimeConfig } from "#app";
import { notify } from "notiwind-ts";
import TorrentActionCard from "~/components/torrent/TorrentActionCard.vue";
import TorrentDescriptionTab from "~/components/torrent/TorrentDescriptionTab.vue";
import TorrentFilesTab from "~/components/torrent/TorrentFilesTab.vue";
import TorrentTrackersTab from "~/components/torrent/TorrentTrackersTab.vue";
import { navigateTo, onMounted, ref, useRestApi } from "#imports";

const config = useRuntimeConfig();
const route = useRoute();
const rest = useRestApi().value;

Expand All @@ -72,8 +72,13 @@ function getTorrentFromApi (infoHash: string) {
.then((data) => {
torrent.value = data;
})
.catch(() => {
.catch((err) => {
loadingTorrent.value = false;
notify({
group: "error",
title: "Error",
text: `Trying to get the torrent information. ${err.message}.`
}, 10000);
});

// TODO: Set torrent title in URL.
Expand Down
13 changes: 11 additions & 2 deletions pages/torrent/edit/[infoHash].vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ function getTorrentFromApi (infoHash: string) {
}
});
})
.catch((err) => {
loadingTorrent.value = false;
notify({
group: "error",
title: "Error",
text: `Trying to get the torrent info. ${err.message}.`
}, 10000);
})
.finally(() => {
loadingTorrent.value = false;
});
Expand Down Expand Up @@ -182,11 +190,12 @@ function submitForm () {
navigateTo(`/torrent/${infoHash}`, { replace: true });
})
.catch((err) => {
loadingTorrent.value = false;
notify({
group: "error",
title: "Error",
text: err.message
}, 4000); // 4s
text: `Trying to update torrent info. ${err.message}.`
}, 10000);
})
.finally(() => {
updatingTorrent.value = false;
Expand Down
9 changes: 8 additions & 1 deletion pages/torrents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import { useRuntimeConfig, useRoute, useRouter } from "nuxt/app";
import { TorrentListing } from "torrust-index-types-lib";
import { Ref } from "vue";
import { notify } from "notiwind-ts";
import { computed, onMounted, ref, useTags, watch } from "#imports";
import { useCategories, useRestApi } from "~/composables/states";
import { TorrustSelectOption } from "~/components/TorrustSelect.vue";
Expand All @@ -77,7 +78,6 @@ const sortingOptions: Array<TorrustSelectOption> = [

const route = useRoute();
const router = useRouter();
const config = useRuntimeConfig();
const categories = useCategories();
const tags = useTags();
const rest = useRestApi();
Expand Down Expand Up @@ -147,6 +147,13 @@ function loadTorrents () {
.then((v) => {
torrentsTotal.value = v.total;
torrents.value = v.results;
})
.catch((err) => {
notify({
group: "error",
title: "Error",
text: `Trying to get the information for the torrents. ${err.message}.`
}, 10000);
});
}
</script>
Expand Down
6 changes: 2 additions & 4 deletions pages/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ import {
onMounted,
ref, toRaw,
useRestApi,
useRuntimeConfig,
useTags,
useUser
} from "#imports";
Expand All @@ -103,7 +102,6 @@ type FormUploadTorrent = {
torrentFile: any;
}

const config = useRuntimeConfig();
const categories = useCategories();
const tags = useTags();
const user = useUser();
Expand Down Expand Up @@ -168,8 +166,8 @@ function submitForm () {
notify({
group: "error",
title: "Error",
text: err
}, 4000);
text: `Trying to upload the torrent. ${err.message}.`
}, 10000);
});
}

Expand Down