add favorit button in entry page

This commit is contained in:
X4Lo committed 2024-04-28 00:26:07 +01:00
1 parent 62056bdc98
commit 299f566b96
6 files changed
+119 -34

No files matched your search

+43 -12
View File
@@ -76,13 +76,27 @@ entryRouter.post('/', async (req, res) => {
res.status(201).json(entry);
});
// * PUT - REQUEST ENTRY UPDATE
// * PUT - ENTRY UPDATE
entryRouter.put('/:id', async (req, res) => {
const { id } = req.params;
const { favorit, hidden, watchlist } = req.body;
// getting the old entry
const oldEntry = await Entry.findByPk(id, {
include: [
// ? checking if the provied id is valid
const oldEntry = await Entry.findByPk(id);
if (!oldEntry)
return res.status(404).json({ message: `Entry with the provided id was not found` });
// ? updating
await oldEntry.update({
favorit: favorit,
watchlist: watchlist,
hidden: hidden
});
// ? returning a new entry with updated values
let includes = [
{ model: EntryId, as: 'entryId' },
{ model: EntryRating, as: 'entryRating' },
{ model: EntrySeen, as: 'entrySeen' },
@@ -94,21 +108,38 @@ entryRouter.put('/:id', async (req, res) => {
attributes: []
}
}
]
});
if (!oldEntry) {
// TODO 404 error
return;
}
];
// getting new data from TMDB
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);
if (data == null) return res.status(500).json({ message: `Counldn't fetch data from TMDB` });
// updating
// ? updating
await updateEntry(oldEntry, data);
// ? returning a new entry with updated values
let includes = [
{ model: EntryId, as: 'entryId' },
{ model: EntryRating, as: 'entryRating' },
+3
View File
@@ -24,6 +24,7 @@ async function saveEntry(data) {
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
is_tvseries: is_tvseries,
watchlist: true,
status: data.status,
genres: data.genre_ids,
@@ -99,6 +100,8 @@ async function saveEntry(data) {
episodes.push(savedEpisode);
}
// TODO fetch cast
savedSeason.setDataValue('episodes', episodes);
seasons.push(savedSeason)
}
@@ -30,17 +30,21 @@ export class EntryService {
}
// update entry
updateEntryById(entry: Entry) {
return this.http.post<Entry>(`${this.backend_apiUrl}/${this.apiAction}`, {
entry,
});
updateEntry(entry: Entry) {
return this.http.put<Entry>(
`${this.backend_apiUrl}/${this.apiAction}/${entry.id}`,
{
favorit: entry.favorit,
watchlist: entry.watchlist,
hidden: entry.hidden,
}
);
}
// update entry
refrechEntryById(entryId: number) {
return this.http.put<Entry>(
`${this.backend_apiUrl}/${this.apiAction}/${entryId}`,
[null]
return this.http.get<Entry>(
`${this.backend_apiUrl}/${this.apiAction}/${entryId}/refrech`
);
}
@@ -67,6 +67,11 @@
margin-top: 200px !important;
}
/* ! LEFT PART - SIDE INFO */
.left-col {
min-width: 240px;
}
.poster {
padding: px 10px 0 10px;
}
@@ -88,22 +93,27 @@
background-color: transparent !important;
}
/* ! DESCRIPTION */
.side-info strong {
color: var(--shz-blue-default);
}
/* ! RIGHT PART - DESCRIPTION */
.title {
color: rgba(0, 0, 0, 0.868);
font-weight: bolder;
font-size: 2.9rem !important;
}
[data-bs-theme=dark] .title {
color: white;
}
.right-col .entry-actions span {
color: black;
}
.side-info strong {
color: #008cff;
.right-col .entry-actions span:hover {
color: var(--shz-blue-default);
}
.btn-icon-only {
@@ -121,7 +131,7 @@
color: #008cff;
}
.interaction-btns {
/* .interaction-btns {
position: absolute;
top: 10px;
right: 15px;
@@ -133,4 +143,19 @@
padding-top: 0;
padding-bottom: 0;
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 class="container mt-5 content-wrapper main-container">
<div class="row">
<div class="col-md-3">
<div class="col-md-3 left-col">
<!-- Movie Poster -->
<div class="poster">
<img [src]="poster" alt="Movie Poster" class="img-fluid mb-3">
@@ -33,21 +33,24 @@
<!-- start watch history - item -->
<div class="accordion-item" *ngFor="let seen of entry.entrySeen">
<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.aria-controls]="'collapse' + seen.id">
{{seen.date_seen.toString().substring(0, 10)}}
{{seen.date_seen | dateFormat:"yyyy-MM-dd"}}
</button>
</h2>
<div id="collapse{{seen.id}}" class="accordion-collapse collapse"
[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 class="d-flex justify-content-end">
<button type="button" class="btn btn-icon-only">
<span class="material-symbols-outlined" (click)="removeEntrySeen(seen.id)">
delete_forever
</span>
<!-- TODO add edit button -->
</button>
</div>
</div>
@@ -61,13 +64,18 @@
</div>
<div class="col-md-8">
<div class="col-md-8 right-col">
<!-- 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>
<!-- 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()">
<span class="material-symbols-outlined">
visibility
@@ -112,7 +112,7 @@ export class EntryPageComponent implements OnInit {
if (!this.entry) return;
const dialogRef = this.dialog.open(SeenModalComponent, {
width: '400px',
width: '360px',
});
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() {
if (this.entry) {
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
@@ -278,7 +292,7 @@ export class EntryPageComponent implements OnInit {
if (episodeSeen == null) return;
const dialogRef = this.dialog.open(SeenModalComponent, {
width: '400px',
width: '360px',
data: {
watchDate: episodeSeen.date_seen,
watchedWith: episodeSeen.seen_with,