-
Notifications
You must be signed in to change notification settings - Fork 180
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
Migrate Post Form to React #10408
base: main
Are you sure you want to change the base?
Migrate Post Form to React #10408
Conversation
Added the Datepicker! |
const [formPost, setFormPost] = useState(post); | ||
const [formTitle, setFormTitle] = useInputState(formPost?.title ?? ''); | ||
const [formBody, setFormBody] = useInputState(formPost?.body ?? ''); | ||
const [formTags, setFormTags] = useState(formPost?.tags_array ?? []); | ||
const [formIsStickied, setFormIsStickied] = useCheckboxState(formPost?.sticky ?? false); | ||
const [formShowOnHomePage, setFormShowOnHomePage] = useCheckboxState(formPost?.show_on_homepage ?? true); | ||
const [unstickAt, setUnstickAt] = useState(formPost?.unstick_at ?? null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels weird to have states for both the (form)post, and most of the properties of the post. Besides initializing the other states (which happens initially, so doesn't need formPost
to be a state), formPost
is only used to check whether we're creating or editing, get the id (if we're editing), and show the url at the end.
It seems like we could get rid of formPost
and instead just have 2 more states for the post id and url; then update those 2 states in the onSuccess
functions below.
{ postCreated && ( | ||
<Message positive> | ||
Post successfully created. View it | ||
{' '} | ||
<a href={formPost.url}>here</a> | ||
</Message> | ||
)} | ||
{ postUpdated && ( | ||
<Message positive> | ||
Post successfully updated. View it | ||
{' '} | ||
<a href={formPost.url}>here</a> | ||
</Message> | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you create a post then edit it, won't both messages be visible?
Side note: Formatting (indentation and spacing) seems to be off here, and I've noticed it in other PRs too.
Only a little jQuery deleted sadly.
TODO: That date picker how long something should be stickied for