Upgraded all components to vue 3 & typescript

This commit is contained in:
2022-08-06 16:10:13 +02:00
parent 890d0c428d
commit d12dfc3c8e
34 changed files with 3508 additions and 3554 deletions

View File

@@ -1,28 +1,29 @@
<template> <template>
<div class="cast"> <div class="cast">
<ol class="persons"> <ol class="persons">
<CastListItem v-for="person in cast" :person="person" :key="person.id" /> <CastListItem
v-for="credit in cast"
:creditItem="credit"
:key="credit.id"
/>
</ol> </ol>
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import CastListItem from "src/components/CastListItem"; import { defineProps } from "vue";
import CastListItem from "src/components/CastListItem.vue";
import type { MediaTypes, CreditTypes } from "../interfaces/IList";
export default { interface Props {
name: "CastList", cast: Array<MediaTypes | CreditTypes>;
components: { CastListItem },
props: {
cast: {
type: Array,
required: true
} }
}
}; defineProps<Props>();
</script> </script>
<style lang="scss"> <style lang="scss">
.cast { .cast {
position: relative; position: relative;
top: 0; top: 0;
left: 0; left: 0;
@@ -40,5 +41,5 @@ export default {
display: none; /* for Chrome, Safari, and Opera */ display: none; /* for Chrome, Safari, and Opera */
} }
} }
} }
</style> </style>

View File

@@ -1,68 +1,63 @@
<template> <template>
<li class="card"> <li class="card">
<a @click="openCastItem"> <a @click="openCastItem">
<img class="persons--image" :src="pictureUrl" /> <img :src="pictureUrl" />
<p class="name">{{ person.name || person.title }}</p> <p class="name">{{ creditItem.name || creditItem.title }}</p>
<p class="meta">{{ person.character || person.year }}</p> <p class="meta">{{ creditItem.character || creditItem.year }}</p>
</a> </a>
</li> </li>
</template> </template>
<script> <script setup lang="ts">
import { mapActions } from "vuex"; import { defineProps, computed } from "vue";
import { useStore } from "vuex";
import type { MediaTypes, CreditTypes } from "../interfaces/IList";
export default { interface Props {
name: "CastListItem", creditItem: MediaTypes | CreditTypes;
props: {
person: {
type: Object,
required: true
} }
},
methods: {
...mapActions("popup", ["open"]),
openCastItem() {
let { id, type } = this.person;
if (type) { const props = defineProps<Props>();
this.open({ id, type }); const store = useStore();
const pictureUrl = computed(() => {
const baseUrl = "https://image.tmdb.org/t/p/w185";
if ("profile_path" in props.creditItem && props.creditItem.profile_path) {
return baseUrl + props.creditItem.profile_path;
} else if ("poster" in props.creditItem && props.creditItem.poster) {
return baseUrl + props.creditItem.poster;
} }
}
},
computed: {
pictureUrl() {
const { profile_path, poster_path, poster } = this.person;
if (profile_path) return "https://image.tmdb.org/t/p/w185" + profile_path;
else if (poster_path)
return "https://image.tmdb.org/t/p/w185" + poster_path;
else if (poster) return "https://image.tmdb.org/t/p/w185" + poster;
return "/assets/no-image_small.svg"; return "/assets/no-image_small.svg";
});
function openCastItem() {
store.dispatch("popup/open", { ...props.creditItem });
} }
}
};
</script> </script>
<style lang="scss"> <style lang="scss">
li a p:first-of-type { li a p:first-of-type {
padding-top: 10px; padding-top: 10px;
} }
li.card p { li.card p {
font-size: 1em; font-size: 1em;
padding: 0 10px; padding: 0 10px;
margin: 0; margin: 0;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
max-height: calc(10px + ((16px * var(--line-height)) * 3)); max-height: calc(10px + ((16px * var(--line-height)) * 3));
} }
li.card { li.card {
margin: 10px; margin: 10px;
margin-right: 4px; margin-right: 4px;
padding-bottom: 10px; padding-bottom: 10px;
border-radius: 8px; border-radius: 8px;
overflow: hidden; overflow: hidden;
cursor: pointer;
min-width: 140px; min-width: 140px;
width: 140px; width: 140px;
@@ -117,5 +112,5 @@ li.card {
background-color: var(--background-color); background-color: var(--background-color);
object-fit: cover; object-fit: cover;
} }
} }
</style> </style>

View File

@@ -1,8 +1,6 @@
<template> <template>
<header <header ref="headerElement" :class="{ expanded, noselect: true }">
:class="{ expanded, noselect: true }" <img :src="bannerImage" ref="imageElement" />
v-bind:style="{ 'background-image': 'url(' + imageFile + ')' }"
>
<div class="container"> <div class="container">
<h1 class="title">Request movies or tv shows</h1> <h1 class="title">Request movies or tv shows</h1>
<strong class="subtitle" <strong class="subtitle"
@@ -10,73 +8,127 @@
> >
</div> </div>
<div class="expand-icon" @click="expanded = !expanded"> <div class="expand-icon" @click="expand" @mouseover="upgradeImage">
<IconExpand v-if="!expanded" /> <IconExpand v-if="!expanded" />
<IconShrink v-else /> <IconShrink v-else />
</div> </div>
</header> </header>
</template> </template>
<script> <script setup lang="ts">
import IconExpand from "../icons/IconExpand.vue"; import { ref, computed, onMounted } from "vue";
import IconShrink from "../icons/IconShrink.vue"; import IconExpand from "@/icons/IconExpand.vue";
import IconShrink from "@/icons/IconShrink.vue";
import type { Ref } from "vue";
export default { const ASSET_URL = "https://request.movie/assets/";
components: { IconExpand, IconShrink }, const images: Array<string> = [
props: {
image: {
type: String,
required: false
}
},
data() {
return {
images: [
"pulp-fiction.jpg", "pulp-fiction.jpg",
"arrival.jpg", "arrival.jpg",
"disaster-artist.jpg",
"dune.jpg", "dune.jpg",
"mandalorian.jpg" "mandalorian.jpg"
], ];
imageFile: undefined,
expanded: false const bannerImage: Ref<string> = ref();
}; const expanded: Ref<boolean> = ref(false);
}, const headerElement: Ref<HTMLElement> = ref(null);
beforeMount() { const imageElement: Ref<HTMLImageElement> = ref(null);
if (this.image && this.image.length > 0) { const defaultHeaderHeight: Ref<string> = ref();
this.imageFile = this.image; const disableProxy = true;
} else {
this.imageFile = `/assets/${ bannerImage.value = randomImage();
this.images[Math.floor(Math.random() * this.images.length)]
}`; function expand() {
expanded.value = !expanded.value;
let height = defaultHeaderHeight?.value;
if (expanded.value) {
const aspectRation =
imageElement.value.naturalHeight / imageElement.value.naturalWidth;
height = `${imageElement.value.clientWidth * aspectRation}px`;
defaultHeaderHeight.value = headerElement.value.style.height;
} }
headerElement.value.style.setProperty("--header-height", height);
} }
};
function randomImage(): string {
const image = images[Math.floor(Math.random() * images?.length)];
return ASSET_URL + image;
}
// function sliceToHeaderSize(url: string): string {
// let width = headerElement.value?.getBoundingClientRect()?.width || 1349;
// let height = headerElement.value?.getBoundingClientRect()?.height || 261;
// if (disableProxy) return url;
// return buildProxyURL(width, height, url);
// }
// function upgradeImage() {
// if (disableProxy || imageUpgraded.value == true) return;
// const headerSize = 90;
// const height = window.innerHeight - headerSize;
// const width = window.innerWidth - headerSize;
// const proxyHost = `http://imgproxy.schleppe:8080/insecure/`;
// const proxySizeOptions = `q:65/plain/`;
// bannerImage.value = `${proxyHost}${proxySizeOptions}${
// ASSET_URL + image.value
// }`;
// }
// function buildProxyURL(width: number, height: number, asset: string): string {
// const proxyHost = `http://imgproxy.schleppe:8080/insecure/`;
// const proxySizeOptions = `resize:fill:${width}:${height}:ce/q:65/plain/`;
// return `${proxyHost}${proxySizeOptions}${asset}`;
// }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
header { header {
width: 100%; width: 100%;
height: 25vh;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
background-size: cover;
background-repeat: no-repeat;
background-position: 50% 50%;
position: relative; position: relative;
transition: height 0.5s ease;
&.expanded { overflow: hidden;
height: calc(100vh - var(--header-size)); --header-height: 261px;
width: calc(100vw - var(--header-size));
@include mobile { @include mobile {
width: 100vw; --header-height: 25vh;
height: 100vh;
} }
height: var(--header-height);
> * {
z-index: 1;
}
img {
position: absolute;
z-index: 0;
object-fit: cover;
width: 100%;
}
&.expanded {
// height: calc(100vh - var(--header-size));
// width: calc(100vw - var(--header-size));
// @include mobile {
// width: 100vw;
// height: 100vh;
// }
&:before { &:before {
background-color: transparent; background-color: transparent;
} }
@@ -114,6 +166,7 @@ header {
&:before { &:before {
content: ""; content: "";
z-index: 1;
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
@@ -155,5 +208,5 @@ header {
font-size: 1.3rem; font-size: 1.3rem;
} }
} }
} }
</style> </style>

View File

@@ -1,125 +0,0 @@
<template>
<header>
<h2>{{ prettify }}</h2>
<h3>{{ subtitle }}</h3>
<router-link
v-if="shortList"
:to="urlify"
class="view-more"
:aria-label="`View all ${title}`"
>
View All
</router-link>
<div v-else-if="info">
<div v-if="info instanceof Array" class="flex flex-direction-column">
<span v-for="item in info" :key="item" class="info">{{ item }}</span>
</div>
<span v-else class="info">{{ info }}</span>
</div>
</header>
</template>
<script>
export default {
props: {
title: {
type: String,
required: true
},
subtitle: {
type: String,
required: false,
default: null
},
info: {
type: [String, Array],
required: false
},
link: {
type: String,
required: false
},
shortList: {
type: Boolean,
required: false,
default: false
}
},
computed: {
urlify: function () {
return `/list/${this.title.toLowerCase().replace(" ", "_")}`;
},
prettify: function () {
return this.title.includes("_")
? this.title.split("_").join(" ")
: this.title;
}
}
};
</script>
<style lang="scss" scoped>
@import "src/scss/variables";
@import "src/scss/media-queries";
@import "src/scss/main";
header {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem 0.75rem;
background-color: $background-color;
position: sticky;
position: -webkit-sticky;
top: $header-size;
z-index: 1;
h2 {
font-size: 1.4rem;
font-weight: 300;
text-transform: capitalize;
line-height: 1.4rem;
margin: 0;
color: $text-color;
}
.view-more {
font-size: 0.9rem;
font-weight: 300;
letter-spacing: 0.5px;
color: $text-color-70;
text-decoration: none;
transition: color 0.5s ease;
cursor: pointer;
&:after {
content: " →";
}
&:hover {
color: $text-color;
}
}
.info {
font-size: 13px;
font-weight: 300;
letter-spacing: 0.5px;
color: $text-color;
text-decoration: none;
text-align: right;
}
@include tablet-min {
padding-left: 1.25rem;
}
@include desktop-lg-min {
padding-left: 1.75rem;
}
}
</style>

View File

@@ -0,0 +1,110 @@
<template>
<header>
<h2>{{ prettify }}</h2>
<h3>{{ subtitle }}</h3>
<router-link
v-if="shortList"
:to="urlify"
class="view-more"
:aria-label="`View all ${title}`"
>
View All
</router-link>
<div v-else-if="info">
<div v-if="info instanceof Array" class="flex flex-direction-column">
<span v-for="item in info" :key="item" class="info">{{ item }}</span>
</div>
<span v-else class="info">{{ info }}</span>
</div>
</header>
</template>
<script setup lang="ts">
import { defineProps, computed } from "vue";
interface Props {
title: string;
subtitle?: string;
info?: string | Array<string>;
link?: string;
shortList?: boolean;
}
const props = defineProps<Props>();
const urlify = computed(() => {
return `/list/${props.title.toLowerCase().replace(" ", "_")}`;
});
const prettify = computed(() => {
return props.title.includes("_")
? props.title.split("_").join(" ")
: props.title;
});
</script>
<style lang="scss" scoped>
@import "src/scss/variables";
@import "src/scss/media-queries";
@import "src/scss/main";
header {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem 0.75rem;
background-color: $background-color;
position: sticky;
position: -webkit-sticky;
top: $header-size;
z-index: 1;
h2 {
font-size: 1.4rem;
font-weight: 300;
text-transform: capitalize;
line-height: 1.4rem;
margin: 0;
color: $text-color;
}
.view-more {
font-size: 0.9rem;
font-weight: 300;
letter-spacing: 0.5px;
color: $text-color-70;
text-decoration: none;
transition: color 0.5s ease;
cursor: pointer;
&:after {
content: " →";
}
&:hover {
color: $text-color;
}
}
.info {
font-size: 13px;
font-weight: 300;
letter-spacing: 0.5px;
color: $text-color;
text-decoration: none;
text-align: right;
}
@include tablet-min {
padding-left: 1.25rem;
}
@include desktop-lg-min {
padding-left: 1.75rem;
}
}
</style>

View File

@@ -9,64 +9,84 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import { mapActions, mapGetters } from "vuex"; import { ref, onMounted, onBeforeUnmount } from "vue";
import Movie from "@/components/popup/Movie"; import { useStore } from "vuex";
import Person from "@/components/popup/Person"; import Movie from "@/components/popup/Movie.vue";
import Person from "@/components/popup/Person.vue";
import { ListTypes } from "../interfaces/IList";
import type { MediaTypes } from "../interfaces/IList";
import type { Ref } from "vue";
export default { interface URLQueryParameters {
components: { Movie, Person }, id: number;
computed: { type: ListTypes;
...mapGetters("popup", ["isOpen", "id", "type"]) }
},
watch: { const store = useStore();
isOpen(value) { const isOpen: Ref<boolean> = ref();
value const id: Ref<string> = ref();
const type: Ref<MediaTypes> = ref();
const unsubscribe = store.subscribe((mutation, state) => {
if (!mutation.type.includes("popup")) return;
isOpen.value = state.popup.open;
id.value = state.popup.id;
type.value = state.popup.type;
console.log("popup state:", isOpen.value);
isOpen.value
? document.getElementsByTagName("body")[0].classList.add("no-scroll") ? document.getElementsByTagName("body")[0].classList.add("no-scroll")
: document : document.getElementsByTagName("body")[0].classList.remove("no-scroll");
.getElementsByTagName("body")[0] });
.classList.remove("no-scroll");
} function getFromURLQuery(): URLQueryParameters {
}, let id, type;
methods: {
...mapActions("popup", ["close", "open"]),
checkEventForEscapeKey(event) {
if (event.keyCode == 27) this.close();
}
},
created() {
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
let id = null; params.forEach((value, key) => {
let type = null; if (!(key in ListTypes)) return;
if (params.has("movie")) { id = Number(params.get(key));
id = Number(params.get("movie")); type = key;
type = "movie"; });
} else if (params.has("show")) {
id = Number(params.get("show")); return { id, type };
type = "show";
} else if (params.has("person")) {
id = Number(params.get("person"));
type = "person";
} }
if (id && type) { function open(id: Number, type: string) {
this.open({ id, type }); if (!id || !type) return;
store.dispatch("popup/open", { id, type });
} }
window.addEventListener("keyup", this.checkEventForEscapeKey); function close() {
}, store.dispatch("popup/close");
beforeDestroy() {
window.removeEventListener("keyup", this.checkEventForEscapeKey);
} }
};
function checkEventForEscapeKey(event: KeyboardEvent) {
if (event.keyCode !== 27) return;
close();
}
window.addEventListener("keyup", checkEventForEscapeKey);
onMounted(() => {
const { id, type } = getFromURLQuery();
open(id, type);
});
onBeforeUnmount(() => {
unsubscribe();
window.removeEventListener("keyup", checkEventForEscapeKey);
});
</script> </script>
<style lang="scss"> <style lang="scss">
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.movie-popup { .movie-popup {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
@@ -121,5 +141,5 @@ export default {
background: $green; background: $green;
} }
} }
} }
</style> </style>

View File

@@ -6,9 +6,9 @@
:class="{ shortList: shortList }" :class="{ shortList: shortList }"
> >
<results-list-item <results-list-item
v-for="(movie, index) in results" v-for="(result, index) in results"
:key="`${movie.type}-${movie.id}-${index}`" :key="`${result.type}-${result.id}-${index}`"
:movie="movie" :listItem="result"
/> />
</ul> </ul>
@@ -16,43 +16,33 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import ResultsListItem from "@/components/ResultsListItem"; import { defineProps } from "vue";
import ResultsListItem from "@/components/ResultsListItem.vue";
import type { ListResults } from "../interfaces/IList";
export default { interface Props {
components: { ResultsListItem }, results: Array<ListResults>;
props: { shortList?: Boolean;
results: { loading?: Boolean;
type: Array,
required: true
},
shortList: {
type: Boolean,
required: false,
default: false
},
loading: {
type: Boolean,
required: false,
default: false
} }
}
}; const props = defineProps<Props>();
</script> </script>
<style lang="scss"> <style lang="scss" scoped>
@import "src/scss/media-queries"; @import "src/scss/media-queries";
@import "src/scss/main"; @import "src/scss/main";
.no-results { .no-results {
width: 100%; width: 100%;
display: block; display: block;
text-align: center; text-align: center;
margin: 1.5rem; margin: 1.5rem;
font-size: 1.2rem; font-size: 1.2rem;
} }
.results { .results {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
grid-auto-rows: auto; grid-auto-rows: auto;
@@ -79,5 +69,5 @@ export default {
max-width: calc(100vw - var(--header-size)); max-width: calc(100vw - var(--header-size));
} }
} }
} }
</style> </style>

View File

@@ -1,6 +1,10 @@
<template> <template>
<li class="movie-item" ref="list-item"> <li class="movie-item" ref="list-item">
<figure ref="poster" class="movie-item__poster" @click="openMoviePopup"> <figure
ref="posterElement"
class="movie-item__poster"
@click="openMoviePopup"
>
<img <img
class="movie-item__img" class="movie-item__img"
:alt="posterAltText" :alt="posterAltText"
@@ -8,111 +12,108 @@
src="/assets/placeholder.png" src="/assets/placeholder.png"
/> />
<div v-if="movie.download" class="progress"> <div v-if="listItem.download" class="progress">
<progress :value="movie.download.progress" max="100"></progress> <progress :value="listItem.download.progress" max="100"></progress>
<span>{{ movie.download.state }}: {{ movie.download.progress }}%</span> <span
>{{ listItem.download.state }}:
{{ listItem.download.progress }}%</span
>
</div> </div>
</figure> </figure>
<div class="movie-item__info"> <div class="movie-item__info">
<p v-if="movie.title || movie.name" class="movie-item__title"> <p v-if="listItem.title || listItem.name" class="movie-item__title">
{{ movie.title || movie.name }} {{ listItem.title || listItem.name }}
</p> </p>
<p v-if="movie.year">{{ movie.year }}</p> <p v-if="listItem.year">{{ listItem.year }}</p>
<p v-if="movie.type == 'person'"> <p v-if="listItem.type == 'person'">
Known for: {{ movie.known_for_department }} Known for: {{ listItem.known_for_department }}
</p> </p>
</div> </div>
</li> </li>
</template> </template>
<script> <script setup lang="ts">
import { mapActions } from "vuex"; import { ref, computed, defineProps, onMounted } from "vue";
import img from "../directives/v-image"; import { useStore } from "vuex";
import { buildImageProxyUrl } from "../utils"; import { buildImageProxyUrl } from "../utils";
import type { Ref } from "vue";
import type { MediaTypes } from "../interfaces/IList";
export default { interface Props {
props: { listItem: MediaTypes;
movie: {
type: Object,
required: true
}
},
directives: {
img: img
},
data() {
return {
poster: null,
observed: false
};
},
computed: {
posterAltText: function () {
const type = this.movie.type || "";
const title = this.movie.title || this.movie.name;
return this.movie.poster
? `Poster for ${type} ${title}`
: `Missing image for ${type} ${title}`;
},
imageWidth() {
if (this.image)
return Math.ceil(this.image.getBoundingClientRect().width);
},
imageHeight() {
if (this.image)
return Math.ceil(this.image.getBoundingClientRect().height);
}
},
beforeMount() {
if (this.movie.poster == null) {
this.poster = "/assets/no-image.svg";
return;
} }
this.poster = `https://image.tmdb.org/t/p/w500${this.movie.poster}`; const props = defineProps<Props>();
// this.poster = this.buildProxyURL( const store = useStore();
// this.imageWidth,
// this.imageHeight, const IMAGE_BASE_URL = "https://image.tmdb.org/t/p/w500";
// assetUrl const IMAGE_FALLBACK = "/assets/no-image.svg";
// ); const poster: Ref<string> = ref();
}, const posterElement: Ref<HTMLElement> = ref(null);
mounted() { const observed: Ref<boolean> = ref(false);
const poster = this.$refs["poster"];
this.image = poster.getElementsByTagName("img")[0]; poster.value = props.listItem?.poster
if (this.image == null) return; ? IMAGE_BASE_URL + props.listItem?.poster
: IMAGE_FALLBACK;
onMounted(observePosterAndSetImageSource);
function observePosterAndSetImageSource() {
const imageElement = posterElement.value.getElementsByTagName("img")[0];
if (imageElement == null) return;
const imageObserver = new IntersectionObserver((entries, imgObserver) => { const imageObserver = new IntersectionObserver((entries, imgObserver) => {
entries.forEach(entry => { entries.forEach(entry => {
if (entry.isIntersecting && this.observed == false) { if (entry.isIntersecting && observed.value == false) {
const lazyImage = entry.target; const lazyImage = entry.target as HTMLImageElement;
lazyImage.src = lazyImage.dataset.src; lazyImage.src = lazyImage.dataset.src;
poster.className = poster.className + " is-loaded"; posterElement.value.classList.add("is-loaded");
this.observed = true; observed.value = true;
} }
}); });
}); });
imageObserver.observe(this.image); imageObserver.observe(imageElement);
}, }
methods: {
...mapActions("popup", ["open"]), function openMoviePopup() {
openMoviePopup() { store.dispatch("popup/open", { ...props.listItem });
this.open({ }
id: this.movie.id,
type: this.movie.type const posterAltText = computed(() => {
const type = props.listItem.type || "";
let title: string = "";
if ("name" in props.listItem) title = props.listItem.name;
else if ("title" in props.listItem) title = props.listItem.title;
return props.listItem.poster
? `Poster for ${type} ${title}`
: `Missing image for ${type} ${title}`;
}); });
}
} const imageSize = computed(() => {
}; if (!posterElement.value) return;
const { height, width } = posterElement.value.getBoundingClientRect();
return {
height: Math.ceil(height),
width: Math.ceil(width)
};
});
// import img from "../directives/v-image";
// directives: {
// img: img
// },
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
@import "src/scss/main"; @import "src/scss/main";
.movie-item { .movie-item {
padding: 15px; padding: 15px;
width: 100%; width: 100%;
background-color: var(--background-color); background-color: var(--background-color);
@@ -176,5 +177,5 @@ export default {
&__title { &__title {
font-weight: 400; font-weight: 400;
} }
} }
</style> </style>

View File

@@ -1,6 +1,6 @@
<template> <template>
<div ref="resultSection" class="resultSection"> <div ref="resultSection" class="resultSection">
<list-header v-bind="{ title, info, shortList }" /> <page-header v-bind="{ title, info, shortList }" />
<div <div
v-if="!loadedPages.includes(1) && loading == false" v-if="!loadedPages.includes(1) && loading == false"
@@ -26,84 +26,116 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import ListHeader from "@/components/ListHeader"; import { defineProps, ref, computed, onMounted } from "vue";
import ResultsList from "@/components/ResultsList"; import { useStore } from "vuex";
import SeasonedButton from "@/components/ui/SeasonedButton"; import PageHeader from "@/components/PageHeader.vue";
import store from "@/store"; import ResultsList from "@/components/ResultsList.vue";
import { getTmdbMovieListByName } from "@/api"; import SeasonedButton from "@/components/ui/SeasonedButton.vue";
import Loader from "@/components/ui/Loader"; import Loader from "@/components/ui/Loader.vue";
import { getTmdbMovieListByName } from "../api";
import type { Ref } from "vue";
import type { IList, ListResults } from "../interfaces/IList";
import type ISection from "../interfaces/ISection";
export default { interface Props extends ISection {
props: { title: string;
apiFunction: { apiFunction: (page: number) => Promise<IList>;
type: Function, shortList?: boolean;
required: true
},
title: {
type: String,
required: true
},
shortList: {
type: Boolean,
required: false,
default: false
}
},
components: { ListHeader, ResultsList, SeasonedButton, Loader },
data() {
return {
results: [],
page: 1,
loadedPages: [],
totalPages: -1,
totalResults: 0,
loading: true,
autoLoad: false,
observer: undefined
};
},
computed: {
info() {
if (this.results.length === 0) return [null, null];
return [this.pageCount, this.resultCount];
},
resultCount() {
const loadedResults = this.results.length;
const totalResults = this.totalResults < 10000 ? this.totalResults : "∞";
return `${loadedResults} of ${totalResults} results`;
},
pageCount() {
return `Page ${this.page} of ${this.totalPages}`;
}
},
methods: {
loadMore() {
if (!this.autoLoad) {
this.autoLoad = true;
} }
this.loading = true; const store = useStore();
let maxPage = [...this.loadedPages].slice(-1)[0]; const props = defineProps<Props>();
const results: Ref<ListResults> = ref([]);
const page: Ref<number> = ref(1);
const loadedPages: Ref<number[]> = ref([]);
const totalResults: Ref<number> = ref(0);
const totalPages: Ref<number> = ref(0);
const loading: Ref<boolean> = ref(true);
const autoLoad: Ref<boolean> = ref(false);
const observer: Ref<any> = ref(null);
const resultSection = ref(null);
const loadMoreButton = ref(null);
page.value = getPageFromUrl() || page.value;
if (results.value?.length === 0) getListResults();
const info = computed(() => {
if (results.value.length === 0) return [null, null];
const pageCount = pageCountString(page.value, totalPages.value);
const resultCount = resultCountString(results.value, totalResults.value);
return [pageCount, resultCount];
});
onMounted(() => {
if (!props?.shortList) setupAutoloadObserver();
});
function pageCountString(page: Number, totalPages: Number) {
return `Page ${page} of ${totalPages}`;
}
function resultCountString(results: ListResults, totalResults: number) {
const loadedResults = results.length;
const _totalResults = totalResults < 10000 ? totalResults : "∞";
return `${loadedResults} of ${_totalResults} results`;
}
function getPageFromUrl() {
const page = new URLSearchParams(window.location.search).get("page");
if (!page) return null;
return Number(page);
}
function getListResults(front = false) {
props
.apiFunction(page.value)
.then(listResponse => {
if (!front)
results.value = results.value.concat(...listResponse.results);
else results.value = listResponse.results.concat(...results.value);
page.value = listResponse.page;
loadedPages.value.push(page.value);
loadedPages.value = loadedPages.value.sort((a, b) => a - b);
totalPages.value = listResponse.total_pages;
totalResults.value = listResponse.total_results;
})
.then(updateQueryParams)
.finally(() => (loading.value = false));
}
function loadMore() {
if (!autoLoad.value) {
autoLoad.value = true;
}
loading.value = true;
let maxPage = [...loadedPages.value].slice(-1)[0];
if (maxPage == NaN) return; if (maxPage == NaN) return;
this.page = maxPage + 1; page.value = maxPage + 1;
this.getListResults(); getListResults();
}, }
loadLess() {
this.loading = true; function loadLess() {
const minPage = this.loadedPages[0]; loading.value = true;
const minPage = loadedPages.value[0];
if (minPage === 1) return; if (minPage === 1) return;
this.page = minPage - 1; page.value = minPage - 1;
this.getListResults(true); getListResults(true);
}, }
updateQueryParams() {
function updateQueryParams() {
let params = new URLSearchParams(window.location.search); let params = new URLSearchParams(window.location.search);
if (params.has("page")) { if (params.has("page")) {
params.set("page", this.page); params.set("page", page.value?.toString());
} else if (this.page > 1) { } else if (page.value > 1) {
params.append("page", this.page); params.append("page", page.value?.toString());
} }
window.history.replaceState( window.history.replaceState(
@@ -115,76 +147,53 @@ export default {
params.toString().length ? `?${params}` : "" params.toString().length ? `?${params}` : ""
}` }`
); );
}, }
getPageFromUrl() {
return new URLSearchParams(window.location.search).get("page"); function handleButtonIntersection(entries) {
}, entries.map(entry =>
getListResults(front = false) { entry.isIntersecting && autoLoad.value ? loadMore() : null
this.apiFunction(this.page) );
.then(results => { }
if (!front) this.results = this.results.concat(...results.results);
else this.results = results.results.concat(...this.results); function setupAutoloadObserver() {
this.page = results.page; observer.value = new IntersectionObserver(handleButtonIntersection, {
this.loadedPages.push(this.page); root: resultSection.value.$el,
this.loadedPages = this.loadedPages.sort((a, b) => a - b);
this.totalPages = results.total_pages;
this.totalResults = results.total_results;
})
.then(this.updateQueryParams)
.finally(() => (this.loading = false));
},
setupAutoloadObserver() {
this.observer = new IntersectionObserver(this.handleButtonIntersection, {
root: this.$refs.resultSection.$el,
rootMargin: "0px", rootMargin: "0px",
threshold: 0 threshold: 0
}); });
this.observer.observe(this.$refs.loadMoreButton); observer.value.observe(loadMoreButton.value);
},
handleButtonIntersection(entries) {
entries.map(entry =>
entry.isIntersecting && this.autoLoad ? this.loadMore() : null
);
} }
},
created() {
this.page = this.getPageFromUrl() || this.page;
if (this.results.length === 0) this.getListResults();
if (!this.shortList) { // created() {
store.dispatch( // if (!this.shortList) {
"documentTitle/updateTitle", // store.dispatch(
`${this.$router.history.current.name} ${this.title}` // "documentTitle/updateTitle",
); // `${this.$router.history.current.name} ${this.title}`
} // );
}, // }
mounted() { // },
if (!this.shortList) { // beforeDestroy() {
this.setupAutoloadObserver(); // this.observer = undefined;
} // }
}, // };
beforeDestroy() {
this.observer = undefined;
}
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.resultSection { .resultSection {
background-color: var(--background-color); background-color: var(--background-color);
} }
.button-container { .button-container {
display: flex; display: flex;
justify-content: center; justify-content: center;
display: flex; display: flex;
width: 100%; width: 100%;
} }
.load-button { .load-button {
margin: 2rem 0; margin: 2rem 0;
@include mobile { @include mobile {
@@ -198,5 +207,5 @@ export default {
margin-bottom: 2rem; margin-bottom: 2rem;
} }
} }
} }
</style> </style>

View File

@@ -1,747 +0,0 @@
<template>
<div v-if="show" class="container">
<h2 class="torrentHeader-text editable">
Searching for:
<span :contenteditable="!edit" @input="this.handleInput">{{
query
}}</span>
<IconSearch
class="icon"
v-if="editedSearchQuery && editedSearchQuery.length"
/>
<IconEdit v-else class="icon" @click="() => (this.edit = !this.edit)" />
</h2>
<div v-if="!loading">
<div v-if="torrents.length > 0">
<table>
<thead class="table__header noselect">
<tr>
<th
v-for="column in columns"
:key="column"
@click="sortTable(column)"
:class="column === selectedColumn ? 'active' : null"
>
{{ column }}
<span v-if="prevCol === column && direction"></span>
<span v-if="prevCol === column && !direction"></span>
</th>
</tr>
<!-- <th
@click="sortTable('name')"
:class="selectedSortableClass('name')"
>
<span>Name</span>
<span v-if="prevCol === 'name' && direction"></span>
<span v-if="prevCol === 'name' && !direction"></span>
</th>
<th
@click="sortTable('seed')"
:class="selectedSortableClass('seed')"
>
<span>Seed</span>
<span v-if="prevCol === 'seed' && direction"></span>
<span v-if="prevCol === 'seed' && !direction"></span>
</th>
<th
@click="sortTable('size')"
:class="selectedSortableClass('size')"
>
<span>Size</span>
<span v-if="prevCol === 'size' && direction"></span>
<span v-if="prevCol === 'size' && !direction"></span>
</th>
<th>
<span>Magnet</span>
</th> -->
</thead>
<tbody>
<tr
v-for="torrent in torrents"
class="table__content"
:key="torrent.magnet"
>
<td @click="expand($event, torrent.name)">{{ torrent.name }}</td>
<td @click="expand($event, torrent.name)">{{ torrent.seed }}</td>
<td @click="expand($event, torrent.name)">{{ torrent.size }}</td>
<td
@click="sendTorrent(torrent.magnet, torrent.name, $event)"
class="download"
>
<IconMagnet />
</td>
</tr>
</tbody>
</table>
<div style="display: flex; justify-content: center; padding: 1rem">
<seasonedButton @click="resetTorrentsAndToggleEditSearchQuery"
>Edit search query</seasonedButton
>
</div>
</div>
<div
v-else
style="
display: flex;
padding-bottom: 2rem;
justify-content: center;
flex-direction: column;
width: 100%;
align-items: center;
"
>
<h2>No results found</h2>
<br />
<div class="editQuery" v-if="editSearchQuery">
<seasonedInput
placeholder="Torrent query"
:value.sync="editedSearchQuery"
@enter="fetchTorrents(editedSearchQuery)"
/>
<div style="height: 45px; width: 5px"></div>
<seasonedButton @click="fetchTorrents(editedSearchQuery)"
>Search</seasonedButton
>
</div>
<seasonedButton
@click="toggleEditSearchQuery"
:active="editSearchQuery ? true : false"
>Edit search query</seasonedButton
>
</div>
</div>
<div v-else class="torrentloader"><i></i></div>
</div>
</template>
<script>
import store from "@/store";
import { sortableSize } from "@/utils";
import { searchTorrents, addMagnet } from "@/api";
import IconMagnet from "../icons/IconMagnet";
import IconEdit from "../icons/IconEdit";
import IconSearch from "../icons/IconSearch";
import SeasonedButton from "@/components/ui/SeasonedButton";
import SeasonedInput from "@/components/ui/SeasonedInput";
import ToggleButton from "@/components/ui/ToggleButton";
export default {
components: {
IconMagnet,
IconEdit,
IconSearch,
SeasonedButton,
SeasonedInput,
ToggleButton
},
props: {
query: {
type: String,
require: true
},
tmdb_id: {
type: Number,
require: true
},
tmdb_type: String,
admin: Boolean,
show: Boolean
},
data() {
return {
edit: true,
loading: false,
torrents: [],
torrentResponse: undefined,
currentPage: 0,
prevCol: "",
direction: false,
release_types: ["all"],
selectedRelaseType: "all",
editSearchQuery: false,
editedSearchQuery: "",
columns: ["name", "seed", "size", "magnet"],
selectedColumn: null
};
},
created() {
this.fetchTorrents().then(_ => this.sortTable("size"));
},
watch: {
selectedRelaseType: function (newValue) {
this.applyFilter(newValue);
}
},
methods: {
selectedSortableClass(headerName) {
return headerName === this.prevCol ? "active" : "";
},
resetTorrentsAndToggleEditSearchQuery() {
this.torrents = [];
this.toggleEditSearchQuery();
},
toggleEditSearchQuery() {
this.editSearchQuery = !this.editSearchQuery;
},
expand(event, name) {
const existingExpandedElement =
document.getElementsByClassName("expanded")[0];
const clickedElement = event.target.parentNode;
const scopedStyleDataVariable = Object.keys(clickedElement.dataset)[0];
if (existingExpandedElement) {
const expandedSibling =
event.target.parentNode.nextSibling.className === "expanded";
existingExpandedElement.remove();
const table = document.getElementsByTagName("table")[0];
table.style.display = "block";
if (expandedSibling) {
return;
}
}
const nameRow = document.createElement("tr");
const nameCol = document.createElement("td");
nameRow.className = "expanded";
nameRow.dataset[scopedStyleDataVariable] = "";
nameCol.innerText = name;
nameCol.dataset[scopedStyleDataVariable] = "";
nameRow.appendChild(nameCol);
clickedElement.insertAdjacentElement("afterend", nameRow);
},
sendTorrent(magnet, name, event) {
this.$notifications.info({
title: "Adding torrent 🦜",
description: this.query,
timeout: 3000
});
event.target.parentNode.classList.add("active");
addMagnet(magnet, name, this.tmdb_id)
.catch(resp => {
console.log("error:", resp.data);
})
.then(resp => {
console.log("addTorrent resp: ", resp);
this.$notifications.success({
title: "Torrent added 🎉",
description: this.query,
timeout: 3000
});
});
},
sortTable(col, sameDirection = false) {
if (this.prevCol === col && sameDirection === false) {
this.direction = !this.direction;
}
if (col === "name") this.sortName();
else if (col === "seed") this.sortSeed();
else if (col === "size") this.sortSize();
this.prevCol = col;
},
sortName() {
const torrentsCopy = [...this.torrents];
if (this.direction) {
this.torrents = torrentsCopy.sort((a, b) => (a.name < b.name ? 1 : -1));
} else {
this.torrents = torrentsCopy.sort((a, b) => (a.name > b.name ? 1 : -1));
}
},
sortSeed() {
const torrentsCopy = [...this.torrents];
if (this.direction) {
this.torrents = torrentsCopy.sort(
(a, b) => parseInt(a.seed) - parseInt(b.seed)
);
} else {
this.torrents = torrentsCopy.sort(
(a, b) => parseInt(b.seed) - parseInt(a.seed)
);
}
},
sortSize() {
const torrentsCopy = [...this.torrents];
if (this.direction) {
this.torrents = torrentsCopy.sort(
(a, b) =>
parseInt(sortableSize(a.size)) - parseInt(sortableSize(b.size))
);
} else {
this.torrents = torrentsCopy.sort(
(a, b) =>
parseInt(sortableSize(b.size)) - parseInt(sortableSize(a.size))
);
}
},
findRelaseTypes() {
this.torrents.forEach(item =>
this.release_types.push(...item.release_type)
);
this.release_types = [...new Set(this.release_types)];
},
applyFilter(item, index) {
this.selectedRelaseType = item;
const torrents = [...this.torrentResponse];
if (item === "all") {
this.torrents = torrents;
this.sortTable(this.prevCol, true);
return;
}
this.torrents = torrents.filter(torrent =>
torrent.release_type.includes(item)
);
this.sortTable(this.prevCol, true);
},
updateResultCountInStore() {
store.dispatch("torrentModule/setResults", this.torrents);
store.dispatch(
"torrentModule/setResultCount",
this.torrentResponse.length
);
},
filterDeadTorrents(torrents) {
return torrents.filter(torrent => {
if (isNaN(torrent.seed)) return false;
return parseInt(torrent.seed) > 0;
});
},
fetchTorrents(query = undefined) {
this.loading = true;
this.editSearchQuery = false;
return searchTorrents(query || this.query)
.then(data => {
const { results } = data;
if (results) {
this.torrentResponse = results;
this.torrents = this.filterDeadTorrents(results);
} else {
this.torrents = [];
}
})
.then(this.updateResultCountInStore)
.then(this.findRelaseTypes)
.catch(e => {
console.log("e:", e);
const error = e.toString();
this.errorMessage =
error.indexOf("401") != -1 ? "Permission denied" : "Nothing found";
})
.finally(() => {
this.loading = false;
});
},
handleInput(event) {
this.editedSearchQuery = event.target.innerText;
console.log("edit text:", this.editedSearchQuery);
}
}
};
</script>
<style lang="scss" scoped>
@import "src/scss/variables";
.expanded {
display: flex;
padding: 0.25rem 1rem;
max-width: 100%;
border-left: 1px solid $text-color;
border-right: 1px solid $text-color;
border-bottom: 1px solid $text-color;
td {
word-break: break-all;
padding: 0.5rem 0.15rem;
width: 100%;
}
}
$checkboxSize: 20px;
$ui-border-width: 2px;
.checkbox {
display: flex;
flex-direction: row;
margin-bottom: $checkboxSize * 0.5;
input[type="checkbox"] {
display: block;
opacity: 0;
position: absolute;
+ div {
position: relative;
display: inline-block;
padding-left: 1.25rem;
font-size: 20px;
line-height: $checkboxSize + $ui-border-width * 2;
left: $checkboxSize;
cursor: pointer;
&::before {
content: "";
display: inline-block;
position: absolute;
left: -$checkboxSize;
border: $ui-border-width solid var(--color-green);
width: $checkboxSize;
height: $checkboxSize;
}
&::after {
transition: all 0.3s ease;
content: "";
position: absolute;
display: inline-block;
left: -$checkboxSize + $ui-border-width;
top: $ui-border-width;
width: $checkboxSize + $ui-border-width;
height: $checkboxSize + $ui-border-width;
}
}
&:checked {
+ div::after {
background-color: var(--color-green);
opacity: 1;
}
}
&:hover:not(checked) {
+ div::after {
background-color: var(--color-green);
opacity: 0.4;
}
}
&:focus {
+ div::before {
outline: 2px solid Highlight;
outline-style: auto;
outline-color: -webkit-focus-ring-color;
}
}
}
}
</style>
<style lang="scss" scoped>
@import "src/scss/variables";
@import "src/scss/media-queries";
@import "src/scss/elements";
h2 {
font-size: 20px;
}
thead {
user-select: none;
-webkit-user-select: none;
color: var(--background-color);
text-transform: uppercase;
cursor: pointer;
background-color: var(--text-color);
letter-spacing: 0.8px;
font-size: 1rem;
border: 1px solid var(--text-color-90);
th:first-of-type {
border-top-left-radius: 8px;
}
th:last-of-type {
border-top-right-radius: 8px;
}
}
tbody {
tr > td:first-of-type {
white-space: unset;
}
tr > td:not(td:first-of-type) {
text-align: center;
}
tr > td:last-of-type {
cursor: pointer;
}
tr td:first-of-type {
border-left: 1px solid var(--text-color-90);
}
tr td:last-of-type {
border-right: 1px solid var(--text-color-90);
}
tr:last-of-type {
td {
border-bottom: 1px solid var(--text-color-90);
}
td:first-of-type {
border-bottom-left-radius: 8px;
}
td:last-of-type {
border-bottom-right-radius: 8px;
}
}
tr:nth-child(even) {
background-color: var(--background-70);
}
}
th,
td {
padding: 0.35rem 0.25rem;
white-space: nowrap;
svg {
width: 24px;
fill: var(--text-color);
}
}
.toggle {
max-width: unset !important;
margin: 1rem 0;
}
.container {
background-color: $background-color;
padding: 0 1rem;
}
.torrentHeader {
display: flex;
align-items: center;
justify-content: center;
padding-bottom: 20px;
&-text {
font-weight: 400;
text-transform: uppercase;
font-size: 20px;
// color: $green;
text-align: center;
margin: 0;
.icon {
vertical-align: text-top;
margin-left: 1rem;
fill: var(--text-color);
width: 22px;
height: 22px;
// stroke: white !important;
}
&.editable {
cursor: pointer;
}
}
&-editIcon {
margin-left: 10px;
margin-top: -3px;
width: 22px;
height: 22px;
&:hover {
fill: $green;
cursor: pointer;
}
}
}
table {
// border-collapse: collapse;
border-spacing: 0;
margin-top: 1rem;
width: 100%;
// table-layout: fixed;
}
// .table__content,
// .table__header {
// display: flex;
// padding: 0;
// border-left: 1px solid $text-color;
// border-right: 1px solid $text-color;
// border-bottom: 1px solid $text-color;
// th,
// td {
// display: flex;
// flex-direction: column;
// flex-basis: 100%;
// padding: 0.4rem;
// white-space: nowrap;
// text-overflow: ellipsis;
// overflow: hidden;
// min-width: 75px;
// }
// th:first-child,
// td:first-child {
// flex: 1;
// }
// th:not(:first-child),
// td:not(:first-child) {
// flex: 0.2;
// }
// th:nth-child(2),
// td:nth-child(2) {
// flex: 0.1;
// }
// @include mobile-only {
// th:first-child,
// td:first-child {
// display: none;
// &.show {
// display: block;
// align: flex-end;
// }
// }
// th:not(:first-child),
// td:not(:first-child) {
// flex: 1;
// }
// }
// }
.table__content {
td:not(:last-child) {
border-right: 1px solid $text-color;
}
}
.table__content:last-child {
margin-bottom: 1rem;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
}
// .table__header {
// color: $text-color;
// text-transform: uppercase;
// cursor: pointer;
// background-color: $background-color-secondary;
// border-top: 1px solid $text-color;
// border-top-left-radius: 3px;
// border-top-right-radius: 3px;
// th {
// display: flex;
// flex-direction: row;
// font-weight: 400;
// letter-spacing: 0.7px;
// // font-size: 1.08rem;
// font-size: 15px;
// &::before {
// content: "";
// min-width: 0.2rem;
// }
// span:first-child {
// margin-right: 0.6rem;
// }
// span:nth-child(2) {
// margin-right: 0.1rem;
// }
// }
// th:not(:last-child) {
// border-right: 1px solid $text-color;
// }
// }
.editQuery {
display: flex;
width: 70%;
justify-content: center;
margin-bottom: 1rem;
@include mobile-only {
width: 90%;
}
}
.download {
&__icon {
fill: $text-color-70;
height: 1.2rem;
&:hover {
fill: $text-color;
cursor: pointer;
}
}
&.active &__icon {
fill: $green;
}
}
.torrentloader {
width: 100%;
padding: 2rem 0;
i {
animation: load 1s linear infinite;
border: 2px solid $text-color;
border-radius: 50%;
display: block;
height: 30px;
left: 50%;
margin: 0 auto;
width: 30px;
&:after {
border: 5px solid $green;
border-radius: 50%;
content: "";
left: 10px;
position: absolute;
top: 16px;
}
}
}
@keyframes load {
100% {
transform: rotate(360deg);
}
}
</style>

View File

@@ -5,9 +5,9 @@
v-for="result in searchResults" v-for="result in searchResults"
:key="`${result.index}-${result.title}-${result.type}`" :key="`${result.index}-${result.title}-${result.type}`"
@click="openPopup(result)" @click="openPopup(result)"
:class=" :class="`result di-${result.index} ${
`result di-${result.index} ${result.index === index ? 'active' : ''}` result.index === index ? 'active' : ''
" }`"
> >
<IconMovie v-if="result.type == 'movie'" class="type-icon" /> <IconMovie v-if="result.type == 'movie'" class="type-icon" />
<IconShow v-if="result.type == 'show'" class="type-icon" /> <IconShow v-if="result.type == 'show'" class="type-icon" />
@@ -24,57 +24,64 @@
</transition> </transition>
</template> </template>
<script> <script setup lang="ts">
import { mapActions } from "vuex"; import { ref, watch, defineProps } from "vue";
import IconMovie from "src/icons/IconMovie"; import { useStore } from "vuex";
import IconShow from "src/icons/IconShow"; import IconMovie from "@/icons/IconMovie.vue";
import IconPerson from "src/icons/IconPerson"; import IconShow from "@/icons/IconShow.vue";
import { elasticSearchMoviesAndShows } from "@/api"; import IconPerson from "@/icons/IconPerson.vue";
import { elasticSearchMoviesAndShows } from "../../api";
import type { Ref } from "vue";
export default { interface Props {
components: { IconMovie, IconShow, IconPerson }, query?: string;
props: { index?: Number;
query: { results?: Array<any>;
type: String,
default: null,
required: false
},
index: {
type: Number,
default: -1,
required: false
},
results: {
type: Array,
default: [],
required: false
} }
},
watch: {
query(newQuery) {
if (newQuery && newQuery.length > 1) this.fetchAutocompleteResults();
}
},
data() {
return {
searchResults: [],
keyboardNavigationIndex: 0,
numberOfResults: 10
};
},
methods: {
...mapActions("popup", ["open"]),
openPopup(result) {
const { id, type } = result;
this.open({ id, type });
},
fetchAutocompleteResults() {
this.keyboardNavigationIndex = 0;
this.searchResults = [];
elasticSearchMoviesAndShows(this.query, this.numberOfResults).then( interface Emit {
resp => { (e: "update:results", value: Array<any>);
const data = resp.hits.hits; }
const numberOfResults: number = 10;
const props = defineProps<Props>();
const emit = defineEmits<Emit>();
const store = useStore();
const searchResults: Ref<Array<any>> = ref([]);
const keyboardNavigationIndex: Ref<number> = ref(0);
// on load functions
fetchAutocompleteResults();
// end on load functions
watch(
() => props.query,
newQuery => {
if (newQuery?.length > 0) fetchAutocompleteResults();
}
);
function openPopup(result) {
if (!result.id || !result.type) return;
store.dispatch("popup/open", { ...result });
}
function fetchAutocompleteResults() {
keyboardNavigationIndex.value = 0;
searchResults.value = [];
elasticSearchMoviesAndShows(props.query, numberOfResults)
.then(elasticResponse => parseElasticResponse(elasticResponse))
.then(_searchResults => {
emit("update:results", _searchResults);
searchResults.value = _searchResults;
});
}
function parseElasticResponse(elasticResponse: any) {
const data = elasticResponse.hits.hits;
let results = data.map(item => { let results = data.map(item => {
let index = null; let index = null;
@@ -83,8 +90,7 @@ export default {
if (index === "movie" || index === "show") { if (index === "movie" || index === "show") {
return { return {
title: title: item._source.original_name || item._source.original_title,
item._source.original_name || item._source.original_title,
id: item._source.id, id: item._source.id,
adult: item._source.adult, adult: item._source.adult,
type: index type: index
@@ -92,17 +98,12 @@ export default {
} }
}); });
results = this.removeDuplicates(results); return removeDuplicates(results).map((el, index) => {
results = results.map((el, index) => {
return { ...el, index }; return { ...el, index };
}); });
this.$emit("update:results", results);
this.searchResults = results;
} }
);
}, function removeDuplicates(searchResults) {
removeDuplicates(searchResults) {
let filteredResults = []; let filteredResults = [];
searchResults.map(result => { searchResults.map(result => {
if (result === undefined) return; if (result === undefined) return;
@@ -115,36 +116,25 @@ export default {
filteredResults.push(result); filteredResults.push(result);
}); });
if (this.adult == false) {
filteredResults = filteredResults.filter(
result => result.adult == false
);
}
return filteredResults; return filteredResults;
} }
},
created() {
if (this.query) this.fetchAutocompleteResults();
}
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
@import "src/scss/main"; @import "src/scss/main";
$sizes: 22; $sizes: 22;
@for $i from 0 through $sizes { @for $i from 0 through $sizes {
.dropdown .di-#{$i} { .dropdown .di-#{$i} {
visibility: visible; visibility: visible;
transform-origin: top center; transform-origin: top center;
animation: scaleZ 200ms calc(50ms * #{$i}) ease-in forwards; animation: scaleZ 200ms calc(50ms * #{$i}) ease-in forwards;
} }
} }
@keyframes scaleZ { @keyframes scaleZ {
0% { 0% {
opacity: 0; opacity: 0;
transform: scale(0); transform: scale(0);
@@ -156,9 +146,9 @@ $sizes: 22;
opacity: 1; opacity: 1;
transform: scale(1); transform: scale(1);
} }
} }
.dropdown { .dropdown {
top: var(--header-size); top: var(--header-size);
position: relative; position: relative;
height: 100%; height: 100%;
@@ -189,9 +179,9 @@ $sizes: 22;
@include desktop { @include desktop {
max-width: 720px; max-width: 720px;
} }
} }
li.result { li.result {
background-color: var(--background-95); background-color: var(--background-95);
color: var(--text-color-50); color: var(--text-color-50);
padding: 0.5rem 2rem; padding: 0.5rem 2rem;
@@ -237,9 +227,9 @@ li.result {
transition: inherit; transition: inherit;
fill: var(--text-color-50); fill: var(--text-color-50);
} }
} }
li.info { li.info {
visibility: hidden; visibility: hidden;
opacity: 0; opacity: 0;
display: flex; display: flex;
@@ -251,12 +241,12 @@ li.info {
font-size: 0.6rem; font-size: 0.6rem;
height: 16px; height: 16px;
width: 100%; width: 100%;
} }
.shut-leave-to { .shut-leave-to {
height: 0px; height: 0px;
transition: height 0.4s ease; transition: height 0.4s ease;
flex-wrap: no-wrap; flex-wrap: no-wrap;
overflow: hidden; overflow: hidden;
} }
</style> </style>

View File

@@ -10,10 +10,10 @@
<SearchInput /> <SearchInput />
<Hamburger class="mobile-only" /> <Hamburger class="mobile-only" />
<NavigationIcon class="desktop-only" :route="profileRoute" /> <NavigationIcon class="desktop-only" :route="profileRoute" />
<div class="navigation-icons-grid mobile-only" :class="{ open: isOpen }"> <!-- <div class="navigation-icons-grid mobile-only" :class="{ open: isOpen }"> -->
<div class="navigation-icons-grid mobile-only" v-if="isOpen">
<NavigationIcons> <NavigationIcons>
<NavigationIcon :route="profileRoute" /> <NavigationIcon :route="profileRoute" />
</NavigationIcons> </NavigationIcons>
@@ -21,72 +21,69 @@
</nav> </nav>
</template> </template>
<script> <script setup lang="ts">
import { mapGetters, mapActions } from "vuex"; import { computed, defineProps, PropType } from "vue";
import TmdbLogo from "@/icons/tmdb-logo"; import type { App } from "vue";
import IconProfile from "@/icons/IconProfile"; import { useStore } from "vuex";
import IconProfileLock from "@/icons/IconProfileLock"; import { useRoute } from "vue-router";
import IconSettings from "@/icons/IconSettings"; import SearchInput from "@/components/header/SearchInput.vue";
import IconActivity from "@/icons/IconActivity"; import Hamburger from "@/components/ui/Hamburger.vue";
import SearchInput from "@/components/header/SearchInput"; import NavigationIcons from "@/components/header/NavigationIcons.vue";
import NavigationIcons from "src/components/header/NavigationIcons"; import NavigationIcon from "@/components/header/NavigationIcon.vue";
import NavigationIcon from "src/components/header/NavigationIcon"; import TmdbLogo from "@/icons/tmdb-logo.vue";
import Hamburger from "@/components/ui/Hamburger"; import IconProfile from "@/icons/IconProfile.vue";
import IconProfileLock from "@/icons/IconProfileLock.vue";
import type INavigationIcon from "../../interfaces/INavigationIcon";
export default { const route = useRoute();
components: { const store = useStore();
NavigationIcons,
NavigationIcon, const signinNavigationIcon: INavigationIcon = {
SearchInput, title: "Signin",
TmdbLogo, route: "/signin",
IconProfile, icon: IconProfileLock
IconProfileLock,
IconSettings,
IconActivity,
Hamburger
},
computed: {
...mapGetters("user", ["loggedIn"]),
...mapGetters("hamburger", ["isOpen"]),
isHome() {
return this.$route.path === "/";
},
profileRoute() {
return {
title: !this.loggedIn ? "Signin" : "Profile",
route: !this.loggedIn ? "/signin" : "/profile",
icon: !this.loggedIn ? IconProfileLock : IconProfile
}; };
}
} const profileNavigationIcon: INavigationIcon = {
}; title: "Profile",
route: "/profile",
icon: IconProfile
};
const isHome = computed(() => route.path === "/");
const isOpen = computed(() => store.getters["hamburger/isOpen"]);
const loggedIn = computed(() => store.getters["user/loggedIn"]);
const profileRoute = computed(() =>
!loggedIn.value ? signinNavigationIcon : profileNavigationIcon
);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.spacer { .spacer {
@include mobile-only { @include mobile-only {
width: 100%; width: 100%;
height: $header-size; height: $header-size;
} }
} }
nav { nav {
display: grid; display: grid;
grid-template-columns: var(--header-size) 1fr var(--header-size); grid-template-columns: var(--header-size) 1fr var(--header-size);
> * { > * {
z-index: 10; z-index: 10;
} }
} }
.nav__logo { .nav__logo {
overflow: hidden; overflow: hidden;
} }
.logo { .logo {
padding: 1rem; padding: 1rem;
fill: var(--color-green); fill: var(--color-green);
width: var(--header-size); width: var(--header-size);
@@ -104,9 +101,9 @@ nav {
@include mobile { @include mobile {
padding: 0.5rem; padding: 0.5rem;
} }
} }
.navigation-icons-grid { .navigation-icons-grid {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
position: fixed; position: fixed;
@@ -118,9 +115,10 @@ nav {
opacity: 0; opacity: 0;
transition: opacity 0.4s ease; transition: opacity 0.4s ease;
&.open {
opacity: 1; opacity: 1;
visibility: visible; visibility: visible;
&.open {
}
} }
}
</style> </style>

View File

@@ -1,8 +1,8 @@
<template> <template>
<router-link <router-link
:to="{ path: route.route }" :to="{ path: route?.route }"
:key="route.title" :key="route?.title"
v-if="route.requiresAuth == undefined || (route.requiresAuth && loggedIn)" v-if="route?.requiresAuth == undefined || (route?.requiresAuth && loggedIn)"
> >
<li class="navigation-link" :class="{ active: route.route == active }"> <li class="navigation-link" :class="{ active: route.route == active }">
<component class="navigation-icon" :is="route.icon"></component> <component class="navigation-icon" :is="route.icon"></component>
@@ -11,31 +11,26 @@
</router-link> </router-link>
</template> </template>
<script> <script setup lang="ts">
import { mapGetters, mapActions } from "vuex"; import { useStore } from "vuex";
import { computed, defineProps } from "vue";
import type INavigationIcon from "../../interfaces/INavigationIcon";
export default { interface Props {
name: "NavigationIcon", route: INavigationIcon;
props: { active?: string;
active: {
type: String,
required: false
},
route: {
type: Object,
required: true
} }
},
computed: { defineProps<Props>();
...mapGetters("user", ["loggedIn"])
} const store = useStore();
}; const loggedIn = computed(() => store.getters["user/loggedIn"]);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.navigation-link { .navigation-link {
display: grid; display: grid;
place-items: center; place-items: center;
min-height: var(--header-size); min-height: var(--header-size);
@@ -67,15 +62,15 @@ export default {
margin-top: 0.25rem; margin-top: 0.25rem;
color: var(--text-color-70); color: var(--text-color-70);
} }
} }
a { a {
text-decoration: none; text-decoration: none;
} }
.navigation-icon { .navigation-icon {
width: 28px; width: 28px;
fill: var(--text-color-70); fill: var(--text-color-70);
transition: inherit; transition: inherit;
} }
</style> </style>

View File

@@ -10,29 +10,22 @@
</ul> </ul>
</template> </template>
<script> <script setup lang="ts">
import NavigationIcon from "@/components/header/NavigationIcon"; import { ref, watch } from "vue";
import IconInbox from "@/icons/IconInbox"; import { useRoute } from "vue-router";
import IconNowPlaying from "@/icons/IconNowPlaying"; import NavigationIcon from "@/components/header/NavigationIcon.vue";
import IconPopular from "@/icons/IconPopular"; import IconInbox from "@/icons/IconInbox.vue";
import IconUpcoming from "@/icons/IconUpcoming"; import IconNowPlaying from "@/icons/IconNowPlaying.vue";
import IconSettings from "@/icons/IconSettings"; import IconPopular from "@/icons/IconPopular.vue";
import IconActivity from "@/icons/IconActivity"; import IconUpcoming from "@/icons/IconUpcoming.vue";
import IconSettings from "@/icons/IconSettings.vue";
import IconActivity from "@/icons/IconActivity.vue";
import IconBinoculars from "@/icons/IconBinoculars.vue";
import type INavigationIcon from "../../interfaces/INavigationIcon";
export default { const route = useRoute();
name: "NavigationIcons", const activeRoute = ref(window?.location?.pathname);
components: { const routes: INavigationIcon[] = [
NavigationIcon,
IconInbox,
IconPopular,
IconNowPlaying,
IconUpcoming,
IconSettings,
IconActivity
},
data() {
return {
routes: [
{ {
title: "Requests", title: "Requests",
route: "/list/requests", route: "/list/requests",
@@ -59,31 +52,27 @@ export default {
requiresAuth: true, requiresAuth: true,
icon: IconActivity icon: IconActivity
}, },
{
title: "Torrents",
route: "/torrents",
requiresAuth: true,
icon: IconBinoculars
},
{ {
title: "Settings", title: "Settings",
route: "/profile?settings=true", route: "/profile?settings=true",
requiresAuth: true, requiresAuth: true,
icon: IconSettings icon: IconSettings
} }
], ];
activeRoute: null
}; watch(route, () => (activeRoute.value = window?.location?.pathname));
},
watch: {
$route() {
this.activeRoute = window.location.pathname;
}
},
created() {
this.activeRoute = window.location.pathname;
}
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.navigation-icons { .navigation-icons {
display: grid; display: grid;
grid-column: 1fr; grid-column: 1fr;
padding-left: 0; padding-left: 0;
@@ -99,5 +88,5 @@ export default {
@include mobile { @include mobile {
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
} }
} }
</style> </style>

View File

@@ -1,10 +1,10 @@
<template> <template>
<div> <div>
<div class="search" :class="{ active: focusingInput }"> <div class="search" :class="{ active: inputIsActive }">
<IconSearch class="search-icon" tabindex="-1" /> <IconSearch class="search-icon" tabindex="-1" />
<input <input
ref="input" ref="inputElement"
type="text" type="text"
placeholder="Search for movie or show" placeholder="Search for movie or show"
aria-label="Search input for finding a movie or show" aria-label="Search input for finding a movie or show"
@@ -13,21 +13,21 @@
tabindex="0" tabindex="0"
v-model="query" v-model="query"
@input="handleInput" @input="handleInput"
@click="focusingInput = true" @click="focus"
@keydown.escape="handleEscape" @keydown.escape="handleEscape"
@keyup.enter="handleSubmit" @keyup.enter="handleSubmit"
@keydown.up="navigateUp" @keydown.up="navigateUp"
@keydown.down="navigateDown" @keydown.down="navigateDown"
@focus="focusingInput = true" @focus="focus"
@blur="focusingInput = false" @blur="blur"
/> />
<IconClose <IconClose
tabindex="0" tabindex="0"
aria-label="button" aria-label="button"
v-if="query && query.length" v-if="query && query.length"
@click="resetQuery" @click="clearInput"
@keydown.enter.stop="resetQuery" @keydown.enter.stop="clearInput"
class="close-icon" class="close-icon"
/> />
</div> </div>
@@ -36,131 +36,143 @@
v-if="showAutocompleteResults" v-if="showAutocompleteResults"
:query="query" :query="query"
:index="dropdownIndex" :index="dropdownIndex"
:results.sync="dropdownResults" v-model:results="dropdownResults"
/> />
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import { mapActions, mapGetters } from "vuex"; import { ref, computed } from "vue";
import SeasonedButton from "@/components/ui/SeasonedButton"; import { useStore } from "vuex";
import AutocompleteDropdown from "@/components/header/AutocompleteDropdown"; import { useRouter } from "vue-router";
import { useRoute } from "vue-router";
import SeasonedButton from "@/components/ui/SeasonedButton.vue";
import AutocompleteDropdown from "@/components/header/AutocompleteDropdown.vue";
import IconSearch from "@/icons/IconSearch.vue";
import IconClose from "@/icons/IconClose.vue";
import config from "../../config";
import type { Ref } from "vue";
import type { ListTypes } from "../../interfaces/IList";
import IconSearch from "src/icons/IconSearch"; interface ISearchResult {
import IconClose from "src/icons/IconClose"; title: string;
import config from "@/config"; id: number;
adult: boolean;
export default { type: ListTypes;
name: "SearchInput",
components: {
SeasonedButton,
AutocompleteDropdown,
IconClose,
IconSearch
},
data() {
return {
query: null,
disabled: false,
dropdownIndex: -1,
dropdownResults: [],
focusingInput: false,
showAutocomplete: false
};
},
computed: {
...mapGetters("popup", ["isOpen"]),
showAutocompleteResults() {
return (
!this.disabled &&
this.focusingInput &&
this.query &&
this.query.length > 0
);
} }
},
created() { const store = useStore();
const router = useRouter();
const route = useRoute();
const query: Ref<string> = ref(null);
const disabled: Ref<boolean> = ref(false);
const dropdownIndex: Ref<number> = ref(-1);
const dropdownResults: Ref<ISearchResult[]> = ref([]);
const inputIsActive: Ref<boolean> = ref(false);
const showAutocomplete: Ref<boolean> = ref(false);
const inputElement: Ref<any> = ref(null);
const isOpen = computed(() => store.getters["popup/isOpen"]);
const showAutocompleteResults = computed(() => {
return (
!disabled.value &&
inputIsActive.value &&
query.value &&
query.value.length > 0
);
});
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
if (params && params.has("query")) { if (params && params.has("query")) {
this.query = decodeURIComponent(params.get("query")); query.value = decodeURIComponent(params.get("query"));
} }
const elasticUrl = config.ELASTIC_URL; const elasticUrl = config.ELASTIC_URL;
if (elasticUrl === undefined || elasticUrl === false || elasticUrl === "") { if (elasticUrl === undefined || elasticUrl === "") {
this.disabled = true; disabled.value = true;
} }
},
methods: {
...mapActions("popup", ["open"]),
navigateDown() {
if (this.dropdownIndex < this.dropdownResults.length - 1) {
this.dropdownIndex++;
}
},
navigateUp() {
if (this.dropdownIndex > -1) this.dropdownIndex--;
const input = this.$refs.input; function navigateDown() {
const textLength = input.value.length; if (dropdownIndex.value < dropdownResults.value.length - 1) {
dropdownIndex.value++;
}
}
function navigateUp() {
if (dropdownIndex.value > -1) dropdownIndex.value--;
const textLength = inputElement.value.value.length;
setTimeout(() => { setTimeout(() => {
input.focus(); inputElement.value.focus();
input.setSelectionRange(textLength, textLength + 1); inputElement.value.setSelectionRange(textLength, textLength + 1);
}, 1); }, 1);
}, }
search() {
const encodedQuery = encodeURI(this.query.replace('/ /g, "+"'));
this.$router.push({ function search() {
const encodedQuery = encodeURI(query.value.replace("/ /g", "+"));
router.push({
name: "search", name: "search",
query: { query: {
...this.$route.query, ...route.query,
query: encodedQuery query: encodedQuery
} }
}); });
}, }
resetQuery(event) {
this.query = "";
this.$refs.input.focus();
},
handleInput(e) {
this.$emit("input", this.query);
this.dropdownIndex = -1;
},
handleSubmit() {
if (!this.query || this.query.length == 0) return;
if (this.dropdownIndex >= 0) { function handleInput(e) {
const resultItem = this.dropdownResults[this.dropdownIndex]; dropdownIndex.value = -1;
}
console.log("resultItem:", resultItem); function handleSubmit() {
this.open({ if (!query.value || query.value.length == 0) return;
id: resultItem.id,
type: resultItem.type if (dropdownIndex.value >= 0) {
const resultItem = dropdownResults.value[dropdownIndex.value];
store.dispatch("popup/open", {
id: resultItem?.id,
type: resultItem?.type
}); });
return; return;
} }
this.search(); search();
this.$refs.input.blur(); reset();
this.dropdownIndex = -1;
},
handleEscape() {
if (!this.isOpen) {
this.$refs.input.blur();
this.dropdownIndex = -1;
} }
function focus() {
inputIsActive.value = true;
} }
function blur(event: MouseEvent = null) {
return setTimeout(reset, 150);
}
function reset() {
inputElement.value.blur();
dropdownIndex.value = -1;
inputIsActive.value = false;
}
function clearInput(event: MouseEvent) {
query.value = "";
inputElement.value.focus();
}
function handleEscape() {
if (!isOpen.value) reset();
} }
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
@import "src/scss/main"; @import "src/scss/main";
.close-icon { .close-icon {
position: absolute; position: absolute;
top: calc(50% - 12px); top: calc(50% - 12px);
right: 0; right: 0;
@@ -172,9 +184,9 @@ export default {
@include tablet-min { @include tablet-min {
right: 6px; right: 6px;
} }
} }
.filter { .filter {
width: 100%; width: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -195,9 +207,9 @@ export default {
margin-left: 1rem; margin-left: 1rem;
} }
} }
} }
hr { hr {
display: block; display: block;
height: 1px; height: 1px;
border: 0; border: 0;
@@ -205,9 +217,9 @@ hr {
margin-top: 10px; margin-top: 10px;
margin-bottom: 10px; margin-bottom: 10px;
width: 90%; width: 90%;
} }
.search.active { .search.active {
input { input {
border-color: var(--color-green); border-color: var(--color-green);
} }
@@ -215,9 +227,9 @@ hr {
.search-icon { .search-icon {
fill: var(--color-green); fill: var(--color-green);
} }
} }
.search { .search {
height: $header-size; height: $header-size;
display: flex; display: flex;
position: fixed; position: fixed;
@@ -277,5 +289,5 @@ hr {
left: 22px; left: 22px;
} }
} }
} }
</style> </style>

View File

@@ -1,32 +1,33 @@
<template> <template>
<li <li
class="sidebar-list-element" class="sidebar-list-element"
@click="event => $emit('click', event)" @click="emit('click')"
:class="{ active, disabled }" :class="{ active, disabled }"
> >
<slot></slot> <slot></slot>
</li> </li>
</template> </template>
<script> <script setup lang="ts">
export default { import { defineProps, defineEmits } from "vue";
props: {
active: { interface Props {
type: Boolean, active?: Boolean;
default: false disabled?: Boolean;
},
disabled: {
type: Boolean,
default: false
} }
interface Emit {
(e: "click");
} }
};
const emit = defineEmits<Emit>();
defineProps<Props>();
</script> </script>
<style lang="scss"> <style lang="scss">
@import "src/scss/media-queries"; @import "src/scss/media-queries";
li.sidebar-list-element { li.sidebar-list-element {
display: flex; display: flex;
align-items: center; align-items: center;
text-decoration: none; text-decoration: none;
@@ -36,6 +37,8 @@ li.sidebar-list-element {
padding: 10px 0; padding: 10px 0;
border-bottom: 1px solid var(--text-color-5); border-bottom: 1px solid var(--text-color-5);
cursor: pointer; cursor: pointer;
user-select: none;
-webkit-user-select: none;
&:first-of-type { &:first-of-type {
padding-top: 0; padding-top: 0;
@@ -78,5 +81,5 @@ li.sidebar-list-element {
margin-left: auto; margin-left: auto;
text-align: right; text-align: right;
} }
} }
</style> </style>

View File

@@ -1,10 +1,10 @@
<template> <template>
<div <div
id="description" ref="descriptionElement"
class="movie-description noselect" class="movie-description noselect"
@click="overflow ? (truncated = !truncated) : null" @click="overflow ? (truncated = !truncated) : null"
> >
<span ref="description" :class="{ truncated }">{{ description }}</span> <span :class="{ truncated }">{{ description }}</span>
<button v-if="description && overflow" class="truncate-toggle"> <button v-if="description && overflow" class="truncate-toggle">
<IconArrowDown :class="{ rotate: !truncated }" /> <IconArrowDown :class="{ rotate: !truncated }" />
@@ -12,35 +12,35 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import IconArrowDown from "../../icons/IconArrowDown"; import { ref, defineProps, onMounted } from "vue";
export default { import IconArrowDown from "../../icons/IconArrowDown.vue";
components: { IconArrowDown }, import type { Ref } from "vue";
props: {
description: { interface Props {
type: String, description: string;
required: true
} }
},
data() {
return {
truncated: true,
overflow: false
};
},
mounted() {
this.checkDescriptionOverflowing();
},
methods: {
checkDescriptionOverflowing() {
const descriptionEl = document.getElementById("description");
if (!descriptionEl) return;
const { height, width } = descriptionEl.getBoundingClientRect(); const props = defineProps<Props>();
const { fontSize, lineHeight } = getComputedStyle(descriptionEl); const truncated: Ref<boolean> = ref(true);
const overflow: Ref<boolean> = ref(false);
const descriptionElement: Ref<HTMLElement> = ref(null);
const elementWithoutOverflow = document.createElement("div"); onMounted(checkDescriptionOverflowing);
elementWithoutOverflow.setAttribute(
// The description element overflows text after 4 rows with css
// line-clamp this takes the same text and adds to a temporary
// element without css overflow. If the temp element is
// higher then description element, we display expand button
function checkDescriptionOverflowing() {
const element = descriptionElement?.value;
if (!element) return;
const { height, width } = element.getBoundingClientRect();
const { fontSize, lineHeight } = getComputedStyle(element);
const descriptionComparisonElement = document.createElement("div");
descriptionComparisonElement.setAttribute(
"style", "style",
`max-width: ${Math.ceil( `max-width: ${Math.ceil(
width + 10 width + 10
@@ -48,25 +48,26 @@ export default {
); );
// Don't know why need to add 10px to width, but works out perfectly // Don't know why need to add 10px to width, but works out perfectly
elementWithoutOverflow.classList.add("dummy-non-overflow"); descriptionComparisonElement.classList.add("dummy-non-overflow");
elementWithoutOverflow.innerText = this.description; descriptionComparisonElement.innerText = props.description;
document.body.appendChild(elementWithoutOverflow); document.body.appendChild(descriptionComparisonElement);
const elemWithoutOverflowHeight = const elemWithoutOverflowHeight =
elementWithoutOverflow.getBoundingClientRect()["height"]; descriptionComparisonElement.getBoundingClientRect()["height"];
this.overflow = elemWithoutOverflowHeight > height; overflow.value = elemWithoutOverflowHeight > height;
this.removeElements(document.querySelectorAll(".dummy-non-overflow")); removeElements(document.querySelectorAll(".dummy-non-overflow"));
}, }
removeElements: elems => elems.forEach(el => el.remove())
function removeElements(elems: NodeListOf<Element>) {
elems.forEach(el => el.remove());
} }
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.movie-description { .movie-description {
font-weight: 300; font-weight: 300;
font-size: 13px; font-size: 13px;
line-height: 1.8; line-height: 1.8;
@@ -77,16 +78,16 @@ export default {
margin-bottom: 30px; margin-bottom: 30px;
font-size: 14px; font-size: 14px;
} }
} }
span.truncated { span.truncated {
display: -webkit-box; display: -webkit-box;
overflow: hidden; overflow: hidden;
-webkit-line-clamp: 4; -webkit-line-clamp: 4;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
} }
.truncate-toggle { .truncate-toggle {
border: none; border: none;
background: none; background: none;
width: 100%; width: 100%;
@@ -120,5 +121,5 @@ span.truncated {
&::after { &::after {
margin-left: 1rem; margin-left: 1rem;
} }
} }
</style> </style>

View File

@@ -7,25 +7,21 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
export default { import { defineProps } from "vue";
props: {
title: { interface Props {
type: String, title: string;
required: true detail?: string | number;
},
detail: {
required: false,
default: null
} }
}
}; defineProps<Props>();
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.movie-detail { .movie-detail {
margin-bottom: 20px; margin-bottom: 20px;
&:last-of-type { &:last-of-type {
@@ -54,5 +50,5 @@ export default {
letter-spacing: 0.8px; letter-spacing: 0.8px;
margin-top: 5px; margin-top: 5px;
} }
} }
</style> </style>

View File

@@ -2,7 +2,7 @@
<section class="movie"> <section class="movie">
<!-- HEADER w/ POSTER --> <!-- HEADER w/ POSTER -->
<header <header
ref="header" ref="backdropElement"
:class="compact ? 'compact' : ''" :class="compact ? 'compact' : ''"
@click="compact = !compact" @click="compact = !compact"
> >
@@ -10,13 +10,13 @@
<img <img
class="movie-item__img is-loaded" class="movie-item__img is-loaded"
ref="poster-image" ref="poster-image"
src="/assets/placeholder.png" :src="poster"
/> />
</figure> </figure>
<div v-if="movie" class="movie__title"> <div v-if="media" class="movie__title">
<h1>{{ movie.title || movie.name }}</h1> <h1>{{ media.title || media.name }}</h1>
<i>{{ movie.tagline }}</i> <i>{{ media.tagline }}</i>
</div> </div>
<loading-placeholder v-else :count="2" /> <loading-placeholder v-else :count="2" />
</header> </header>
@@ -25,11 +25,15 @@
<div class="movie__main"> <div class="movie__main">
<div class="movie__wrap movie__wrap--main"> <div class="movie__wrap movie__wrap--main">
<!-- SIDEBAR ACTIONS --> <!-- SIDEBAR ACTIONS -->
<div class="movie__actions" v-if="movie"> <div class="movie__actions" v-if="media">
<action-button :active="matched" :disabled="true"> <action-button :active="media?.exists_in_plex" :disabled="true">
<IconThumbsUp v-if="matched" /> <IconThumbsUp v-if="media?.exists_in_plex" />
<IconThumbsDown v-else /> <IconThumbsDown v-else />
{{ !matched ? "Not yet available" : "Already available 🎉" }} {{
!media?.exists_in_plex
? "Not yet available"
: "Already available 🎉"
}}
</action-button> </action-button>
<action-button @click="sendRequest" :active="requested"> <action-button @click="sendRequest" :active="requested">
@@ -37,16 +41,19 @@
<div v-if="!requested" key="request"><IconRequest /></div> <div v-if="!requested" key="request"><IconRequest /></div>
<div v-else key="requested"><IconRequested /></div> <div v-else key="requested"><IconRequested /></div>
</transition> </transition>
{{ !requested ? `Request ${this.type}?` : "Already requested" }} {{ !requested ? `Request ${type}?` : "Already requested" }}
</action-button> </action-button>
<action-button v-if="plexId && matched" @click="openInPlex"> <action-button
v-if="plexId && media?.exists_in_plex"
@click="openInPlex"
>
<IconPlay /> <IconPlay />
Open and watch in plex now! Open and watch in plex now!
</action-button> </action-button>
<action-button <action-button
v-if="credits && credits.cast && credits.cast.length" v-if="cast?.length"
:active="showCast" :active="showCast"
@click="() => (showCast = !showCast)" @click="() => (showCast = !showCast)"
> >
@@ -94,260 +101,219 @@
</div> </div>
<Description <Description
v-if="!loading && movie && movie.overview" v-if="!loading && media && media.overview"
:description="movie.overview" :description="media.overview"
/> />
<div class="movie__details" v-if="movie"> <div class="movie__details" v-if="media">
<Detail <Detail
v-if="movie.year" v-if="media.year"
title="Release date" title="Release date"
:detail="movie.year" :detail="media.year"
/> />
<Detail v-if="movie.rating" title="Rating" :detail="movie.rating" /> <Detail v-if="media.rating" title="Rating" :detail="media.rating" />
<Detail <Detail
v-if="movie.type == 'show'" v-if="media.type == ListTypes.Show"
title="Seasons" title="Seasons"
:detail="movie.seasons" :detail="media.seasons"
/> />
<Detail <Detail
v-if="movie.genres && movie.genres.length" v-if="media.genres && media.genres.length"
title="Genres" title="Genres"
:detail="movie.genres.join(', ')" :detail="media.genres.join(', ')"
/> />
<Detail <Detail
v-if=" v-if="
movie.production_status && media.production_status &&
movie.production_status !== 'Released' media.production_status !== 'Released'
" "
title="Production status" title="Production status"
:detail="movie.production_status" :detail="media.production_status"
/> />
<Detail <Detail
v-if="movie.runtime" v-if="media.runtime"
title="Runtime" title="Runtime"
:detail="humanMinutes(movie.runtime)" :detail="humanMinutes(media.runtime)"
/> />
</div> </div>
</div> </div>
<!-- TODO: change this classname, this is general --> <!-- TODO: change this classname, this is general -->
<div <div class="movie__admin" v-if="showCast && cast?.length">
class="movie__admin"
v-if="showCast && credits && credits.cast && credits.cast.length"
>
<Detail title="cast"> <Detail title="cast">
<CastList :cast="credits.cast" /> <CastList :cast="cast" />
</Detail> </Detail>
</div> </div>
</div> </div>
<!-- TORRENT LIST --> <!-- TORRENT LIST -->
<TorrentList <TorrentList
v-if="movie && admin" v-if="media && admin && showTorrents"
:show="showTorrents" class="torrents"
:query="title" :query="media?.title"
:tmdb_id="id" :tmdb_id="id"
:admin="admin"
></TorrentList> ></TorrentList>
</div> </div>
</section> </section>
</template> </template>
<script> <script setup lang="ts">
import { mapGetters } from "vuex"; import { ref, computed, defineProps } from "vue";
import img from "@/directives/v-image"; import { useStore } from "vuex";
import IconProfile from "@/icons/IconProfile";
import IconThumbsUp from "@/icons/IconThumbsUp";
import IconThumbsDown from "@/icons/IconThumbsDown";
import IconInfo from "@/icons/IconInfo";
import IconRequest from "@/icons/IconRequest";
import IconRequested from "@/icons/IconRequested";
import IconBinoculars from "@/icons/IconBinoculars";
import IconPlay from "@/icons/IconPlay";
import TorrentList from "@/components/TorrentList";
import CastList from "@/components/CastList";
import Detail from "@/components/popup/Detail";
import ActionButton from "@/components/popup/ActionButton";
import Description from "@/components/popup/Description";
import store from "@/store";
import LoadingPlaceholder from "@/components/ui/LoadingPlaceholder";
import { // import img from "@/directives/v-image";
import IconProfile from "@/icons/IconProfile.vue";
import IconThumbsUp from "@/icons/IconThumbsUp.vue";
import IconThumbsDown from "@/icons/IconThumbsDown.vue";
import IconInfo from "@/icons/IconInfo.vue";
import IconRequest from "@/icons/IconRequest.vue";
import IconRequested from "@/icons/IconRequested.vue";
import IconBinoculars from "@/icons/IconBinoculars.vue";
import IconPlay from "@/icons/IconPlay.vue";
import TorrentList from "@/components/torrent/TruncatedTorrentResults.vue";
import CastList from "@/components/CastList.vue";
import Detail from "@/components/popup/Detail.vue";
import ActionButton from "@/components/popup/ActionButton.vue";
import Description from "@/components/popup/Description.vue";
import LoadingPlaceholder from "@/components/ui/LoadingPlaceholder.vue";
import type { Ref, ComputedRef } from "vue";
import type {
IMovie,
IShow,
IMediaCredits,
ICast
} from "../../interfaces/IList";
import { ListTypes } from "../../interfaces/IList";
import { humanMinutes } from "../../utils";
import {
getMovie, getMovie,
getShow, getShow,
getPerson, getPerson,
getCredits, getMovieCredits,
getShowCredits,
request, request,
getRequestStatus, getRequestStatus,
watchLink watchLink
} from "@/api"; } from "../../api";
export default { interface Props {
// props: ['id', 'type'], id: number;
props: { type: ListTypes.Movie | ListTypes.Show;
id: {
required: true,
type: Number
},
type: {
required: false,
type: String
}
},
components: {
Description,
Detail,
ActionButton,
IconProfile,
IconThumbsUp,
IconThumbsDown,
IconRequest,
IconRequested,
IconInfo,
IconBinoculars,
IconPlay,
TorrentList,
CastList,
LoadingPlaceholder
},
directives: { img: img }, // TODO decide to remove or use
data() {
return {
ASSET_URL: "https://image.tmdb.org/t/p/",
ASSET_SIZES: ["w500", "w780", "original"],
movie: undefined,
title: undefined,
poster: undefined,
backdrop: undefined,
matched: false,
requested: false,
showTorrents: false,
showCast: false,
credits: [],
compact: false,
loading: true
};
},
watch: {
id: function (val) {
this.fetchByType();
},
backdrop: function (backdrop) {
if (backdrop != null) {
const style = {
backgroundImage:
"url(" + this.ASSET_URL + this.ASSET_SIZES[1] + backdrop + ")"
};
Object.assign(this.$refs.header.style, style);
}
}
},
computed: {
...mapGetters("user", ["loggedIn", "admin", "plexId"]),
numberOfTorrentResults: () => {
let numTorrents = store.getters["torrentModule/resultCount"];
return numTorrents !== null ? numTorrents + " results" : null;
}
},
methods: {
async fetchByType() {
try {
let response;
if (this.type === "movie") {
response = await getMovie(this.id, true, false);
} else if (this.type === "show") {
response = await getShow(this.id, false, false);
} else {
this.$router.push({ name: "404" });
} }
this.parseResponse(response); const props = defineProps<Props>();
} catch (error) { const ASSET_URL = "https://image.tmdb.org/t/p/";
this.$router.push({ name: "404" }); const ASSET_SIZES = ["w500", "w780", "original"];
}
// async get credits const media: Ref<IMovie | IShow> = ref();
getCredits(this.type, this.id).then(credits => (this.credits = credits)); const requested: Ref<boolean> = ref();
}, const showTorrents: Ref<boolean> = ref();
parseResponse(movie) { const showCast: Ref<boolean> = ref();
this.loading = false; const cast: Ref<ICast[]> = ref([]);
this.movie = { ...movie }; const compact: Ref<boolean> = ref();
this.title = movie.title; const loading: Ref<boolean> = ref();
this.poster = movie.poster; const backdropElement: Ref<HTMLElement> = ref();
this.backdrop = movie.backdrop;
this.matched = movie.exists_in_plex || false;
this.checkIfRequested(movie).then(status => (this.requested = status));
store.dispatch("documentTitle/updateTitle", movie.title); const store = useStore();
this.setPosterSrc();
}, const loggedIn = computed(() => store.getters["user/loggedIn"]);
async checkIfRequested(movie) { const admin = computed(() => store.getters["user/admin"]);
return await getRequestStatus(movie.id, movie.type); const plexId = computed(() => store.getters["user/plexId"]);
}, const poster = computed(() => computePoster());
setPosterSrc() {
const poster = this.$refs["poster-image"]; const numberOfTorrentResults = computed(() => {
if (this.poster == null) { const count = store.getters["torrentModule/resultCount"];
poster.src = "/assets/no-image.svg"; return count ? `${count} results` : null;
});
// On created functions
fetchMedia();
setBackdrop();
store.dispatch("torrentModule/setResultCount", null);
// End on create functions
function fetchMedia() {
if (!props.id || !props.type) {
console.error("Unable to fetch media, requires id & type");
return; return;
} }
poster.src = `${this.ASSET_URL}${this.ASSET_SIZES[0]}${this.poster}`; let apiFunction: Function;
}, let parameters: object;
humanMinutes(minutes) {
if (minutes instanceof Array) { if (props.type === ListTypes.Movie) {
minutes = minutes[0]; apiFunction = getMovie;
parameters = { checkExistance: true, credits: false };
} else if (props.type === ListTypes.Show) {
apiFunction = getShow;
parameters = { checkExistance: true, credits: false };
} }
const hours = Math.floor(minutes / 60); apiFunction(props.id, { ...parameters })
const minutesLeft = minutes - hours * 60; .then(setAndReturnMedia)
.then(media => getCredits(props.type))
if (minutesLeft == 0) { .then(credits => (cast.value = credits?.cast))
return hours > 1 ? `${hours} hours` : `${hours} hour`; .then(() => getRequestStatus(props.id, props.type))
} else if (hours == 0) { .then(requestStatus => (requested.value = requestStatus || false));
return `${minutesLeft} min`;
} }
return `${hours}h ${minutesLeft}m`; function getCredits(
}, type: ListTypes.Movie | ListTypes.Show
sendRequest() { ): Promise<IMediaCredits> {
request(this.id, this.type).then(resp => { if (type === ListTypes.Movie) {
if (resp.success) { return getMovieCredits(props.id);
this.requested = true; } else if (type === ListTypes.Show) {
return getShowCredits(props.id);
} }
});
}, return Promise.reject();
openInPlex() { }
watchLink(this.title, this.movie.year).then(
watchLink => (window.location = watchLink) function setAndReturnMedia(_media: IMovie | IShow) {
media.value = _media;
return _media;
}
const computePoster = () => {
if (!media.value) return "/assets/placeholder.png";
else if (!media.value?.poster) return "/assets/no-image.svg";
return `${ASSET_URL}${ASSET_SIZES[0]}${media.value.poster}`;
};
function setBackdrop() {
if (!media.value?.backdrop || !backdropElement.value?.style) return "";
const backdropURL = `${ASSET_URL}${ASSET_SIZES[1]}${media.value.backdrop}`;
backdropElement.value.style.backgroundImage = `url(${backdropURL})`;
}
function sendRequest() {
request(props.id, props.type).then(
resp => (requested.value = resp?.success || false)
); );
},
openTmdb() {
const tmdbType = this.type === "show" ? "tv" : this.type;
window.location.href =
"https://www.themoviedb.org/" + tmdbType + "/" + this.id;
} }
},
created() { function openInPlex() {
store.dispatch("torrentModule/setResultCount", null); return;
this.prevDocumentTitle = store.getters["documentTitle/title"]; }
this.fetchByType();
}, function openTmdb() {
beforeDestroy() { const tmdbType = props.type === ListTypes.Show ? "tv" : props.type;
store.dispatch("documentTitle/updateTitle", this.prevDocumentTitle); const tmdbURL = "https://www.themoviedb.org/" + tmdbType + "/" + props.id;
window.location.href = tmdbURL;
} }
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/loading-placeholder"; @import "src/scss/loading-placeholder";
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
@import "src/scss/main"; @import "src/scss/main";
header { header {
$duration: 0.2s; $duration: 0.2s;
transform: scaleY(1); transform: scaleY(1);
transition: height $duration ease; transition: height $duration ease;
@@ -388,9 +354,9 @@ header {
height: 100px; height: 100px;
} }
} }
} }
.movie__poster { .movie__poster {
display: none; display: none;
@include desktop { @include desktop {
@@ -405,9 +371,9 @@ header {
border-radius: 10px; border-radius: 10px;
} }
} }
} }
.movie { .movie {
&__wrap { &__wrap {
&--header { &--header {
align-items: center; align-items: center;
@@ -531,14 +497,23 @@ header {
} }
} }
} }
}
.fade-enter-active, .torrents {
.fade-leave-active { background-color: var(--background-color);
padding: 0 1rem;
@include mobile {
padding: 0 0.5rem;
}
}
}
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.4s; transition: opacity 0.4s;
} }
.fade-enter, .fade-enter,
.fade-leave-to { .fade-leave-to {
opacity: 0; opacity: 0;
} }
</style> </style>

View File

@@ -23,7 +23,7 @@
<img <img
class="person-item__img is-loaded" class="person-item__img is-loaded"
ref="poster-image" ref="poster-image"
src="/assets/placeholder.png" :src="poster"
/> />
</figure> </figure>
</header> </header>
@@ -51,150 +51,117 @@
<Detail <Detail
title="movies" title="movies"
:detail="`Credited in ${movieCredits.length} movies`" :detail="`Credited in ${creditedMovies.length} movies`"
v-if="credits" v-if="creditedShows.length"
> >
<CastList :cast="movieCredits" /> <CastList :cast="creditedMovies" />
</Detail> </Detail>
<Detail <Detail
title="shows" title="shows"
:detail="`Credited in ${showCredits.length} shows`" :detail="`Credited in ${creditedShows.length} shows`"
v-if="credits" v-if="creditedShows.length"
> >
<CastList :cast="showCredits" /> <CastList :cast="creditedShows" />
</Detail> </Detail>
</div> </div>
</section> </section>
</template> </template>
<script> <script setup lang="ts">
import img from "@/directives/v-image"; import { ref, computed, defineProps } from "vue";
import CastList from "@/components/CastList"; import img from "@/directives/v-image.vue";
import Detail from "@/components/popup/Detail"; import CastList from "@/components/CastList.vue";
import Description from "@/components/popup/Description"; import Detail from "@/components/popup/Detail.vue";
import LoadingPlaceholder from "@/components/ui/LoadingPlaceholder"; import Description from "@/components/popup/Description.vue";
import LoadingPlaceholder from "@/components/ui/LoadingPlaceholder.vue";
import { getPerson, getPersonCredits } from "../../api";
import type { Ref, ComputedRef } from "vue";
import type {
IPerson,
IPersonCredits,
ICast,
IMovie,
IShow
} from "../../interfaces/IList";
import { ListTypes } from "../../interfaces/IList";
import { getPerson, getPersonCredits } from "@/api"; interface Props {
id: number;
}
export default { const props = defineProps<Props>();
props: { const ASSET_URL = "https://image.tmdb.org/t/p/";
id: { const ASSET_SIZES = ["w500", "w780", "original"];
required: true,
type: Number
},
type: {
required: false,
type: String,
default: "person"
}
},
components: {
Detail,
Description,
CastList,
LoadingPlaceholder
},
directives: { img: img }, // TODO decide to remove or use
data() {
return {
ASSET_URL: "https://image.tmdb.org/t/p/",
ASSET_SIZES: ["w500", "w780", "original"],
person: undefined,
loading: true,
credits: undefined
};
},
watch: {
backdrop: function (backdrop) {
if (backdrop != null) {
const style = {
backgroundImage:
"url(" + this.ASSET_URL + this.ASSET_SIZES[1] + backdrop + ")"
};
Object.assign(this.$refs.header.style, style); const person: Ref<IPerson> = ref();
} const credits: Ref<IPersonCredits> = ref();
} const loading: Ref<boolean> = ref(false);
}, const creditedMovies: Ref<Array<IMovie | IShow>> = ref([]);
computed: { const creditedShows: Ref<Array<IMovie | IShow>> = ref([]);
age: function () {
if (!this.person || !this.person.birthday) { const poster: ComputedRef<string> = computed(() => computePoster());
return; const age: ComputedRef<string> = computed(() => {
} if (!person.value?.birthday) return;
const today = new Date().getFullYear(); const today = new Date().getFullYear();
const birthYear = new Date(this.person.birthday).getFullYear(); const birthYear = new Date(person.value.birthday).getFullYear();
return `${today - birthYear} years old`; return `${today - birthYear} years old`;
}, });
movieCredits: function () {
const { cast } = this.credits;
if (!cast) return;
return cast // On create functions
.filter(l => l.type === "movie") fetchPerson();
.filter((item, pos, self) => self.indexOf(item) == pos) //
.sort((a, b) => a.popularity < b.popularity);
},
showCredits: function () {
const { cast } = this.credits;
if (!cast) return;
const alreadyExists = (item, pos, self) => { function fetchPerson() {
const names = self.map(item => item.title); if (!props.id) {
return names.indexOf(item.title) == pos; console.error("Unable to fetch person, missing id!");
};
return cast
.filter(item => item.type === "show")
.filter(alreadyExists)
.sort((a, b) => a.popularity < b.popularity);
}
},
methods: {
parseResponse(person) {
this.loading = false;
this.person = { ...person };
this.title = person.title;
this.poster = person.poster;
if (person.credits) this.credits = person.credits;
this.setPosterSrc();
},
setPosterSrc() {
const poster = this.$refs["poster-image"];
if (this.poster == null) {
poster.src = "/assets/no-image.svg";
return; return;
} }
poster.src = `${this.ASSET_URL}${this.ASSET_SIZES[0]}${this.poster}`; getPerson(props.id)
.then(_person => (person.value = _person))
.then(() => getPersonCredits(person.value?.id))
.then(_credits => (credits.value = _credits))
.then(() => personCreditedFrom(credits.value?.cast));
} }
},
created() {
getPerson(this.id, false)
.then(this.parseResponse)
.catch(error => {
console.error(error);
this.$router.push({ name: "404" });
});
getPersonCredits(this.id) function sortPopularity(a: IMovie | IShow, b: IMovie | IShow): number {
.then(credits => (this.credits = credits)) return a.popularity < b.popularity ? 1 : -1;
.catch(error => {
console.error(error);
});
} }
};
function alreadyExists(item: IMovie | IShow, pos: number, self: any[]) {
const names = self.map(item => item.title);
return names.indexOf(item.title) === pos;
}
function personCreditedFrom(cast: Array<IMovie | IShow>): void {
creditedMovies.value = cast
.filter(credit => credit.type === ListTypes.Movie)
.filter(alreadyExists)
.sort(sortPopularity);
creditedShows.value = cast
.filter(credit => credit.type === ListTypes.Show)
.filter(alreadyExists)
.sort(sortPopularity);
}
const computePoster = () => {
if (!person.value) return "/assets/placeholder.png";
else if (!person.value?.poster) return "/assets/no-image.svg";
return `${ASSET_URL}${ASSET_SIZES[0]}${person.value.poster}`;
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/loading-placeholder"; @import "src/scss/loading-placeholder";
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
@import "src/scss/main"; @import "src/scss/main";
section.person { section.person {
overflow: hidden; overflow: hidden;
position: relative; position: relative;
padding: 40px; padding: 40px;
@@ -221,9 +188,9 @@ section.person {
top: -215px; top: -215px;
} }
} }
} }
header { header {
$duration: 0.2s; $duration: 0.2s;
transition: height $duration ease; transition: height $duration ease;
position: relative; position: relative;
@@ -268,10 +235,12 @@ header {
color: rgba(255, 255, 255, 0.8); color: rgba(255, 255, 255, 0.8);
font-size: 1.2rem; font-size: 1.2rem;
} }
} }
.person__poster { .person__poster {
display: block; display: block;
margin: auto;
width: fit-content;
border-radius: 10px; border-radius: 10px;
background-color: grey; background-color: grey;
animation: pulse 1s infinite ease-in-out; animation: pulse 1s infinite ease-in-out;
@@ -296,5 +265,5 @@ header {
max-width: 225px; max-width: 225px;
} }
} }
} }
</style> </style>

View File

@@ -0,0 +1,98 @@
<template>
<div>
<h3 class="settings__header">Change password</h3>
<form class="form">
<seasoned-input
placeholder="old password"
icon="Keyhole"
type="password"
v-model="oldPassword"
/>
<seasoned-input
placeholder="new password"
icon="Keyhole"
type="password"
v-model="newPassword"
/>
<seasoned-input
placeholder="repeat new password"
icon="Keyhole"
type="password"
v-model="newPasswordRepeat"
/>
<seasoned-button @click="changePassword">change password</seasoned-button>
</form>
<seasoned-messages v-model:messages="messages" />
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import SeasonedInput from "@/components/ui/SeasonedInput.vue";
import SeasonedButton from "@/components/ui/SeasonedButton.vue";
import SeasonedMessages from "@/components/ui/SeasonedMessages.vue";
import type { Ref } from "vue";
import type IErrorMessage from "../../interfaces/IErrorMessage";
interface ResetPasswordPayload {
old_password: string;
new_password: string;
}
const oldPassword: Ref<string> = ref("");
const newPassword: Ref<string> = ref("");
const newPasswordRepeat: Ref<string> = ref("");
const messages: Ref<IErrorMessage[]> = ref([]);
function clearMessages() {
messages.value = [];
}
function addWarningMessage(message: string, title?: string) {
messages.value.push({ message, title, type: "warning" });
}
function validate() {
return new Promise((resolve, reject) => {
if (!oldPassword.value || oldPassword?.value?.length === 0) {
addWarningMessage("Missing old password!", "Validation error");
return reject();
}
if (!newPassword.value || newPassword?.value?.length === 0) {
addWarningMessage("Missing new password!", "Validation error");
return reject();
}
if (newPassword.value !== newPasswordRepeat.value) {
addWarningMessage(
"Password and password repeat do not match!",
"Validation error"
);
return reject();
}
resolve(true);
});
}
// TODO seasoned-api /user/password-reset
async function changePassword() {
try {
validate();
} catch (error) {
console.log("not valid!");
return;
}
const body: ResetPasswordPayload = {
old_password: oldPassword.value,
new_password: newPassword.value
};
const options = {};
// fetch()
}
</script>

View File

@@ -0,0 +1,120 @@
<template>
<div>
<h3 class="settings__header">Plex account</h3>
<div v-if="!plexId">
<span class="info"
>Sign in to your plex account to get information about recently added
movies and to see your watch history</span
>
<form class="form">
<seasoned-input
placeholder="plex username"
type="email"
v-model="username"
/>
<seasoned-input
placeholder="plex password"
type="password"
v-model="password"
@enter="authenticatePlex"
>
</seasoned-input>
<seasoned-button @click="authenticatePlex"
>link plex account</seasoned-button
>
</form>
</div>
<div v-else>
<span class="info"
>Awesome, your account is already authenticated with plex! Enjoy viewing
your seasoned search history, plex watch history and real-time torrent
download progress.</span
>
<seasoned-button @click="unauthenticatePlex"
>un-link plex account</seasoned-button
>
</div>
<seasoned-messages v-model:messages="messages" />
</div>
</template>
<script setup lang="ts">
import { ref, computed, defineEmits } from "vue";
import { useStore } from "vuex";
import seasonedInput from "@/components/ui/SeasonedInput.vue";
import SeasonedButton from "@/components/ui/SeasonedButton.vue";
import SeasonedMessages from "@/components/ui/SeasonedMessages.vue";
import { linkPlexAccount, unlinkPlexAccount } from "../../api";
import type { Ref, ComputedRef } from "vue";
import type IErrorMessage from "../../interfaces/IErrorMessage";
interface Emit {
(e: "reload");
}
const username: Ref<string> = ref("");
const password: Ref<string> = ref("");
const messages: Ref<IErrorMessage[]> = ref([]);
const store = useStore();
const emit = defineEmits<Emit>();
const loggedIn: ComputedRef<boolean> = computed(
() => store.getters["user/loggedIn"]
);
const plexId: ComputedRef<boolean> = computed(
() => store.getters["user/plexId"]
);
const settings: ComputedRef<boolean> = computed(
() => store.getters["user/settings"]
);
async function authenticatePlex() {
let username = this.plexUsername;
let password = this.plexPassword;
const { success, message } = await linkPlexAccount(
username.value,
password.value
);
if (success) {
username.value = "";
password.value = "";
emit("reload");
}
messages.value.push({
type: success ? "success" : "error",
title: success ? "Authenticated with plex" : "Something went wrong",
message: message
});
}
async function unauthenticatePlex() {
const response = await unlinkPlexAccount();
if (response?.success) {
emit("reload");
}
messages.value.push({
type: response.success ? "success" : "error",
title: response.success
? "Unlinked plex account "
: "Something went wrong",
message: response.message
});
}
</script>
<style lang="scss" scoped>
.info {
display: block;
margin-bottom: 25px;
}
</style>

View File

@@ -0,0 +1,6 @@
<template>
<code
>Monitor active torrents requested. Requires authentication with owners plex
library!</code
>
</template>

View File

@@ -0,0 +1,157 @@
<template>
<div class="container" v-if="query?.length">
<h2 class="torrent-header-text">
Searching for: <span class="query">{{ query }}</span>
</h2>
<loader v-if="loading" type="section" />
<div v-else>
<div v-if="torrents.length > 0" class="torrent-table">
<torrent-table :torrents="torrents" @magnet="addTorrent" />
<slot />
</div>
<div v-else class="no-results">
<h2>No results found</h2>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, inject, defineProps } from "vue";
import { useStore } from "vuex";
import { sortableSize } from "../../utils";
import { searchTorrents, addMagnet } from "../../api";
import Loader from "@/components/ui/Loader.vue";
import TorrentTable from "@/components/torrent/TorrentTable.vue";
import type { Ref } from "vue";
import type ITorrent from "../../interfaces/ITorrent";
interface Props {
query: string;
tmdb_id?: number;
}
const loading: Ref<boolean> = ref(true);
const torrents: Ref<ITorrent[]> = ref([]);
const release_types: Ref<string[]> = ref(["all"]);
const props = defineProps<Props>();
const store = useStore();
const notifications: {
info;
success;
error;
} = inject("notifications");
fetchTorrents();
function fetchTorrents() {
loading.value = true;
searchTorrents(props.query)
.then(torrentResponse => (torrents.value = torrentResponse?.results))
.then(() => updateResultCountDisplay())
.finally(() => (loading.value = false));
}
function updateResultCountDisplay() {
store.dispatch("torrentModule/setResults", torrents.value);
store.dispatch(
"torrentModule/setResultCount",
torrents.value?.length || -1
);
}
function addTorrent(torrent: ITorrent) {
const { name, magnet } = torrent;
notifications.info({
title: "Adding torrent 🧲",
description: props.query,
timeout: 3000
});
addMagnet(magnet, name, props.tmdb_id)
.then(resp => {
notifications.success({
title: "Torrent added 🎉",
description: props.query,
timeout: 3000
});
})
.catch(resp => {
console.log("Error while adding torrent:", resp?.data);
notifications.error({
title: "Failed to add torrent 🙅‍♀️",
description: "Check console for more info",
timeout: 3000
});
});
}
</script>
<style lang="scss" scoped>
@import "src/scss/variables";
@import "src/scss/media-queries";
@import "src/scss/elements";
h2 {
font-size: 20px;
}
.toggle {
max-width: unset !important;
margin: 1rem 0;
}
.container {
background-color: $background-color;
}
.no-results {
display: flex;
padding-bottom: 2rem;
justify-content: center;
flex-direction: column;
width: 100%;
align-items: center;
}
.torrent-header-text {
font-weight: 300;
text-transform: uppercase;
font-size: 20px;
color: var(--text-color);
text-align: center;
margin: 0;
.query {
font-weight: 500;
white-space: pre;
}
@include mobile {
text-align: left;
}
}
.download {
&__icon {
fill: $text-color-70;
height: 1.2rem;
&:hover {
fill: $text-color;
cursor: pointer;
}
}
&.active &__icon {
fill: $green;
}
}
</style>

View File

@@ -0,0 +1,250 @@
<template>
<table>
<thead class="table__header noselect">
<tr>
<th
v-for="column in columns"
:key="column"
@click="sortTable(column)"
:class="column === selectedColumn ? 'active' : null"
>
{{ column }}
<span v-if="prevCol === column && direction"></span>
<span v-if="prevCol === column && !direction"></span>
</th>
</tr>
</thead>
<tbody>
<tr
v-for="torrent in torrents"
class="table__content"
:key="torrent.magnet"
>
<td @click="expand($event, torrent.name)">{{ torrent.name }}</td>
<td @click="expand($event, torrent.name)">{{ torrent.seed }}</td>
<td @click="expand($event, torrent.name)">{{ torrent.size }}</td>
<td @click="() => emit('magnet', torrent)" class="download">
<IconMagnet />
</td>
</tr>
</tbody>
</table>
</template>
<script setup lang="ts">
import { ref, defineProps, defineEmits } from "vue";
import IconMagnet from "@/icons/IconMagnet.vue";
import { sortableSize } from "../../utils";
import type { Ref } from "vue";
import type ITorrent from "../../interfaces/ITorrent";
interface Props {
torrents: Array<ITorrent>;
}
interface Emit {
(e: "magnet", torrent: ITorrent): void;
}
const props = defineProps<Props>();
const emit = defineEmits<Emit>();
const columns: string[] = ["name", "seed", "size", "add"];
const torrents: Ref<ITorrent[]> = ref(props.torrents);
const direction: Ref<boolean> = ref(false);
const selectedColumn: Ref<string> = ref(columns[0]);
const prevCol: Ref<string> = ref("");
function expand(event: MouseEvent, text: string) {
const elementClicked = event.target as HTMLElement;
const tableRow = elementClicked.parentElement;
const scopedStyleDataVariable = Object.keys(tableRow.dataset)[0];
const existingExpandedElement =
document.getElementsByClassName("expanded")[0];
const clickedSameTwice =
existingExpandedElement?.previousSibling?.isEqualNode(tableRow);
if (existingExpandedElement) {
existingExpandedElement.remove();
// Clicked the same element twice, remove and return
// not recreate and collapse
if (clickedSameTwice) return;
}
const expandedRow = document.createElement("tr");
const expandedCol = document.createElement("td");
expandedRow.dataset[scopedStyleDataVariable] = "";
expandedCol.dataset[scopedStyleDataVariable] = "";
expandedRow.className = "expanded";
expandedCol.innerText = text;
expandedCol.colSpan = 4;
expandedRow.appendChild(expandedCol);
tableRow.insertAdjacentElement("afterend", expandedRow);
}
function sortTable(col, sameDirection = false) {
if (prevCol.value === col && sameDirection === false) {
direction.value = !direction.value;
}
if (col === "name") sortName();
else if (col === "seed") sortSeed();
else if (col === "size") sortSize();
prevCol.value = col;
}
function sortName() {
const torrentsCopy = [...torrents.value];
if (direction.value) {
torrents.value = torrentsCopy.sort((a, b) => (a.name < b.name ? 1 : -1));
} else {
torrents.value = torrentsCopy.sort((a, b) => (a.name > b.name ? 1 : -1));
}
}
function sortSeed() {
const torrentsCopy = [...torrents.value];
if (direction.value) {
torrents.value = torrentsCopy.sort(
(a, b) => parseInt(a.seed) - parseInt(b.seed)
);
} else {
torrents.value = torrentsCopy.sort(
(a, b) => parseInt(b.seed) - parseInt(a.seed)
);
}
}
function sortSize() {
const torrentsCopy = [...torrents.value];
if (direction.value) {
torrents.value = torrentsCopy.sort(
(a, b) => sortableSize(a.size) - sortableSize(b.size)
);
} else {
torrents.value = torrentsCopy.sort(
(a, b) => sortableSize(b.size) - sortableSize(a.size)
);
}
}
</script>
<style lang="scss" scoped>
@import "src/scss/variables";
@import "src/scss/media-queries";
@import "src/scss/elements";
table {
border-spacing: 0;
margin-top: 0.5rem;
width: 100%;
// border-collapse: collapse;
border-radius: 0.5rem;
overflow: hidden;
}
th,
td {
border: 0.5px solid var(--background-color-40);
@include mobile {
white-space: nowrap;
padding: 0;
}
}
thead {
position: relative;
user-select: none;
-webkit-user-select: none;
color: var(--table-header-text-color);
text-transform: uppercase;
cursor: pointer;
background-color: var(--table-background-color);
// background-color: black;
// color: var(--color-green);
letter-spacing: 0.8px;
font-size: 1rem;
th:last-of-type {
padding-right: 0.4rem;
}
}
tbody {
// first column
tr td:first-of-type {
position: relative;
padding: 0 0.3rem;
cursor: default;
word-break: break-all;
border-left: 1px solid var(--table-background-color);
@include mobile {
max-width: 40vw;
overflow-x: hidden;
}
}
// all columns except first
tr td:not(td:first-of-type) {
text-align: center;
white-space: nowrap;
}
// last column
tr td:last-of-type {
vertical-align: middle;
cursor: pointer;
border-right: 1px solid var(--table-background-color);
svg {
width: 21px;
display: block;
margin: auto;
padding: 0.3rem 0;
fill: var(--text-color);
}
}
// alternate background color per row
tr:nth-child(even) {
background-color: var(--background-70);
}
// last element rounded corner border
tr:last-of-type {
td {
border-bottom: 1px solid var(--table-background-color);
}
td:first-of-type {
border-bottom-left-radius: 0.5rem;
}
td:last-of-type {
border-bottom-right-radius: 0.5rem;
}
}
}
.expanded {
padding: 0.25rem 1rem;
max-width: 100%;
border-left: 1px solid $text-color;
border-right: 1px solid $text-color;
border-bottom: 1px solid $text-color;
td {
white-space: normal;
word-break: break-all;
padding: 0.5rem 0.15rem;
width: 100%;
}
}
</style>

View File

@@ -0,0 +1,86 @@
<template>
<div>
<torrent-search-results
:query="query"
:tmdb_id="tmdb_id"
:class="{ truncated: truncated }"
><div
v-if="truncated"
class="load-more"
role="button"
@click="truncated = false"
>
<icon-arrow-down />
</div>
</torrent-search-results>
<div class="edit-query-btn-container">
<seasonedButton @click="openInTorrentPage"
>View on torrent page</seasonedButton
>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, inject, defineProps } from "vue";
import { useRouter } from "vue-router";
import TorrentSearchResults from "@/components/torrent/TorrentSearchResults.vue";
import SeasonedButton from "@/components/ui/SeasonedButton.vue";
import IconArrowDown from "@/icons/IconArrowDown.vue";
import type { Ref } from "vue";
interface Props {
query: string;
tmdb_id?: number;
}
const props = defineProps<Props>();
const router = useRouter();
const truncated: Ref<boolean> = ref(true);
function openInTorrentPage() {
if (!props.query?.length) {
router.push("/torrents");
return;
}
router.push({ path: "/torrents", query: { query: props.query } });
}
</script>
<style lang="scss" scoped>
:global(.truncated .torrent-table) {
position: relative;
max-height: 500px;
overflow-y: hidden;
}
.load-more {
position: absolute;
display: flex;
align-items: flex-end;
justify-content: center;
bottom: 0rem;
width: 100%;
height: 3rem;
cursor: pointer;
background: linear-gradient(
to top,
var(--background-color) 20%,
var(--background-0) 100%
);
}
svg {
height: 30px;
fill: var(--text-color);
}
.edit-query-btn-container {
display: flex;
justify-content: center;
padding: 1rem;
}
</style>

View File

@@ -4,36 +4,30 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
export default { import { ref, computed } from "vue";
data() {
return { let darkmode = ref(systemDarkModeEnabled());
darkmode: this.systemDarkModeEnabled() const darkmodeToggleIcon = computed(() => {
}; return darkmode.value ? "🌝" : "🌚";
}, });
methods: {
toggleDarkmode() { function toggleDarkmode() {
this.darkmode = !this.darkmode; darkmode.value = !darkmode.value;
document.body.className = this.darkmode ? "dark" : "light"; document.body.className = darkmode.value ? "dark" : "light";
}, }
systemDarkModeEnabled() {
function systemDarkModeEnabled() {
const computedStyle = window.getComputedStyle(document.body); const computedStyle = window.getComputedStyle(document.body);
if (computedStyle["colorScheme"] != null) { if (computedStyle["colorScheme"] != null) {
return computedStyle.colorScheme.includes("dark"); return computedStyle.colorScheme.includes("dark");
} }
return false; return false;
} }
},
computed: {
darkmodeToggleIcon() {
return this.darkmode ? "🌝" : "🌚";
}
}
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.darkToggle { .darkToggle {
height: 25px; height: 25px;
width: 25px; width: 25px;
cursor: pointer; cursor: pointer;
@@ -48,5 +42,5 @@ export default {
-moz-user-select: none; -moz-user-select: none;
-ms-user-select: none; -ms-user-select: none;
user-select: none; user-select: none;
} }
</style> </style>

View File

@@ -10,19 +10,22 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import { mapGetters, mapActions } from "vuex"; import { computed } from "vue";
import { useStore } from "vuex";
export default { const store = useStore();
computed: { ...mapGetters("hamburger", ["isOpen"]) },
methods: { ...mapActions("hamburger", ["toggle"]) } const isOpen = computed(() => store.getters["hamburger/isOpen"]);
}; const toggle = () => {
store.dispatch("hamburger/toggle");
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.nav__hamburger { .nav__hamburger {
display: block; display: block;
position: relative; position: relative;
width: var(--header-size); width: var(--header-size);
@@ -78,5 +81,5 @@ export default {
} }
} }
} }
} }
</style> </style>

View File

@@ -1,21 +1,45 @@
<template> <template>
<div class="loader"> <div :class="`loader type-${type}`">
<i class="loader--icon"> <i class="loader--icon">
<i class="loader--icon-spinner" /> <i class="loader--icon-spinner" />
</i> </i>
</div> </div>
</template>
<!--
TODO: fetch and display movie facts after 1.5 seconds while loading?
--></template>
<script setup lang="ts">
import { defineProps } from "vue";
enum LoaderHeightType {
Page = "page",
Section = "section"
}
interface Props {
type?: LoaderHeightType;
}
const { type = LoaderHeightType.Page } = defineProps<Props>();
</script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
.loader { .loader {
display: flex; display: flex;
width: 100%; width: 100%;
height: 30vh; height: 30vh;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
&.type-section {
height: 15vh;
}
&--icon { &--icon {
border: 2px solid $text-color-70; border: 2px solid $text-color-70;
border-radius: 50%; border-radius: 50%;
@@ -44,5 +68,5 @@
transform: rotate(360deg); transform: rotate(360deg);
} }
} }
} }
</style> </style>

View File

@@ -9,26 +9,18 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
export default { import { defineProps } from "vue";
props: {
count: { interface Props {
type: Number, count?: Number;
default: 1, lineClass?: String;
require: false top?: Number;
},
lineClass: {
type: String,
default: ""
},
top: {
type: Number,
default: 0
} }
}
}; const { count = 1, lineClass = "", top = 0 } = defineProps<Props>();
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/loading-placeholder"; @import "src/scss/loading-placeholder";
</style> </style>

View File

@@ -8,34 +8,28 @@
</button> </button>
</template> </template>
<script> <script setup lang="ts">
export default { import { ref, defineProps, defineEmits } from "vue";
name: "seasonedButton", import type { Ref } from "vue";
props: {
active: { interface Props {
type: Boolean, active?: Boolean;
default: false, fullWidth?: Boolean;
required: false
},
fullWidth: {
type: Boolean,
default: false,
required: false
} }
},
methods: { interface Emit {
emit() { (e: "click");
this.$emit("click");
} }
}
}; const props = defineProps<Props>();
const emit = defineEmits<Emit>();
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
button { button {
display: inline-block; display: inline-block;
border: 1px solid $text-color; border: 1px solid $text-color;
font-size: 11px; font-size: 11px;
@@ -80,5 +74,5 @@ button {
color: $background-color; color: $background-color;
} }
} }
} }
</style> </style>

View File

@@ -1,77 +1,82 @@
<template> <template>
<div class="group" :class="{ completed: value, focus }"> <div class="group" :class="{ completed: modelValue, focus }">
<component :is="inputIcon" v-if="inputIcon" /> <component :is="inputIcon" v-if="inputIcon" />
<input <input
class="input" class="input"
:type="tempType || type" :type="toggledType || type"
@input="handleInput"
v-model="inputValue"
:placeholder="placeholder" :placeholder="placeholder"
@keyup.enter="event => $emit('enter', event)" :value="modelValue"
@input="handleInput"
@keyup.enter="event => emit('enter', event)"
@focus="focus = true" @focus="focus = true"
@blur="focus = false" @blur="focus = false"
/> />
<i <i
v-if="value && type === 'password'" v-if="modelValue && type === 'password'"
@click="toggleShowPassword" @click="toggleShowPassword"
@keydown.enter="toggleShowPassword" @keydown.enter="toggleShowPassword"
class="show noselect" class="show noselect"
tabindex="0" tabindex="0"
>{{ tempType == "password" ? "show" : "hide" }}</i >{{ toggledType == "password" ? "show" : "hide" }}</i
> >
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import IconKey from "../../icons/IconKey"; import { ref, computed, defineProps, defineEmits } from "vue";
import IconEmail from "../../icons/IconEmail"; import IconKey from "@/icons/IconKey.vue";
import IconEmail from "@/icons/IconEmail.vue";
import IconBinoculars from "@/icons/IconBinoculars.vue";
import type { Ref } from "vue";
export default { interface Props {
components: { IconKey, IconEmail }, modelValue: string;
props: { placeholder: string;
placeholder: { type: String }, type?: string;
type: { type: String, default: "text" }, }
value: { type: String, default: undefined }
}, interface Emit {
data() { (e: "change");
return { (e: "enter");
inputValue: this.value || undefined, (e: "update:modelValue", value: string);
tempType: this.type, }
focus: false
}; const { placeholder, type = "text", modelValue } = defineProps<Props>();
}, const emit = defineEmits<Emit>();
computed: {
inputIcon() { const toggledType: Ref<string> = ref(type);
if (this.type === "password") return IconKey; const focus: Ref<boolean> = ref(false);
if (this.type === "email") return IconEmail;
const inputIcon = computed(() => {
if (type === "password") return IconKey;
if (type === "email") return IconEmail;
if (type === "torrents") return IconBinoculars;
return false; return false;
});
function handleInput(event: KeyboardEvent) {
const target = event?.target as HTMLInputElement;
if (!target) return;
emit("update:modelValue", target?.value);
} }
},
methods: { // Could we move this to component that injects ??
handleInput(event) { function toggleShowPassword() {
if (this.value !== undefined) { if (toggledType.value === "text") {
this.$emit("update:value", this.inputValue); toggledType.value = "password";
} else { } else {
this.$emit("change", this.inputValue, event); toggledType.value = "text";
}
},
toggleShowPassword() {
if (this.tempType === "text") {
this.tempType = "password";
} else {
this.tempType = "text";
} }
} }
}
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.group { .group {
display: flex; display: flex;
width: 100%; width: 100%;
position: relative; position: relative;
@@ -130,5 +135,5 @@ export default {
-webkit-user-select: none; -webkit-user-select: none;
user-select: none; user-select: none;
} }
} }
</style> </style>

View File

@@ -1,13 +1,13 @@
<template> <template>
<transition-group name="fade"> <transition-group name="fade">
<div <div
class="message" class="card"
v-for="(message, index) in reversedMessages" v-for="(message, index) in messages"
:key="`${index}-${message.title}-${message.type}}`" :key="`${index}-${message.title}-${message.type}}`"
:class="message.type || 'warning'" :class="message.type || 'warning'"
> >
<span class="pinstripe"></span> <span class="pinstripe"></span>
<div> <div class="content">
<h2 class="title"> <h2 class="title">
{{ message.title || defaultTitles[message.type] }} {{ message.title || defaultTitles[message.type] }}
</h2> </h2>
@@ -16,70 +16,67 @@
}}</span> }}</span>
</div> </div>
<button class="dismiss" @click="clicked(message)">X</button> <button class="dismiss" @click="dismiss(index)">X</button>
</div> </div>
</transition-group> </transition-group>
</template> </template>
<script> <script setup lang="ts">
export default { import { defineProps, defineEmits } from "vue";
props: { import type { Ref } from "vue";
messages: {
required: true, interface IErrorMessage {
type: Array title: string;
message: string;
type: "error" | "success" | "warning";
} }
},
data() { interface Props {
return { messages: IErrorMessage[];
defaultTitles: { }
interface Emit {
(e: "update:messages", messages: IErrorMessage[]);
}
const props = defineProps<Props>();
const emit = defineEmits<Emit>();
const defaultTitles = {
error: "Unexpected error", error: "Unexpected error",
warning: "Something went wrong", warning: "Something went wrong",
success: "",
undefined: "Something went wrong" undefined: "Something went wrong"
},
localMessages: [...this.messages]
}; };
},
computed: { function dismiss(index: number) {
reversedMessages() { props.messages.splice(index, 1);
return [...this.messages].reverse(); emit("update:messages", [...props.messages]);
} }
},
methods: {
clicked(e) {
const removedMessage = [...this.messages].filter(mes => mes !== e);
this.$emit("update:messages", removedMessage);
}
}
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
@import "src/scss/media-queries"; @import "src/scss/media-queries";
.fade-enter-active { .fade-active {
transition: opacity 0.4s; transition: opacity 0.4s;
} }
.fade-leave-active { .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
transition: opacity 0.1s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
opacity: 0; opacity: 0;
} }
.message { .card {
width: 100%; width: 100%;
max-width: 35rem; max-width: 35rem;
display: flex; display: flex;
margin-top: 1rem; margin-top: 0.8rem;
margin-bottom: 1rem;
color: $text-color-70; color: $text-color-70;
> div { .content {
margin: 10px 24px; margin: 0.4rem 1.2rem;
width: 100%; width: 100%;
}
.title { .title {
font-weight: 300; font-weight: 300;
@@ -89,18 +86,19 @@ export default {
color: $text-color; color: $text-color;
transition: color 0.5s ease; transition: color 0.5s ease;
} }
.message { .message {
font-weight: 300; font-weight: 400;
font-size: 1.2rem;
color: $text-color-70; color: $text-color-70;
transition: color 0.5s ease; transition: color 0.5s ease;
margin: 0.2rem 0 0.5rem; margin-bottom: 0.2rem;
} }
@include mobile-only { @include mobile-only {
> div {
margin: 6px 6px; margin: 6px 6px;
line-height: 1.3rem; line-height: 1.3rem;
}
h2 { h2 {
font-size: 1.1rem; font-size: 1.1rem;
} }
@@ -108,6 +106,7 @@ export default {
font-size: 0.9rem; font-size: 0.9rem;
} }
} }
}
.pinstripe { .pinstripe {
width: 0.5rem; width: 0.5rem;
@@ -161,5 +160,5 @@ export default {
background-color: $color-warning-highlight; background-color: $color-warning-highlight;
} }
} }
} }
</style> </style>

View File

@@ -4,53 +4,44 @@
v-for="option in options" v-for="option in options"
:key="option" :key="option"
class="toggle-button" class="toggle-button"
@click="toggle(option)" @click="toggleTo(option)"
:class="toggleValue === option ? 'selected' : null" :class="selected === option ? 'selected' : null"
> >
{{ option }} {{ option }}
</button> </button>
</div> </div>
</template> </template>
<script> <script setup lang="ts">
export default { import { ref, defineProps, defineEmits } from "vue";
props: { import type { Ref } from "vue";
options: {
Array, interface Props {
required: true options: string[];
}, selected?: string;
selected: {
type: String,
required: false,
default: undefined
} }
},
data() { interface Emit {
return { (e: "update:selected", selected: string);
toggleValue: this.selected || this.options[0] (e: "change");
};
},
methods: {
toggle(toggleValue) {
this.toggleValue = toggleValue;
if (this.selected !== undefined) {
this.$emit("update:selected", toggleValue);
this.$emit("change", toggleValue);
} else {
this.$emit("change", toggleValue);
} }
defineProps<Props>();
const emit = defineEmits<Emit>();
function toggleTo(option: string) {
emit("update:selected", option);
emit("change");
} }
}
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "src/scss/variables"; @import "src/scss/variables";
$background: $background-ui; $background: $background-ui;
$background-selected: $background-color-secondary; $background-selected: $background-color-secondary;
.toggle-container { .toggle-container {
width: 100%; width: 100%;
display: flex; display: flex;
overflow-x: scroll; overflow-x: scroll;
@@ -82,5 +73,5 @@ $background-selected: $background-color-secondary;
border-radius: 8px; border-radius: 8px;
} }
} }
} }
</style> </style>