Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDispatch } from "react-redux";

import { joinArtists } from "../utils";
import { setQueue } from "../store/queue/actions";
import { Post } from "../store/list/types";
import { FeedListType, Post } from "../store/list/types";

import { Heart } from "react-feather";

Expand All @@ -17,6 +17,7 @@ type CardProps = {
onClick?: Function;
gkey?: string;
listName?: string;
type: FeedListType;
};

export default function Card(props: CardProps) {
Expand All @@ -30,7 +31,7 @@ export default function Card(props: CardProps) {
if (props.onClick !== undefined) {
props.onClick();
} else if (props.redirect === true) {
dispatch(setQueue(props.queue));
dispatch(setQueue(props.queue, props.type));
history.push("/video?=" + props.id);
}
}}
Expand Down
4 changes: 2 additions & 2 deletions src/components/feed-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useDispatch } from "react-redux";

import { joinArtists } from "../utils";
import { setQueue } from "../store/queue/actions";
import { Post } from "../store/list/types";
import { FeedListType, Post } from "../store/list/types";

import { Heart } from "react-feather";

Expand All @@ -29,7 +29,7 @@ export default function FeedCard(props: CardProps) {
if (props.onClick !== undefined) {
props.onClick();
} else if (props.redirect === true) {
dispatch(setQueue(props.queue));
dispatch(setQueue(props.queue, FeedListType.latest));
history.push("/video?=" + props.id);
}
};
Expand Down
9 changes: 8 additions & 1 deletion src/components/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ export const List = ({ title, type, redirect }: ListProps) => {
) : (
<VArray className="array" id={title.trim()} len={videoList.length}>
{videoList.map((vid) => (
<Card id={vid.id} key={vid.id + title.trim()} data={vid} queue={videoList} redirect={redirect} />
<Card
id={vid.id}
key={vid.id + title.trim()}
data={vid}
queue={videoList}
redirect={redirect}
type={type}
/>
))}
</VArray>
)}
Expand Down
21 changes: 14 additions & 7 deletions src/components/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ interface VideoProps {
}

export const Video = (props: VideoProps) => {
let preQueue = useSelector((state: FalconRootState) => state.queue.posts);
let [queue] = useState(preQueue);
let { type, posts } = useSelector((state: FalconRootState) => state.queue);
let [queue] = useState(posts);

if (preQueue.length === 0) {
if (posts.length === 0) {
if (window !== undefined) {
var home = window.location.protocol + "//" + window.location.host;
if (window.history.pushState) {
Expand All @@ -42,7 +42,7 @@ export const Video = (props: VideoProps) => {
let [currentIndex, changeIndex] = useState(
(() => {
if (props.id) {
return preQueue.map((e) => e.id).indexOf(props.id);
return posts.map((e) => e.id).indexOf(props.id);
}
return 0;
})()
Expand Down Expand Up @@ -105,9 +105,15 @@ export const Video = (props: VideoProps) => {
}, [currentIndex]);

let playNextVideo = useCallback(() => {
if (queue.length > 0 && currentIndex + 1 < queue.length) {
changeURLid(queue[currentIndex + 1].id);
changeIndex(currentIndex + 1);
if (queue.length > 0) {
if (currentIndex + 1 < queue.length) {
changeURLid(queue[currentIndex + 1].id);
changeIndex(currentIndex + 1);
} else {
// Fetch the songs of the current list type
// append the songs to the queue
// Play the next song
}
}
}, [queue, currentIndex]);

Expand Down Expand Up @@ -235,6 +241,7 @@ export const Video = (props: VideoProps) => {
id={vid.id}
key={vid.id + "Queue-xyppu"}
data={vid}
type={type}
className={"queueCard" + selectClass}
redirect={false}
onClick={() => {
Expand Down
7 changes: 5 additions & 2 deletions src/store/queue/action.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Post } from "../list/types";
import { FeedListType, Post } from "../list/types";

export type QueueAction = {
type: string;
payload: Post[];
payload: {
type: FeedListType;
posts: Post[];
};
};
6 changes: 3 additions & 3 deletions src/store/queue/actions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { QueueAction } from "./action.types";
import { Post } from "../list/types";
import { FeedListType, Post } from "../list/types";

export const setQueue = (list: Post[]): QueueAction => {
export const setQueue = (list: Post[], type: FeedListType): QueueAction => {
return {
type: "new queue",
payload: list,
payload: { type, posts: list },
};
};
8 changes: 6 additions & 2 deletions src/store/queue/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Reducer } from "redux";
import { FeedListType } from "../list/types";

import { QueueAction } from "./action.types";
import { QUEUE_ADD, QUEUE_RESET } from "./constants";
import { QueueState } from "./types";

let initialQueueState: QueueState = {
// TODO: Find a better way to represent no type state
// (Although this gets overwritten in the first update)
type: FeedListType.latest,
posts: [],
};

export const queueReducer: Reducer<QueueState, QueueAction> = (state = initialQueueState, action): QueueState => {
switch (action.type) {
case QUEUE_ADD:
return { posts: [...state.posts, ...action.payload] };
return { type: action.payload.type, posts: [...state.posts, ...action.payload.posts] };
case QUEUE_RESET:
return { posts: action.payload };
return { type: action.payload.type, posts: action.payload.posts };
default:
return state;
}
Expand Down
3 changes: 2 additions & 1 deletion src/store/queue/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Post } from "../list/types";
import { FeedListType, Post } from "../list/types";

export interface QueueState {
type: FeedListType;
posts: Post[];
}