Skip to content

Commit

Permalink
feat: add content prop to watchlist and readlist button components
Browse files Browse the repository at this point in the history
  • Loading branch information
olexh committed Aug 20, 2024
1 parent 3addbad commit 05c7a90
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/components/readlist-button/readlist-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface Props {
disabled?: boolean;
content_type: 'novel' | 'manga';
read?: API.Read;
content?: API.Manga | API.Novel;
size?: 'sm' | 'md';
}

Expand Down Expand Up @@ -63,6 +64,7 @@ const Component = ({
content_type,
disabled,
read: readProp,
content: contentProp,
size,
}: Props) => {
const { openModal } = useModalContext();
Expand All @@ -79,24 +81,23 @@ const Component = ({
{
slug,
},
{ enabled: !disabled && content_type === 'manga' },
{ enabled: !disabled && content_type === 'manga' && !contentProp },
);

const { data: novel } = useNovelInfo(
{
slug,
},
{ enabled: !disabled && content_type === 'novel' },
{ enabled: !disabled && content_type === 'novel' && !contentProp },
);

const { mutate: addRead } = useAddRead();

const read = readProp || (readQuery && !readError ? readQuery : undefined);
const content = contentProp || manga || novel;

const openReadEditModal = () => {
if (manga || novel) {
const content = manga || novel;

if (content) {
openModal({
content: (
<ReadEditModal
Expand Down
15 changes: 12 additions & 3 deletions src/components/watchlist-button/watchlist-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Props {
additional?: boolean;
disabled?: boolean;
watch?: API.Watch;
anime?: API.Anime;
size?: 'sm' | 'md';
}

Expand Down Expand Up @@ -56,7 +57,13 @@ const OPTIONS = [
})),
];

const Component = ({ slug, disabled, watch: watchProp, size }: Props) => {
const Component = ({
slug,
disabled,
watch: watchProp,
anime: animeProp,
size,
}: Props) => {
const { openModal } = useModalContext();

const { data: watchQuery, isError: watchError } = useWatch(
Expand All @@ -65,17 +72,19 @@ const Component = ({ slug, disabled, watch: watchProp, size }: Props) => {
},
{ enabled: !disabled && !watchProp },
);
const { data: anime } = useAnimeInfo(
const { data: animeQuery } = useAnimeInfo(
{
slug,
},
{ enabled: !disabled },
{ enabled: !disabled && !animeProp },
);
const { mutate: addWatch } = useAddWatch();

const watch =
watchProp || (watchQuery && !watchError ? watchQuery : undefined);

const anime = animeProp || (animeQuery ? animeQuery : undefined);

const openWatchEditModal = () => {
if (anime) {
openModal({
Expand Down
2 changes: 2 additions & 0 deletions src/features/franchise/franchise-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const FranchiseItem: FC<Props> = ({ content }) => {
{content.data_type === 'anime' && (
<WatchlistButton
slug={content.slug}
anime={content}
watch={content.watch && content.watch[0]}
size="md"
/>
Expand All @@ -59,6 +60,7 @@ const FranchiseItem: FC<Props> = ({ content }) => {
<ReadlistButton
content_type={content.data_type}
slug={content.slug}
content={content}
read={content.read && content.read[0]}
size="md"
/>
Expand Down

0 comments on commit 05c7a90

Please sign in to comment.