next-realworld-example-app icon indicating copy to clipboard operation
next-realworld-example-app copied to clipboard

Factor out new article vs edit article pages

Open cirosantilli opened this issue 4 years ago • 1 comments

They are mostly copy paste now:

  • https://github.com/reck1ess/next-realworld-example-app/blob/66003772a42bf71c7b2771119121d4c9cf4b07d4/pages/editor/%5Bpid%5D.tsx
  • https://github.com/reck1ess/next-realworld-example-app/blob/66003772a42bf71c7b2771119121d4c9cf4b07d4/pages/editor/new.tsx

I'm giving it a shot but stuck at some point, I wanted to do a this.props from getInitialProps to check new at:

import ArticleEditor from "../../components/editor/ArticleEditor";

export default function PublishArticleEditor() {
  return (
    <ArticleEditor new />
  );
};

but I can't use this.props from there. Thinking is hard.

cirosantilli avatar May 20 '21 21:05 cirosantilli

OK, I managed it as in: https://github.com/cirosantilli/cirodown/commit/8c05857c8f93c5269c8505427bb1bcec44f80769 by creating a function that returns a function.

I also made it use ArticleAPI.update in the component rather than raw axios.

Now I'm going to convert to the better new API getStaticProps + getStaticPaths since my repo is a fullstack integration.

cirosantilli avatar May 21 '21 15:05 cirosantilli