2023-09-11 10:03:49 +00:00
|
|
|
import { Form, useLoaderData, useParams, redirect } from "react-router-dom";
|
|
|
|
import PageHeader from "../Components/PageHeader";
|
|
|
|
import { requestEdit } from "../APIcalls.mjs";
|
|
|
|
|
|
|
|
export async function action({request,params}){
|
|
|
|
const formData = await request.formData()
|
|
|
|
const data = Object.fromEntries(formData)
|
|
|
|
data.id=parseInt(params.storyId)
|
|
|
|
console.dir(data)
|
|
|
|
await requestEdit(data,'story')
|
|
|
|
return redirect(`/story/${params.storyId}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function EditStory(){
|
|
|
|
const { storyId } = useParams()
|
|
|
|
const { stories } = useLoaderData()
|
|
|
|
const storyData = stories.find(row=>row.id==storyId)
|
|
|
|
|
|
|
|
|
|
|
|
return(
|
2023-09-12 14:27:51 +00:00
|
|
|
<div id="page-container">
|
|
|
|
<PageHeader super={`Story #${storyData.id}`} heading="EDIT" url="/story" id={storyId}/>
|
2023-09-11 10:03:49 +00:00
|
|
|
<Form method="post" id="story-form">
|
2023-09-12 09:38:45 +00:00
|
|
|
<label> Title:
|
2023-09-11 10:03:49 +00:00
|
|
|
<input
|
|
|
|
placeholder='title'
|
|
|
|
aria-label="Title"
|
|
|
|
type="text"
|
|
|
|
name="title"
|
|
|
|
defaultValue={storyData.title}
|
|
|
|
/>
|
2023-09-12 09:38:45 +00:00
|
|
|
</label>
|
|
|
|
<label> Wordcount:
|
2023-09-11 10:03:49 +00:00
|
|
|
<input
|
|
|
|
placeholder='1000'
|
|
|
|
aria-label="Wordcount"
|
|
|
|
type="number"
|
|
|
|
step="1"
|
|
|
|
name="word_count"
|
2023-09-11 12:44:24 +00:00
|
|
|
defaultValue={storyData.word_count}
|
2023-09-11 10:03:49 +00:00
|
|
|
/>
|
2023-09-12 09:38:45 +00:00
|
|
|
</label>
|
|
|
|
<div id="bottom-button-container">
|
2023-09-11 10:03:49 +00:00
|
|
|
<button type="submit">SAVE</button>
|
|
|
|
<button type="button">CANCEL</button>
|
2023-09-12 09:38:45 +00:00
|
|
|
</div>
|
|
|
|
|
2023-09-11 10:03:49 +00:00
|
|
|
</Form>
|
|
|
|
|
2023-09-12 14:27:51 +00:00
|
|
|
</div>
|
2023-09-11 10:03:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
}
|