2022-10-18 19:28:37 +00:00
|
|
|
import { Link, useLoaderData } from "@remix-run/react";
|
2023-08-06 16:10:55 +00:00
|
|
|
import { useState } from "react";
|
2022-10-18 19:28:37 +00:00
|
|
|
import IconAdd from "~/images/icon-add.svg";
|
|
|
|
import IconGridView from "~/images/icon-gridview.svg";
|
|
|
|
import IconListView from "~/images/icon-listview.svg";
|
2023-08-06 16:10:55 +00:00
|
|
|
import { API_URL } from "~/lib/constants";
|
2022-10-18 19:28:37 +00:00
|
|
|
import { API_KEY } from "~/lib/constants.server";
|
2023-08-06 16:10:55 +00:00
|
|
|
import { getPlaylists } from "~/lib/getPlaylists";
|
2022-10-18 19:28:37 +00:00
|
|
|
import type { Playlists } from "~/types/playlists";
|
2022-04-13 18:08:07 +00:00
|
|
|
|
2023-08-06 16:10:55 +00:00
|
|
|
export const loader = async () => {
|
2022-10-18 19:28:37 +00:00
|
|
|
const playlists = await getPlaylists(API_KEY);
|
2022-04-13 18:08:07 +00:00
|
|
|
|
2022-10-18 19:28:37 +00:00
|
|
|
return playlists;
|
2022-04-13 18:08:07 +00:00
|
|
|
};
|
|
|
|
|
2022-10-18 19:28:37 +00:00
|
|
|
type ViewStyle = "grid" | "list";
|
2022-04-13 18:08:07 +00:00
|
|
|
|
2022-10-18 19:28:37 +00:00
|
|
|
const Playlist = () => {
|
|
|
|
const playlists = useLoaderData<Playlists>();
|
2022-04-13 18:08:07 +00:00
|
|
|
const [viewStyle, setViewStyle] = useState<ViewStyle>("grid");
|
|
|
|
|
|
|
|
const handleSetViewstyle = (selectedViewStyle: ViewStyle) => {
|
|
|
|
setViewStyle(selectedViewStyle);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-10-18 19:28:37 +00:00
|
|
|
<>
|
2022-04-13 18:08:07 +00:00
|
|
|
<div className="boxed-content">
|
|
|
|
<div className="title-split">
|
|
|
|
<div className="title-bar">
|
|
|
|
<h1>Playlists</h1>
|
|
|
|
</div>
|
|
|
|
<div className="title-split-form">
|
2022-10-18 19:28:37 +00:00
|
|
|
<img
|
2022-04-13 18:08:07 +00:00
|
|
|
id="animate-icon"
|
|
|
|
// onClick="showForm()"
|
|
|
|
src={IconAdd}
|
2022-10-18 19:28:37 +00:00
|
|
|
width={35}
|
|
|
|
height={30}
|
2022-04-13 18:08:07 +00:00
|
|
|
alt="add-icon"
|
|
|
|
title="Subscribe to Playlists"
|
|
|
|
/>
|
|
|
|
<div className="show-form">
|
|
|
|
<form id="hidden-form" action="/playlist/" method="post">
|
|
|
|
{/* {% csrf_token %}
|
|
|
|
{{ subscribe_form }} */}
|
|
|
|
<button type="submit">Subscribe</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* <div id="notifications" data="playlist"></div> */}
|
|
|
|
<div className="view-controls">
|
|
|
|
<div className="toggle">
|
|
|
|
<span>Show subscribed only:</span>
|
|
|
|
<div className="toggleBox">
|
|
|
|
<input
|
|
|
|
id="show_subed_only"
|
|
|
|
// onClick="toggleCheckbox(this)"
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
|
|
|
{/* {% if not show_subed_only %} */}
|
2022-10-18 19:28:37 +00:00
|
|
|
<label htmlFor="show_subed_only" className="ofbtn">
|
2022-04-13 18:08:07 +00:00
|
|
|
Off
|
|
|
|
</label>
|
|
|
|
{/* {% else %} */}
|
2022-10-18 19:28:37 +00:00
|
|
|
<label htmlFor="show_subed_only" className="onbtn">
|
2022-04-13 18:08:07 +00:00
|
|
|
On
|
|
|
|
</label>
|
|
|
|
{/* {% endif %} */}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="view-icons">
|
2022-10-18 19:28:37 +00:00
|
|
|
<img
|
2022-04-13 18:08:07 +00:00
|
|
|
src={IconGridView}
|
|
|
|
width={35}
|
|
|
|
height={30}
|
|
|
|
onClick={() => handleSetViewstyle("grid")}
|
|
|
|
alt="grid view"
|
|
|
|
/>
|
2022-10-18 19:28:37 +00:00
|
|
|
<img
|
2022-04-13 18:08:07 +00:00
|
|
|
src={IconListView}
|
|
|
|
width={35}
|
|
|
|
height={30}
|
|
|
|
onClick={() => handleSetViewstyle("list")}
|
|
|
|
alt="list view"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={`playlist-list ${viewStyle}`}>
|
|
|
|
{/* {% if results %}
|
|
|
|
{% for playlist in results %} */}
|
2022-10-18 19:28:37 +00:00
|
|
|
{!playlists ? (
|
2022-04-13 18:08:07 +00:00
|
|
|
<h2>No playlists found...</h2>
|
|
|
|
) : (
|
2022-10-18 19:28:37 +00:00
|
|
|
playlists.data.map((playlist) => {
|
2022-04-13 18:08:07 +00:00
|
|
|
return (
|
2023-08-06 16:10:55 +00:00
|
|
|
<div key={playlist.playlist_id} className={`playlist-item ${viewStyle}`}>
|
2022-04-13 18:08:07 +00:00
|
|
|
<div className="playlist-thumbnail">
|
2022-10-18 19:28:37 +00:00
|
|
|
<Link to={playlist.playlist_id}>
|
2022-04-13 18:08:07 +00:00
|
|
|
<img
|
2022-10-18 19:28:37 +00:00
|
|
|
src={`${API_URL}/${playlist.playlist_thumbnail}`}
|
2022-04-13 18:08:07 +00:00
|
|
|
alt={`${playlist.playlist_id}-thumbnail`}
|
|
|
|
/>
|
2022-10-18 19:28:37 +00:00
|
|
|
</Link>
|
2022-04-13 18:08:07 +00:00
|
|
|
</div>
|
|
|
|
<div className={`playlist-desc ${viewStyle}`}>
|
|
|
|
<a href="{% url 'channel_id' playlist.source.playlist_channel_id %}">
|
|
|
|
<h3> {playlist.playlist_channel} </h3>
|
|
|
|
</a>
|
|
|
|
<a href="{% url 'playlist_id' playlist.source.playlist_id %}">
|
|
|
|
<h2> {playlist.playlist_name} </h2>
|
|
|
|
</a>
|
|
|
|
<p>Last refreshed: {playlist.playlist_last_refresh} </p>
|
2022-10-18 19:28:37 +00:00
|
|
|
|
|
|
|
{playlist.playlist_subscribed ? (
|
|
|
|
<button
|
|
|
|
className="unsubscribe"
|
|
|
|
type="button"
|
|
|
|
id="{{ playlist.source.playlist_id }}"
|
|
|
|
// onClick="unsubscribe(this.id)"
|
|
|
|
title="Unsubscribe from {{ playlist.source.playlist_name }}"
|
|
|
|
>
|
|
|
|
Unsubscribe
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
id="{{ playlist.source.playlist_id }}"
|
|
|
|
// onClick="subscribe(this.id)"
|
|
|
|
title="Subscribe to {{ playlist.source.playlist_name }}"
|
|
|
|
>
|
|
|
|
Subscribe
|
|
|
|
</button>
|
|
|
|
)}
|
2022-04-13 18:08:07 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-18 19:28:37 +00:00
|
|
|
</>
|
2022-04-13 18:08:07 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Playlist;
|