New interfaces defined
This commit is contained in:
5
src/interfaces/IErrorMessage.ts
Normal file
5
src/interfaces/IErrorMessage.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export default interface IErrorMessage {
|
||||||
|
title: string;
|
||||||
|
message: string;
|
||||||
|
type: "error" | "success" | "warning";
|
||||||
|
}
|
||||||
@@ -1,10 +1,27 @@
|
|||||||
export interface IList {
|
export interface IList {
|
||||||
results: Array<IMovie | IShow | IPerson | IRequest>;
|
results: ListResults;
|
||||||
page: number;
|
page: number;
|
||||||
total_results: number;
|
total_results: number;
|
||||||
total_pages: number;
|
total_pages: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IMediaCredits {
|
||||||
|
cast: Array<ICast>;
|
||||||
|
crew: Array<ICrew>;
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPersonCredits {
|
||||||
|
cast: Array<IMovie | IShow>;
|
||||||
|
crew: Array<ICrew>;
|
||||||
|
id: number;
|
||||||
|
type?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type MediaTypes = IMovie | IShow | IPerson | IRequest;
|
||||||
|
export type CreditTypes = ICast | ICrew;
|
||||||
|
export type ListResults = Array<MediaTypes>;
|
||||||
|
|
||||||
export enum ListTypes {
|
export enum ListTypes {
|
||||||
Movie = "movie",
|
Movie = "movie",
|
||||||
Show = "show",
|
Show = "show",
|
||||||
@@ -25,6 +42,7 @@ export interface IMovie {
|
|||||||
backdrop: string;
|
backdrop: string;
|
||||||
release_date: string | Date;
|
release_date: string | Date;
|
||||||
rating: number;
|
rating: number;
|
||||||
|
popularity?: number;
|
||||||
type: ListTypes.Movie;
|
type: ListTypes.Movie;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,17 +53,25 @@ export interface IShow {
|
|||||||
overview: string;
|
overview: string;
|
||||||
poster: string;
|
poster: string;
|
||||||
backdrop: string;
|
backdrop: string;
|
||||||
|
seasons?: number;
|
||||||
|
episodes?: number;
|
||||||
|
popularity?: number;
|
||||||
|
genres?: Array<string>;
|
||||||
|
production_status?: string;
|
||||||
|
runtime?: Array<number>;
|
||||||
|
exists_in_plex?: boolean;
|
||||||
type: ListTypes.Show;
|
type: ListTypes.Show;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPerson {
|
export interface IPerson {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
name: string;
|
||||||
poster: string;
|
poster: string;
|
||||||
birthday: string | null;
|
birthday: string | null;
|
||||||
deathday: string | null;
|
deathday: string | null;
|
||||||
known_for_department: string;
|
known_for_department: string;
|
||||||
adult: boolean;
|
adult: boolean;
|
||||||
|
type: ListTypes.Person;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRequest extends IMovie {
|
export interface IRequest extends IMovie {
|
||||||
@@ -54,3 +80,22 @@ export interface IRequest extends IMovie {
|
|||||||
status: string | RequestTypes;
|
status: string | RequestTypes;
|
||||||
user_agent: string;
|
user_agent: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICast {
|
||||||
|
character: string;
|
||||||
|
gender: number;
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
profile_path: string | null;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ICrew {
|
||||||
|
department: string;
|
||||||
|
gender: number;
|
||||||
|
id: number;
|
||||||
|
job: string;
|
||||||
|
name: string;
|
||||||
|
profile_path: string | null;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|||||||
6
src/interfaces/INavigationIcon.ts
Normal file
6
src/interfaces/INavigationIcon.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export default interface INavigationIcon {
|
||||||
|
title: string;
|
||||||
|
route: string;
|
||||||
|
icon: any;
|
||||||
|
requiresAuth?: boolean;
|
||||||
|
}
|
||||||
6
src/interfaces/ISection.ts
Normal file
6
src/interfaces/ISection.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import type { IList } from "./IList";
|
||||||
|
|
||||||
|
export default interface ISection {
|
||||||
|
title: string;
|
||||||
|
apiFunction: (page: number) => Promise<IList>;
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
export enum PopupTypes {
|
import type { MediaTypes } from "./IList";
|
||||||
Movie = "movie",
|
// export enum PopupTypes {
|
||||||
Show = "show",
|
// Movie = "movie",
|
||||||
Person = "person"
|
// Show = "show",
|
||||||
}
|
// Person = "person"
|
||||||
|
// }
|
||||||
|
|
||||||
// export interface IPopupOpen {
|
// export interface IPopupOpen {
|
||||||
// id: string | number;
|
// id: string | number;
|
||||||
@@ -11,6 +12,6 @@ export enum PopupTypes {
|
|||||||
|
|
||||||
export interface IStatePopup {
|
export interface IStatePopup {
|
||||||
id: number | null;
|
id: number | null;
|
||||||
type: PopupTypes | null;
|
type: MediaTypes | null;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { PopupTypes } from "../interfaces/IStatePopup";
|
import router from "../routes";
|
||||||
|
import { ListTypes } from "../interfaces/IList";
|
||||||
import type { IStatePopup } from "../interfaces/IStatePopup";
|
import type { IStatePopup } from "../interfaces/IStatePopup";
|
||||||
|
|
||||||
const removeIncludedQueryParams = (params, key) => {
|
const removeIncludedQueryParams = (params, key) => {
|
||||||
@@ -6,26 +7,29 @@ const removeIncludedQueryParams = (params, key) => {
|
|||||||
return params;
|
return params;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function paramsToObject(entries) {
|
||||||
|
const result = {};
|
||||||
|
for (const [key, value] of entries) {
|
||||||
|
// each 'entry' is a [key, value] tupple
|
||||||
|
result[key] = value;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
const updateQueryParams = (id: number | null = null, type: string = "") => {
|
const updateQueryParams = (id: number | null = null, type: string = "") => {
|
||||||
let params = new URLSearchParams(window.location.search);
|
let params = new URLSearchParams(window.location.search);
|
||||||
params = removeIncludedQueryParams(params, "movie");
|
params = removeIncludedQueryParams(params, "movie");
|
||||||
params = removeIncludedQueryParams(params, "show");
|
params = removeIncludedQueryParams(params, "show");
|
||||||
params = removeIncludedQueryParams(params, "person");
|
params = removeIncludedQueryParams(params, "person");
|
||||||
|
|
||||||
if (id && type in PopupTypes) {
|
if (id && type) {
|
||||||
params.append(type, id.toString());
|
params.append(type, id.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = `${window.location.protocol}//${window.location.hostname}${
|
router.push({
|
||||||
window.location.port ? `:${window.location.port}` : ""
|
path: window.location.pathname,
|
||||||
}${window.location.pathname}${params.toString().length ? `?${params}` : ""}`;
|
query: paramsToObject(params.entries())
|
||||||
|
});
|
||||||
if (window.preventPushState) {
|
|
||||||
window.history.replaceState({}, "search", url);
|
|
||||||
window.preventPushState = false;
|
|
||||||
} else {
|
|
||||||
window.history.pushState({}, "search", url);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const state: IStatePopup = {
|
const state: IStatePopup = {
|
||||||
@@ -63,6 +67,17 @@ export default {
|
|||||||
close: ({ commit }) => {
|
close: ({ commit }) => {
|
||||||
commit("SET_CLOSE");
|
commit("SET_CLOSE");
|
||||||
updateQueryParams(); // reset
|
updateQueryParams(); // reset
|
||||||
|
},
|
||||||
|
resetStateFromUrlQuery: ({ commit }, query: any) => {
|
||||||
|
let { movie, show, person } = query;
|
||||||
|
movie = !isNaN(movie) ? Number(movie) : movie;
|
||||||
|
show = !isNaN(show) ? Number(show) : show;
|
||||||
|
person = !isNaN(person) ? Number(person) : person;
|
||||||
|
|
||||||
|
if (movie) commit("SET_OPEN", { id: movie, type: "movie" });
|
||||||
|
else if (show) commit("SET_OPEN", { id: show, type: "show" });
|
||||||
|
else if (person) commit("SET_OPEN", { id: person, type: "person" });
|
||||||
|
else commit("SET_CLOSE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user