Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Twitch clip pagination and clearing #170

Merged
merged 5 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add TwitchClipList
  • Loading branch information
vinceau committed Jun 10, 2023
commit 2f14f78b792471011e7874a9e0522408ded8f70e
44 changes: 44 additions & 0 deletions src/renderer/components/twitch/TwitchClipList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { TwitchClip } from "common/types";
import React from "react";
import { Grid, Input, Pagination, Segment } from "semantic-ui-react";

import { TwitchClipInfo } from "./TwitchClipInfo";

export const TwitchClipList = ({
clips,
onRemove,
clipsPerPage = 20,
}: {
clips: TwitchClip[];
onRemove: (key: string) => void;
clipsPerPage?: number;
}) => {
const totalPages = Math.ceil(clips.length / clipsPerPage);
const [activePage, setActivePage] = React.useState(1); // Pagination needs to start from 1

const startIndex = (activePage - 1) * clipsPerPage;
const endIndex = activePage * clipsPerPage;
const currentPageClips = clips.slice(startIndex, endIndex);

return (
<div>
{currentPageClips.map((v) => (
<TwitchClipInfo key={v.clipID} clip={v} onRemove={onRemove} />
))}
<div style={{ marginTop: 10, display: "flex", justifyContent: "space-between" }}>
<div>
Page {activePage} of {totalPages}
</div>
<Pagination
activePage={activePage}
onPageChange={(_e, { activePage }) => setActivePage(activePage as number)}
totalPages={totalPages}
ellipsisItem={null}
siblingRange={2}
boundaryRange={0}
/>
<div>{clips.length} clips</div>
</div>
</div>
);
};
1 change: 1 addition & 0 deletions src/renderer/components/twitch/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./TwitchClipInfo";
export * from "./TwitchClipList";
export * from "./TwitchConnectButton";
export * from "./TwitchUserStatus";
10 changes: 6 additions & 4 deletions src/renderer/views/settings/TwitchIntegration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useDispatch, useSelector } from "react-redux";
import { Header, Icon, Loader, Segment } from "semantic-ui-react";

import { Field, FormContainer, PageHeader, Toggle } from "@/components/Form";
import { TwitchClipInfo, TwitchConnectButton, TwitchUserStatus } from "@/components/twitch";
import { TwitchClipList, TwitchConnectButton, TwitchUserStatus } from "@/components/twitch";
import type { Dispatch, iRootState } from "@/store";

export const TwitchIntegration: React.FC = () => {
Expand Down Expand Up @@ -43,9 +43,11 @@ export const TwitchIntegration: React.FC = () => {

<h2>Clips</h2>
{allClips.length > 0 ? (
allClips.map((v) => (
<TwitchClipInfo key={v.clipID} clip={v} onRemove={(key) => dispatch.twitch.removeTwitchClip(key)} />
))
<TwitchClipList
clips={allClips}
clipsPerPage={TWITCH_CLIPS_PER_PAGE}
onRemove={(key) => dispatch.twitch.removeTwitchClip(key)}
/>
) : (
<Segment placeholder>
<Header icon>
Expand Down