Skip to content

Commit

Permalink
Save the post when selections happen
Browse files Browse the repository at this point in the history
  • Loading branch information
psrpinto committed Sep 18, 2024
1 parent ad2edd4 commit f6f0589
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/ui/flows/blog-post/SelectContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Message } from '@/bus/Message';
import { ContentBus } from '@/bus/ContentBus';
import { cleanHtml } from '@/parser/cleanHtml';
import { Post } from '@/api/Post';
import { useSessionContext } from '@/ui/session/SessionProvider';

enum section {
title = 1,
Expand All @@ -17,14 +18,15 @@ interface SectionContent {
}

export function SelectContent( props: { post: Post; onExit: () => void } ) {
const { onExit } = props;
const { post, onExit } = props;
const [ title, setTitle ] = useState< SectionContent >();
const [ content, setContent ] = useState< SectionContent >();
const [ date, setDate ] = useState< SectionContent >();
const [ lastClickedElement, setLastClickedElement ] = useState< string >();
const [ waitingForSelection, setWaitingForSelection ] = useState<
section | false
>( false );
const { apiClient, playgroundClient } = useSessionContext();

// Listen to click events coming from the content script.
useEffect( () => {
Expand Down Expand Up @@ -74,6 +76,18 @@ export function SelectContent( props: { post: Post; onExit: () => void } ) {
setLastClickedElement( undefined );
}, [ waitingForSelection, lastClickedElement ] );

// Save the post when selections happen.
useEffect( () => {
if ( ! title ) {
return;
}
apiClient
?.updatePost( post.id, {
title: title.cleanHtml ?? post.title.raw ?? '',
} )
.then( () => playgroundClient.goTo( post.link ) );
}, [ title ] );

Check warning on line 89 in src/ui/flows/blog-post/SelectContent.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'apiClient', 'playgroundClient', 'post.id', 'post.link', and 'post.title.raw'. Either include them or remove the dependency array

const isValid = title && date && content;
return (
<>
Expand Down

0 comments on commit f6f0589

Please sign in to comment.