add favorit button in entry page
This commit is contained in:
1 parent
62056bdc98
commit
299f566b96
6 files changed
+130
-45
No files matched your search
@@ -76,39 +76,70 @@ entryRouter.post('/', async (req, res) => {
|
|||||||
res.status(201).json(entry);
|
res.status(201).json(entry);
|
||||||
});
|
});
|
||||||
|
|
||||||
// * PUT - REQUEST ENTRY UPDATE
|
|
||||||
|
// * PUT - ENTRY UPDATE
|
||||||
entryRouter.put('/:id', async (req, res) => {
|
entryRouter.put('/:id', async (req, res) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
const { favorit, hidden, watchlist } = req.body;
|
||||||
|
|
||||||
// getting the old entry
|
// ? checking if the provied id is valid
|
||||||
const oldEntry = await Entry.findByPk(id, {
|
const oldEntry = await Entry.findByPk(id);
|
||||||
include: [
|
|
||||||
{ model: EntryId, as: 'entryId' },
|
if (!oldEntry)
|
||||||
{ model: EntryRating, as: 'entryRating' },
|
return res.status(404).json({ message: `Entry with the provided id was not found` });
|
||||||
{ model: EntrySeen, as: 'entrySeen' },
|
|
||||||
{
|
// ? updating
|
||||||
model: Genre,
|
await oldEntry.update({
|
||||||
as: 'genres',
|
favorit: favorit,
|
||||||
attributes: ['id'],
|
watchlist: watchlist,
|
||||||
through: {
|
hidden: hidden
|
||||||
attributes: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
if (!oldEntry) {
|
|
||||||
// TODO 404 error
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// getting new data from TMDB
|
// ? returning a new entry with updated values
|
||||||
|
let includes = [
|
||||||
|
{ model: EntryId, as: 'entryId' },
|
||||||
|
{ model: EntryRating, as: 'entryRating' },
|
||||||
|
{ model: EntrySeen, as: 'entrySeen' },
|
||||||
|
{
|
||||||
|
model: Genre,
|
||||||
|
as: 'genres',
|
||||||
|
attributes: ['id'],
|
||||||
|
through: {
|
||||||
|
attributes: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' });
|
||||||
|
|
||||||
|
const entry = await Entry.findByPk(id, {
|
||||||
|
include: includes
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(201).json(entry);
|
||||||
|
});
|
||||||
|
|
||||||
|
// * GET - REQUEST ENTRY UPDATE
|
||||||
|
entryRouter.get('/:id/refrech', async (req, res) => {
|
||||||
|
const { id } = req.params;
|
||||||
|
|
||||||
|
// ? checking if the provied id is valid
|
||||||
|
const oldEntry = await Entry.findByPk(id);
|
||||||
|
|
||||||
|
if (!oldEntry)
|
||||||
|
return res.status(404).json({ message: `Entry id not found` });
|
||||||
|
|
||||||
|
|
||||||
|
// ? getting new data from TMDB
|
||||||
const data = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries);
|
const data = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries);
|
||||||
|
|
||||||
if (data == null) return res.status(500).json({ message: `Counldn't fetch data from TMDB` });
|
if (data == null) return res.status(500).json({ message: `Counldn't fetch data from TMDB` });
|
||||||
|
|
||||||
|
|
||||||
// updating
|
// ? updating
|
||||||
await updateEntry(oldEntry, data);
|
await updateEntry(oldEntry, data);
|
||||||
|
|
||||||
|
// ? returning a new entry with updated values
|
||||||
let includes = [
|
let includes = [
|
||||||
{ model: EntryId, as: 'entryId' },
|
{ model: EntryId, as: 'entryId' },
|
||||||
{ model: EntryRating, as: 'entryRating' },
|
{ model: EntryRating, as: 'entryRating' },
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const Episode = require('../models/Episode.js');
|
|||||||
|
|
||||||
async function saveEntry(data) {
|
async function saveEntry(data) {
|
||||||
if (data == null) return;
|
if (data == null) return;
|
||||||
|
|
||||||
// creating the object
|
// creating the object
|
||||||
var is_tvseries = data.release_date == null ? true : false;
|
var is_tvseries = data.release_date == null ? true : false;
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ async function saveEntry(data) {
|
|||||||
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
|
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
|
||||||
|
|
||||||
is_tvseries: is_tvseries,
|
is_tvseries: is_tvseries,
|
||||||
|
watchlist: true,
|
||||||
status: data.status,
|
status: data.status,
|
||||||
|
|
||||||
genres: data.genre_ids,
|
genres: data.genre_ids,
|
||||||
@@ -99,6 +100,8 @@ async function saveEntry(data) {
|
|||||||
episodes.push(savedEpisode);
|
episodes.push(savedEpisode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO fetch cast
|
||||||
|
|
||||||
savedSeason.setDataValue('episodes', episodes);
|
savedSeason.setDataValue('episodes', episodes);
|
||||||
seasons.push(savedSeason)
|
seasons.push(savedSeason)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,17 +30,21 @@ export class EntryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update entry
|
// update entry
|
||||||
updateEntryById(entry: Entry) {
|
updateEntry(entry: Entry) {
|
||||||
return this.http.post<Entry>(`${this.backend_apiUrl}/${this.apiAction}`, {
|
return this.http.put<Entry>(
|
||||||
entry,
|
`${this.backend_apiUrl}/${this.apiAction}/${entry.id}`,
|
||||||
});
|
{
|
||||||
|
favorit: entry.favorit,
|
||||||
|
watchlist: entry.watchlist,
|
||||||
|
hidden: entry.hidden,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update entry
|
// update entry
|
||||||
refrechEntryById(entryId: number) {
|
refrechEntryById(entryId: number) {
|
||||||
return this.http.put<Entry>(
|
return this.http.get<Entry>(
|
||||||
`${this.backend_apiUrl}/${this.apiAction}/${entryId}`,
|
`${this.backend_apiUrl}/${this.apiAction}/${entryId}/refrech`
|
||||||
[null]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,11 @@
|
|||||||
margin-top: 200px !important;
|
margin-top: 200px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ! LEFT PART - SIDE INFO */
|
||||||
|
.left-col {
|
||||||
|
min-width: 240px;
|
||||||
|
}
|
||||||
|
|
||||||
.poster {
|
.poster {
|
||||||
padding: px 10px 0 10px;
|
padding: px 10px 0 10px;
|
||||||
}
|
}
|
||||||
@@ -88,22 +93,27 @@
|
|||||||
background-color: transparent !important;
|
background-color: transparent !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ! DESCRIPTION */
|
.side-info strong {
|
||||||
|
color: var(--shz-blue-default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ! RIGHT PART - DESCRIPTION */
|
||||||
.title {
|
.title {
|
||||||
color: rgba(0, 0, 0, 0.868);
|
color: rgba(0, 0, 0, 0.868);
|
||||||
font-weight: bolder;
|
font-weight: bolder;
|
||||||
font-size: 2.9rem !important;
|
font-size: 2.9rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[data-bs-theme=dark] .title {
|
[data-bs-theme=dark] .title {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.right-col .entry-actions span {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
.side-info strong {
|
.right-col .entry-actions span:hover {
|
||||||
color: #008cff;
|
color: var(--shz-blue-default);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-icon-only {
|
.btn-icon-only {
|
||||||
@@ -121,7 +131,7 @@
|
|||||||
color: #008cff;
|
color: #008cff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.interaction-btns {
|
/* .interaction-btns {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
right: 15px;
|
right: 15px;
|
||||||
@@ -133,4 +143,19 @@
|
|||||||
padding-top: 0;
|
padding-top: 0;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
width: 50px;
|
width: 50px;
|
||||||
|
} */
|
||||||
|
|
||||||
|
/* * favorit button */
|
||||||
|
.btn-icon-only-favorite {
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right-col .entry-actions .favorite:hover span {
|
||||||
|
color: var(--shz-red-danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.right-col .entry-actions .favorite span {
|
||||||
|
color: var(--shz-gold-1);
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="container mt-5 content-wrapper main-container">
|
<div class="container mt-5 content-wrapper main-container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-3">
|
<div class="col-md-3 left-col">
|
||||||
<!-- Movie Poster -->
|
<!-- Movie Poster -->
|
||||||
<div class="poster">
|
<div class="poster">
|
||||||
<img [src]="poster" alt="Movie Poster" class="img-fluid mb-3">
|
<img [src]="poster" alt="Movie Poster" class="img-fluid mb-3">
|
||||||
@@ -33,21 +33,24 @@
|
|||||||
<!-- start watch history - item -->
|
<!-- start watch history - item -->
|
||||||
<div class="accordion-item" *ngFor="let seen of entry.entrySeen">
|
<div class="accordion-item" *ngFor="let seen of entry.entrySeen">
|
||||||
<h2 class="accordion-header" id="heading{{seen.id}}">
|
<h2 class="accordion-header" id="heading{{seen.id}}">
|
||||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
|
<button class="accordion-button collapsed" type=" button" data-bs-toggle="collapse"
|
||||||
[attr.data-bs-target]="'#collapse'+seen.id" aria-expanded="false"
|
[attr.data-bs-target]="'#collapse'+seen.id" aria-expanded="false"
|
||||||
[attr.aria-controls]="'collapse' + seen.id">
|
[attr.aria-controls]="'collapse' + seen.id">
|
||||||
{{seen.date_seen.toString().substring(0, 10)}}
|
{{seen.date_seen | dateFormat:"yyyy-MM-dd"}}
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<div id="collapse{{seen.id}}" class="accordion-collapse collapse"
|
<div id="collapse{{seen.id}}" class="accordion-collapse collapse"
|
||||||
[attr.aria-labelledby]="'heading' + seen.id" data-bs-parent="#accordionWatchHistory">
|
[attr.aria-labelledby]="'heading' + seen.id" data-bs-parent="#accordionWatchHistory">
|
||||||
<div class="accordion-body"> <strong>Seen With:</strong><br>{{seen.seen_with.split(", ").join("\n")}}
|
<div class="accordion-body" *ngIf="seen.seen_with.length != 0">
|
||||||
|
<strong>Seen With:</strong><br>
|
||||||
|
{{seen.seen_with}}
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
<button type="button" class="btn btn-icon-only">
|
<button type="button" class="btn btn-icon-only">
|
||||||
<span class="material-symbols-outlined" (click)="removeEntrySeen(seen.id)">
|
<span class="material-symbols-outlined" (click)="removeEntrySeen(seen.id)">
|
||||||
delete_forever
|
delete_forever
|
||||||
</span>
|
</span>
|
||||||
|
<!-- TODO add edit button -->
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -61,13 +64,18 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-8">
|
<div class="col-md-8 right-col">
|
||||||
<!-- Movie Title -->
|
<!-- Movie Title -->
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center ">
|
||||||
<h2 class="title">{{this.entry.title}}</h2>
|
<h2 class="title">{{this.entry.title}}</h2>
|
||||||
|
|
||||||
<!-- Interraction buttons -->
|
<!-- Interraction buttons -->
|
||||||
<div class="row">
|
<div class="row entry-actions">
|
||||||
|
<button class="btn btn-icon-only-favorite wh-48" (click)="toggleFavorite()"
|
||||||
|
[ngClass]="{ 'favorite': entry.favorit }">
|
||||||
|
<span class="material-symbols-outlined">{{ entry.favorit ? 'workspace_premium' : 'license' }}</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
<button class="btn btn-icon-only-success wh-48" *ngIf="!entry.is_tvseries" (click)="openEntrySeenModal()">
|
<button class="btn btn-icon-only-success wh-48" *ngIf="!entry.is_tvseries" (click)="openEntrySeenModal()">
|
||||||
<span class="material-symbols-outlined">
|
<span class="material-symbols-outlined">
|
||||||
visibility
|
visibility
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ export class EntryPageComponent implements OnInit {
|
|||||||
if (!this.entry) return;
|
if (!this.entry) return;
|
||||||
|
|
||||||
const dialogRef = this.dialog.open(SeenModalComponent, {
|
const dialogRef = this.dialog.open(SeenModalComponent, {
|
||||||
width: '400px',
|
width: '360px',
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Seen dialog opened');
|
console.log('Seen dialog opened');
|
||||||
@@ -183,6 +183,20 @@ export class EntryPageComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleFavorite() {
|
||||||
|
this.entry.favorit = !this.entry.favorit;
|
||||||
|
this.entryService.updateEntry(this.entry).subscribe({
|
||||||
|
next: (entry) => {
|
||||||
|
console.log(`Entry updated: `, entry);
|
||||||
|
this.entry = entry;
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.log(`Error updating entry: `, error);
|
||||||
|
this.entry.favorit = !this.entry.favorit;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
showAddToListModal() {
|
showAddToListModal() {
|
||||||
if (this.entry) {
|
if (this.entry) {
|
||||||
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
|
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
|
||||||
@@ -278,7 +292,7 @@ export class EntryPageComponent implements OnInit {
|
|||||||
if (episodeSeen == null) return;
|
if (episodeSeen == null) return;
|
||||||
|
|
||||||
const dialogRef = this.dialog.open(SeenModalComponent, {
|
const dialogRef = this.dialog.open(SeenModalComponent, {
|
||||||
width: '400px',
|
width: '360px',
|
||||||
data: {
|
data: {
|
||||||
watchDate: episodeSeen.date_seen,
|
watchDate: episodeSeen.date_seen,
|
||||||
watchedWith: episodeSeen.seen_with,
|
watchedWith: episodeSeen.seen_with,
|
||||||
|
|||||||
Reference in new issue
Block a user