-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement queue and top recommendation
- Loading branch information
Showing
23 changed files
with
75,451 additions
and
9,448 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
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,41 @@ | ||
import { useUser } from "../store"; | ||
import { API_BASE } from "../common/constants"; | ||
|
||
// Cache | ||
const moviesById = {}; | ||
|
||
export async function fetchMovies(searchParams) { | ||
const response = await fetch(API_BASE + "/movies?" + (searchParams || "")); | ||
const data = await response.json(); | ||
for (const movie of data.movies) { | ||
moviesById[movie.id] = movie | ||
} | ||
return data | ||
} | ||
|
||
export async function fetchRecommendations(page) { | ||
const [user] = useUser(); | ||
const response = await fetch( | ||
`${API_BASE}/users/${user.email}/recommendations?page=${page || 1}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${user.token}`, | ||
}, | ||
}, | ||
); | ||
const data = await response.json(); | ||
for (const movie of data.movies) { | ||
moviesById[movie.id] = movie | ||
} | ||
return data | ||
} | ||
|
||
export async function fetchMovie(id) { | ||
if (!(id in moviesById)) { | ||
const response = await fetch(`${API_BASE}/movies/${id}`); | ||
const data = await response.json(); | ||
moviesById[id] = data.movie; | ||
} | ||
|
||
return moviesById[id]; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const BASE = "/nextflix-web" | ||
export const API_BASE = BASE + "/api" // for now | ||
export const IMG_BASE = "http://image.tmdb.org/t/p/" |
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,51 @@ | ||
import { useUser } from "../store"; | ||
import { | ||
ThumbsUp, | ||
ThumbsDown, | ||
} from "phosphor-solid"; | ||
|
||
function createLikePair(id) { | ||
const [user, { like, dislike }] = useUser(); | ||
|
||
const likes = () => id() in user.ratings && user.ratings[id()]; | ||
const dislikes = () => id() in user.ratings && !user.ratings[id()]; | ||
|
||
const Like = (props) => ( | ||
<button | ||
onClick={() => like(id())} | ||
classList={{ | ||
"bg-neutral-300": !likes(), | ||
"bg-green-500": likes(), | ||
}} | ||
class="aspect-square p-4 rounded-full group hover:bg-green-300 transition" | ||
> | ||
<ThumbsUp | ||
class="m-auto group-hover:-rotate-6 group-active:-rotate-12 transition" | ||
weight="duotone" | ||
color="white" | ||
size={props.size} | ||
/> | ||
</button> | ||
); | ||
const Dislike = (props) => ( | ||
<button | ||
onClick={() => dislike(id())} | ||
classList={{ | ||
"bg-neutral-300": !dislikes(), | ||
"bg-red-500": dislikes(), | ||
}} | ||
class="aspect-square p-4 rounded-full group hover:bg-red-300 transition" | ||
> | ||
<ThumbsDown | ||
class="m-auto group-hover:rotate-6 group-active:rotate-12 transition" | ||
weight="duotone" | ||
color="white" | ||
size={props.size} | ||
/> | ||
</button> | ||
); | ||
|
||
return [Like, Dislike] | ||
} | ||
|
||
export default createLikePair; |
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,8 @@ | ||
import { createResource } from "solid-js"; | ||
import { fetchMovie } from "../api"; | ||
|
||
function createMovie(id) { | ||
return createResource(id, fetchMovie)[0]; | ||
} | ||
|
||
export default createMovie; |
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,28 @@ | ||
import { createSignal, untrack } from "solid-js"; | ||
import { createStore } from "solid-js/store"; | ||
import { fetchRecommendations } from "../api"; | ||
|
||
export function createRecommendations() { | ||
const [store, setStore] = createStore({ | ||
fetching: false, | ||
page: 0, | ||
pages: 1, | ||
movies: [], | ||
}); | ||
|
||
async function loadMore() { | ||
setStore({ fetching: true, page: untrack(() => store.page + 1) }); | ||
const response = await fetchRecommendations(store.page); | ||
console.log(response.page) | ||
setStore({ | ||
fetching: false, | ||
pages: response.pages, | ||
movies: untrack(() => [...store.movies, ...response.movies]), | ||
}); | ||
} | ||
|
||
// Load first batch of recommendations | ||
loadMore(); | ||
|
||
return [store, loadMore]; | ||
} |
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
Oops, something went wrong.