-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add sessions to favorites (#18)
* feat: Add sessions to favorites * feat: Ajout de session favoris * feat: Filtre des sessions favorites * fix: Problème de merge --------- Co-authored-by: Thomas DA ROCHA <[email protected]>
- Loading branch information
1 parent
4f3e90c
commit eee438b
Showing
6 changed files
with
142 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Data } from "@lenra/app-server"; | ||
|
||
export class Favorite extends Data { | ||
/** | ||
* | ||
* @param {string[]} sessions | ||
* @param {boolean} filter | ||
* @param {user} user | ||
*/ | ||
constructor(sessions, user, filter = false) { | ||
super(); | ||
this.user = user; | ||
this.sessions = sessions; | ||
this.filter = filter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Favorite } from "../classes/Favorite.js"; | ||
|
||
/** | ||
* | ||
* @param {import("@lenra/app-server").props} props | ||
* @param {import("@lenra/app-server").event} _event | ||
* @param {import("@lenra/app-server").Api} api | ||
*/ | ||
export async function toggleFavorite(props, _event, api) { | ||
const [fav] = await api.data.find(Favorite, { user: "@me" }) | ||
if (!fav) return api.data.createDoc(new Favorite([props.session], "@me")); | ||
|
||
if (fav.sessions.includes(props.session)) fav.sessions = fav.sessions.filter(s => s !== props.session); | ||
else fav.sessions.push(props.session); | ||
await api.data.updateDoc(fav); | ||
} | ||
|
||
/** | ||
* | ||
* @param {import("@lenra/app-server").props} props | ||
* @param {import("@lenra/app-server").event} _event | ||
* @param {import("@lenra/app-server").Api} api | ||
*/ | ||
export async function toggleFavoriteFilter(props, _event, api) { | ||
console.log("_event", _event); | ||
const [fav] = await api.data.find(Favorite, { user: "@me" }) | ||
if (!fav) return api.data.createDoc(new Favorite([], "@me", true)); | ||
fav.filter = !fav.filter; | ||
await api.data.updateDoc(fav); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters