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 Shoko episodeID Copy Button / Trim Descriptions #1091

Merged
merged 4 commits into from
Oct 4, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/components/Collection/CleanDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo } from 'react';
import cx from 'classnames';
import { trim } from 'lodash';

import { useSettingsQuery } from '@/core/react-query/settings/queries';

Expand Down Expand Up @@ -69,7 +70,7 @@ const CleanDescription = React.memo(({ altText, className, text }: Props) => {
lines.push(cleanedText.substring(prevPos));
}
LinkRegex.lastIndex = 0;
return lines.join('');
return trim(lines.join(''), '\n ');
}, [text, filterDescription]);

// Fallback to alt text if modified text is empty
Expand Down
19 changes: 17 additions & 2 deletions src/components/Collection/Episode/EpisodeDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { mdiCalendarMonthOutline, mdiClockOutline, mdiOpenInNew, mdiStarHalfFull } from '@mdi/js';
import { mdiCalendarMonthOutline, mdiClipboardOutline, mdiClockOutline, mdiOpenInNew, mdiStarHalfFull } from '@mdi/js';
import { Icon } from '@mdi/react';
import { toNumber } from 'lodash';

import { convertTimeSpanToMs, dayjs } from '@/core/util';
import { convertTimeSpanToMs, copyToClipboard, dayjs } from '@/core/util';

import type { EpisodeType } from '@/core/types/api/episode';

Expand All @@ -13,6 +13,10 @@ const getDuration = (duration: string) => {
return `${intMinutes} minutes`;
};

const handleCopyToClipboard = (id: string) => {
copyToClipboard(id, 'Shoko Episode ID').catch(console.error);
};

function EpisodeDetails({ episode }: { episode: EpisodeType }) {
return (
<div className="flex max-h-52 grow flex-col gap-y-4 overflow-hidden">
Expand Down Expand Up @@ -51,6 +55,17 @@ function EpisodeDetails({ episode }: { episode: EpisodeType }) {
{episode.AniDB?.Rating.Votes}
&nbsp;Votes)
</div>
<div
className="flex cursor-pointer items-center gap-x-2"
onClick={() => handleCopyToClipboard(episode.IDs.ID.toString())}
>
<Icon
className="hidden text-panel-icon-action lg:inline"
path={mdiClipboardOutline}
size={1}
/>
Copy ShokoID
</div>
{episode.AniDB?.ID && (
<a href={`https://anidb.net/episode/${episode.AniDB?.ID}`} target="_blank" rel="noopener noreferrer">
<div className="flex items-center gap-x-2 text-panel-text-primary">
Expand Down
6 changes: 3 additions & 3 deletions src/components/Collection/Episode/EpisodeFiles.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useState } from 'react';
import {
mdiContentCopy,
mdiClipboardOutline,
mdiDatabaseSearchOutline,
mdiFileDocumentMultipleOutline,
mdiLoading,
Expand Down Expand Up @@ -82,7 +82,7 @@ const EpisodeFiles = ({ anidbSeriesId, episodeFiles, episodeId, seriesId }: Prop
});

const handleCopyToClipboard = (id: string) => {
copyToClipboard(id, 'ShokoID').catch(console.error);
copyToClipboard(id, 'Shoko File ID').catch(console.error);
};

if (!episodeFiles.length || episodeFiles.length < 1) {
Expand Down Expand Up @@ -136,7 +136,7 @@ const EpisodeFiles = ({ anidbSeriesId, episodeFiles, episodeId, seriesId }: Prop
>
<Icon
className="hidden text-panel-icon-action lg:inline"
path={mdiContentCopy}
path={mdiClipboardOutline}
size={1}
/>
Copy ShokoID
Expand Down
2 changes: 1 addition & 1 deletion src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const copyToClipboard = async (text: string, entityName?: string) => {
} else {
copy(text);
}
if (entityName) toast.success(`${entityName} has been copied to clipboard!`);
if (entityName) toast.success(`${entityName} has been copied to the clipboard!`);
} catch (error) {
if (entityName) toast.error(`${entityName} copy failed!`);
throw error;
Expand Down