From 1a0783c89cf47fd2307b99794f7bb626708aef9b Mon Sep 17 00:00:00 2001 From: Max Jacobson Date: Mon, 22 May 2023 17:09:02 -0400 Subject: [PATCH] Button to remove shows entirely (#1101) --- app/controllers/api/your_shows_controller.rb | 9 +++ app/javascript/components/AddShowButton.tsx | 64 ++++++++----------- .../components/RemoveShowButton.tsx | 42 ++++++++++++ app/javascript/pages/ChangelogPage.tsx | 1 + app/javascript/pages/CreditsPage.tsx | 4 +- app/javascript/pages/RoadmapPage.tsx | 1 - app/javascript/pages/ShowPage.tsx | 26 +++++--- app/services/remove_my_show.rb | 6 ++ config/routes.rb | 2 +- 9 files changed, 106 insertions(+), 49 deletions(-) create mode 100644 app/javascript/components/RemoveShowButton.tsx create mode 100644 app/services/remove_my_show.rb diff --git a/app/controllers/api/your_shows_controller.rb b/app/controllers/api/your_shows_controller.rb index 99efbc5f..05400701 100644 --- a/app/controllers/api/your_shows_controller.rb +++ b/app/controllers/api/your_shows_controller.rb @@ -50,6 +50,15 @@ def update end end + def destroy + authorize! { current_human.present? } + + show = Show.find_by(slug: params.require(:id)) + RemoveMyShow.call(show, current_human) + + render json: {} + end + private def search(my_shows) diff --git a/app/javascript/components/AddShowButton.tsx b/app/javascript/components/AddShowButton.tsx index 5318c8b4..67523e0e 100644 --- a/app/javascript/components/AddShowButton.tsx +++ b/app/javascript/components/AddShowButton.tsx @@ -1,49 +1,39 @@ -import { Show, YourRelationshipToShow, YourShow } from "../types" +import { Show, YourShow } from "../types" import { Button } from "./Button" import { FunctionComponent } from "react" interface Props { show: Show - yourRelationship?: YourRelationshipToShow token: string setYourShow: (yourShow: YourShow) => void } -export const AddShowButton: FunctionComponent = ({ - show, - token, - yourRelationship, - setYourShow, -}: Props) => { - if (yourRelationship) { - return - } else { - return ( - - ) - } + if (response.ok) { + const data: { your_show: YourShow } = await response.json() + setYourShow(data.your_show) + } else { + throw new Error("Could not add show") + } + }} + > + Add + + ) } diff --git a/app/javascript/components/RemoveShowButton.tsx b/app/javascript/components/RemoveShowButton.tsx new file mode 100644 index 00000000..d7d8b0fc --- /dev/null +++ b/app/javascript/components/RemoveShowButton.tsx @@ -0,0 +1,42 @@ +import { Button } from "./Button" +import { Show } from "../types" + +interface Props { + show: Show + token: string + onRemove: () => void +} + +export const RemoveShowButton = ({ show, token, onRemove }: Props) => { + return ( + + ) +} diff --git a/app/javascript/pages/ChangelogPage.tsx b/app/javascript/pages/ChangelogPage.tsx index 3b42edf6..8f6dde23 100644 --- a/app/javascript/pages/ChangelogPage.tsx +++ b/app/javascript/pages/ChangelogPage.tsx @@ -7,6 +7,7 @@ const changelog = ` But here's some highlights of when things happened. + 1. **May 22, 2023** — Humans can now remove a show from their "Your shows" list entirely. Seasoning will forget your "note to self" and the assigned status. It will still remember which episodes you've checked off that you've seen, and your season reviews. 1. **April 17, 2023** — Humans can optionally set a limit on how many shows they are currently watching 1. **March 31, 2023** — Show "last refreshed at" show data on season page and episode page 1. **February 23, 2023** — Automatically toggle shows from "waiting for more" to "next up" _only when there is a new episode available to watch_, not just when the season is announced. diff --git a/app/javascript/pages/CreditsPage.tsx b/app/javascript/pages/CreditsPage.tsx index 129d8519..0727cbdc 100644 --- a/app/javascript/pages/CreditsPage.tsx +++ b/app/javascript/pages/CreditsPage.tsx @@ -36,8 +36,8 @@ export const CreditsPage: FunctionComponent = () => {
  • The television icon you see up top is{" "} - by Shannon E Thomas, which I got from the defunct{" "} - to icon project. + by Shannon E Thomas, which I got from the now + defunct to icon project.
  • diff --git a/app/javascript/pages/RoadmapPage.tsx b/app/javascript/pages/RoadmapPage.tsx index 581bbecd..b0f48ad3 100644 --- a/app/javascript/pages/RoadmapPage.tsx +++ b/app/javascript/pages/RoadmapPage.tsx @@ -8,7 +8,6 @@ const roadmap = ` 1. Pagination on [the reviews page](/reviews) 1. Pagination on a person's reviews page, for example [mine](/maxjacobson/reviews) - 1. Possible to remove a show from your shows 1. Like button on reviews 1. Comments on reviews 1. Possible to edit reviews after publishing them -- body, star rating, visibility diff --git a/app/javascript/pages/ShowPage.tsx b/app/javascript/pages/ShowPage.tsx index c78eaffb..348655ce 100644 --- a/app/javascript/pages/ShowPage.tsx +++ b/app/javascript/pages/ShowPage.tsx @@ -5,6 +5,7 @@ import { ChooseShowStatusButton } from "../components/ChooseShowStatusButton" import { MoreInfo } from "../components/MoreInfo" import { NoteToSelf } from "../components/NoteToSelf" import { Poster } from "../components/Poster" +import { RemoveShowButton } from "../components/RemoveShowButton" import { SeasonsList } from "../components/SeasonsList" import { setHeadTitle } from "../hooks" import { ShowMetadata } from "../components/ShowMetadata" @@ -80,14 +81,23 @@ export const ShowPage = () => { <> {guest.authenticated && ( - { - setShowData({ loading: false, data: yourShow }) - }} - /> + {data.your_relationship ? ( + { + setShowData({ loading: false, data: { show: data.show } }) + }} + /> + ) : ( + { + setShowData({ loading: false, data: yourShow }) + }} + /> + )} )} diff --git a/app/services/remove_my_show.rb b/app/services/remove_my_show.rb new file mode 100644 index 00000000..628f3a18 --- /dev/null +++ b/app/services/remove_my_show.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +RemoveMyShow = lambda do |show, human| + my_show = MyShow.find_by(human:, show:) or raise ArgumentError, "No relationship to destroy" + my_show.destroy! +end diff --git a/config/routes.rb b/config/routes.rb index b841e39e..db4b4bf3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,7 @@ resource :guest, only: [:show] resources :magic_links, only: %i[create show], path: "/magic-links" resources :humans, only: [:create] - resources :your_shows, only: %i[index create update], path: "/your-shows" + resources :your_shows, only: %i[index create update destroy], path: "/your-shows" resources :your_seasons, only: %i[update], path: "/your-seasons" do resources :episodes, only: %i[update], controller: "your_episodes" end