From f5cbc598620b92dbb3a467136fcb8f13b0fe6baf Mon Sep 17 00:00:00 2001 From: Graeme Fulton Date: Fri, 7 Jun 2024 12:06:00 -0400 Subject: [PATCH] initial interview template, add interviews/tools to userpostsid query --- .../editorHooks/libs/getCreatePostData.js | 11 +- .../libs/helpers/editorDataFormatter.js | 6 + .../libs/templates/interviewTemplate.js | 423 ++++++++++++++++++ .../Editor/editorHooks/newPost/useCreate.js | 4 +- .../Editor/editorHooks/newPost/useLoad.js | 13 +- components/StickyFooterInterview.js | 4 +- lib/api.js | 7 + lib/queries/getUserRelatedPostsFromPostId.js | 14 + pages/toolbox/[slug].js | 27 +- pages/toolbox/post/[id]/interview/[slug].js | 175 ++++++++ pages/toolbox/post/[id]/interview/index.js | 123 +++++ pages/write.js | 4 +- 12 files changed, 799 insertions(+), 12 deletions(-) create mode 100644 components/Editor/editorHooks/libs/templates/interviewTemplate.js create mode 100644 lib/queries/getUserRelatedPostsFromPostId.js create mode 100644 pages/toolbox/post/[id]/interview/[slug].js create mode 100644 pages/toolbox/post/[id]/interview/index.js diff --git a/components/Editor/editorHooks/libs/getCreatePostData.js b/components/Editor/editorHooks/libs/getCreatePostData.js index 7c58faef..118f820c 100644 --- a/components/Editor/editorHooks/libs/getCreatePostData.js +++ b/components/Editor/editorHooks/libs/getCreatePostData.js @@ -4,13 +4,15 @@ import { getContent, getLegacyFeaturedImage, uid, + getPostRelation } from "./helpers/editorDataFormatter"; export const getCreatePostData = ({ editor, forReview, postObject, - user + user, + relatedPost }) => { const html = editor.getHTML(); const json = editor.getJSON()?.content; @@ -25,6 +27,9 @@ export const getCreatePostData = ({ //create post slug - just use a unique id and the date const slug = `${uid()}--${user?.profile?.id}`; + const postRelation = getPostRelation({ relatedPost, postObject }); + + let entry = { type: "article", status: forReview ? "pending" : "draft", @@ -38,6 +43,10 @@ export const getCreatePostData = ({ user: user?.profile?.id, }; + if(postRelation) { + entry.tools = [postRelation]; + } + //change the date on save only if postStatus==draft or postStatus==pending publish if (postObject?.status !== "publish") { entry.date = new Date(); diff --git a/components/Editor/editorHooks/libs/helpers/editorDataFormatter.js b/components/Editor/editorHooks/libs/helpers/editorDataFormatter.js index 3ffed26b..f93ed35f 100644 --- a/components/Editor/editorHooks/libs/helpers/editorDataFormatter.js +++ b/components/Editor/editorHooks/libs/helpers/editorDataFormatter.js @@ -161,3 +161,9 @@ export const getPostDate = ({ postObject }) => { export const uid = function () { return Date.now().toString(36) + Math.random().toString(36).substr(2); }; + + +export const getPostRelation = ({ postObject, relatedPost }) => { + + return relatedPost; +}; \ No newline at end of file diff --git a/components/Editor/editorHooks/libs/templates/interviewTemplate.js b/components/Editor/editorHooks/libs/templates/interviewTemplate.js new file mode 100644 index 00000000..c44a6e53 --- /dev/null +++ b/components/Editor/editorHooks/libs/templates/interviewTemplate.js @@ -0,0 +1,423 @@ +export const getInterViewTemplate = ({ productName }) => { + return { + type: "doc", + content: [ + { + type: "heading", + attrs: { + level: 1, + }, + content: [ + { + type: "text", + text: `${productName}: Creator Story`, + }, + ], + }, + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "Welcome to your creator story! This is an interview template that will help share your story and show the human behind the product. The purpose is to showcase work you're excited about, whilst also helping and inspiring readers with their own projects. ", + }, + ], + }, + { + type: "bulletList", + content: [ + { + type: "listItem", + content: [ + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "Add your responses under the headings marked with Q.", + }, + ], + }, + ], + }, + { + type: "listItem", + content: [ + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "Feel free to add your own questions to steer the article ", + }, + ], + }, + { + type: "paragraph", + }, + ], + }, + { + type: "listItem", + content: [ + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "Long answers are encouraged, we will scope it down where needed when editing the submission", + }, + ], + }, + ], + }, + { + type: "listItem", + content: [ + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "Add pictures and videos (this editor is still WIP, so add links to videos if they don't upload)", + }, + ], + }, + { + type: "paragraph", + }, + ], + }, + ], + }, + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "Once completed, submit it for review, and we'll work with you to turn it into a piece ", + }, + { + type: "text", + marks: [ + { + type: "link", + attrs: { + href: "https://prototypr.io/post/framer-sites-building-landing-pages-that-tell-stories-with-olvy", + target: "_blank", + rel: null, + class: null, + }, + }, + { + type: "italic", + }, + ], + text: "like this one", + }, + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: " or ", + }, + { + type: "text", + marks: [ + { + type: "link", + attrs: { + href: "https://prototypr.io/post/from-design-system-to-nft-design-system-creating-tinyfaces", + target: "_blank", + rel: null, + class: null, + }, + }, + { + type: "italic", + }, + ], + text: "this one", + }, + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: ". ", + }, + ], + }, + { + type: "horizontalRule", + }, + { + type: "heading", + attrs: { + level: 1, + }, + content: [ + { + type: "text", + text: "Introduction", + }, + ], + }, + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "What's your story? This section is to share your background and what inspires you.", + }, + ], + }, + { + type: "heading", + attrs: { + level: 2, + }, + content: [ + { + type: "text", + text: "Q. Tell us about yourself, current work and side projects", + }, + ], + }, + { + type: "horizontalRule", + }, + { + type: "heading", + attrs: { + level: 1, + }, + content: [ + { + type: "text", + text: `What inspired you to work on ${productName}?`, + }, + ], + }, + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "How you decided what to work on, and what inspires and drives you to do it. It will also help other people decide on what they should work on.", + }, + ], + }, + { + type: "heading", + attrs: { + level: 2, + }, + content: [ + { + type: "text", + text: `Q. What is ${productName}, and how did you discover the problem you’re trying to solve?`, + }, + ], + }, + { + type: "heading", + attrs: { + level: 2, + }, + content: [ + { + type: "text", + text: "Q. Who is it for, and how are you discovering your first users?", + }, + ], + }, + { + type: "horizontalRule", + }, + { + type: "heading", + attrs: { + level: 1, + }, + content: [ + { + type: "text", + text: "Sharing the process", + }, + ], + }, + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "This section gives a look into your craft, and also teaches readers how they can approach certain tasks you undertook.", + }, + ], + }, + { + type: "heading", + attrs: { + level: 2, + }, + content: [ + { + type: "text", + text: `Q. What are the piece(s) of ${productName} you're most proud of, and why?`, + }, + ], + }, + { + type: "heading", + attrs: { + level: 2, + }, + content: [ + { + type: "text", + text: "Q. Share some of the process behind creating a piece you're proud of? What tools did you use along the way, and for what purpose?", + }, + ], + }, + { + type: "horizontalRule", + }, + { + type: "heading", + attrs: { + level: 1, + }, + content: [ + { + type: "text", + text: `What's Next for ${productName}?`, + }, + ], + }, + + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "Share your plans for the future of your project, and what you're excited about.", + }, + ], + }, + { + type: "heading", + attrs: { + level: 2, + }, + content: [ + { + type: "text", + text: "Q. Where do you want to take the project next? ", + }, + ], + }, + { + type: "heading", + attrs: { + level: 2, + }, + content: [ + { + type: "text", + text: "Q. Do you have any predictions about the future of your project industry?", + }, + ], + }, + { + type: "horizontalRule", + }, + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "Once you're done, submit the article for review. ", + }, + ], + }, + { + type: "paragraph", + content: [ + { + type: "text", + marks: [ + { + type: "italic", + }, + ], + text: "An editor (Graeme) will work on it and get back to you with edits and any additional questions.", + }, + ], + }, + { + type: "paragraph", + }, + ], + }; +}; diff --git a/components/Editor/editorHooks/newPost/useCreate.js b/components/Editor/editorHooks/newPost/useCreate.js index 16579a79..29ee3356 100644 --- a/components/Editor/editorHooks/newPost/useCreate.js +++ b/components/Editor/editorHooks/newPost/useCreate.js @@ -3,9 +3,9 @@ import { getCreatePostData } from "../libs/getCreatePostData"; var axios = require("axios"); const useCreate = () => { - const createPost = async ({ user, editor, forReview }) => { + const createPost = async ({ user, editor, forReview, relatedPost }) => { - const { entry } = getCreatePostData({ user, editor, forReview }); + const { entry } = getCreatePostData({ user, editor, forReview, relatedPost }); let publishPostEndpointConfig = { method: "post", diff --git a/components/Editor/editorHooks/newPost/useLoad.js b/components/Editor/editorHooks/newPost/useLoad.js index bbf9b453..9df7a11c 100644 --- a/components/Editor/editorHooks/newPost/useLoad.js +++ b/components/Editor/editorHooks/newPost/useLoad.js @@ -9,7 +9,9 @@ import { useEffect, useState } from "react"; * @param {*} usr * @returns */ -const useLoad = user => { +import { getInterViewTemplate } from "../libs/templates/interviewTemplate"; + +const useLoad = ({user, interview, productName}) => { const [loading, setLoading] = useState(true); const [postStatus] = useState("draft"); @@ -27,12 +29,19 @@ const useLoad = user => { const refetch = async () => { let retrievedObject = localStorage.getItem("wipContent"); + if(interview){ + retrievedObject = localStorage.getItem("wipInterview"); + } if (retrievedObject) { setInitialContent(JSON.parse(retrievedObject)); setLoading(false); - } else { + } + else { //it's a new post setInitialContent(false) + if(interview){ + setInitialContent(getInterViewTemplate({productName:'Prototypr Publisher'})); + } setLoading(false); } }; diff --git a/components/StickyFooterInterview.js b/components/StickyFooterInterview.js index 32067492..da00e4d5 100644 --- a/components/StickyFooterInterview.js +++ b/components/StickyFooterInterview.js @@ -14,7 +14,7 @@ export function getScrollPercent() { return ((h[st] || b[st]) / ((h[sh] || b[sh]) - h.clientHeight)) * 100; } -const StickyFooterInterview = ({ title, description, buttonText }) => { +const StickyFooterInterview = ({ title, description, buttonText, post }) => { const [isVisible, setVisible] = useState(true); // const [userClosed, setUserClosed] = useState(false); @@ -113,7 +113,7 @@ const StickyFooterInterview = ({ title, description, buttonText }) => {
- +