feat: Implemented Favouriting for a user
Co-Authored-By: Tadios Temesgen <tt2022@ic.ac.uk>
This commit is contained in:
@@ -8,7 +8,25 @@ export const load: PageServerLoad = async ({ depends, locals: { supabase } }) =>
|
||||
.select("*, study_space_images(*), study_space_hours(*)");
|
||||
if (err) error(500, "Failed to load study spaces");
|
||||
|
||||
const {
|
||||
data: { session }
|
||||
} = await supabase.auth.getSession();
|
||||
|
||||
// Fetch this user’s favourites
|
||||
let favouriteIds: string[] = [];
|
||||
if (session?.user?.id) {
|
||||
const { data: favs, error: favErr } = await supabase
|
||||
.from("favourite_study_spaces")
|
||||
.select("study_space_id")
|
||||
.eq("user_id", session.user.id);
|
||||
if (!favErr && favs) {
|
||||
favouriteIds = favs.map((f) => f.study_space_id);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
studySpaces
|
||||
studySpaces,
|
||||
session,
|
||||
favouriteIds
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user