-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Button to remove shows entirely (#1101)
- Loading branch information
1 parent
df6487b
commit 1a0783c
Showing
9 changed files
with
106 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Props> = ({ | ||
show, | ||
token, | ||
yourRelationship, | ||
setYourShow, | ||
}: Props) => { | ||
if (yourRelationship) { | ||
return <Button disabled={true}>Added</Button> | ||
} else { | ||
return ( | ||
<Button | ||
onClick={async () => { | ||
const response = await fetch(`/api/your-shows.json`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-SEASONING-TOKEN": token, | ||
export const AddShowButton: FunctionComponent<Props> = ({ show, token, setYourShow }: Props) => { | ||
return ( | ||
<Button | ||
onClick={async () => { | ||
const response = await fetch(`/api/your-shows.json`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-SEASONING-TOKEN": token, | ||
}, | ||
body: JSON.stringify({ | ||
show: { | ||
id: show.id, | ||
}, | ||
body: JSON.stringify({ | ||
show: { | ||
id: show.id, | ||
}, | ||
}), | ||
method: "POST", | ||
}) | ||
}), | ||
method: "POST", | ||
}) | ||
|
||
if (response.ok) { | ||
const data: { your_show: YourShow } = await response.json() | ||
setYourShow(data.your_show) | ||
} else { | ||
throw new Error("Could not add show") | ||
} | ||
}} | ||
> | ||
Add | ||
</Button> | ||
) | ||
} | ||
if (response.ok) { | ||
const data: { your_show: YourShow } = await response.json() | ||
setYourShow(data.your_show) | ||
} else { | ||
throw new Error("Could not add show") | ||
} | ||
}} | ||
> | ||
Add | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Button | ||
onClick={async () => { | ||
if ( | ||
!confirm( | ||
"Are you sure? This will lose track of your note to self and show status (but not reviews or which episodes you've seen" | ||
) | ||
) { | ||
return | ||
} | ||
|
||
// N.B. here we're specifying the show id rather than the my_shows id, because that's what we've expoed to the front-end | ||
// and it's non-ambiguous | ||
const response = await fetch(`/api/your-shows/${show.slug}.json`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-SEASONING-TOKEN": token, | ||
}, | ||
method: "DELETE", | ||
}) | ||
|
||
if (response.ok) { | ||
onRemove() | ||
} else { | ||
throw new Error("Could not remove show") | ||
} | ||
}} | ||
> | ||
Remove | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters