Skip to content

Commit

Permalink
interview draft
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed Jun 7, 2024
1 parent f5cbc59 commit d264375
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 51 deletions.
96 changes: 61 additions & 35 deletions components/Dashboard/PostCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@ const PostCard = ({ post, refetch, user, edit }) => {
}
};


return (
<div className="flex flex-row justify-between p-4 h-full rounded-lg border shadow-sm border-black/5 hover:border-opacity-10 cursor-default bg-white hover:transition duration-300 ease-in-out col-span-12">
<div className="flex flex-col grid gap-2 w-full flex-shrink">
<div className="">
<Link
href={
(edit===false && post.type=='article')? `/post/${post.slug}`:
(edit===false && post.type=='tool')? `/toolbox/${post.slug}`:
post.type == "article"
? `/p/${post.id}`
: `/toolbox/post/${post.id}`
edit === false && post.type == "article"
? `/post/${post.slug}`
: edit === false && post.type == "tool"
? `/toolbox/${post.slug}`
: post.type == "article" && post.tools?.length
? `/toolbox/post/${post.tools[0].id}/interview/${post.id}`
: post.type == "article"
? `/p/${post.id}`
: `/toolbox/post/${post.id}`
}
>
<h3 className="text-xl font-semibold max-w-2xl ">{post.title}</h3>
Expand All @@ -89,14 +94,34 @@ const PostCard = ({ post, refetch, user, edit }) => {
{format(new Date(post.date), "LLLL d, yyyy")}
</p>
<div className="my-auto text-sm text-gray-500">{` · `}</div>
{post.type ? (
{post.type == "article" && post.tools?.length ? (
<div className="text-[11px] font-semibold my-auto bg-yellow-100 px-3 py-1 uppercase rounded-full text-yellow-900">
Interview
</div>
) : post.type ? (
<div className="text-[11px] font-semibold my-auto bg-gray-100 px-3 py-1 uppercase rounded-full text-gray-600">
{post.type}
</div>
) : (
""
)}

{post.type == "article" && post.tools?.length ? (
<>
<div className="my-auto text-sm text-gray-500">{` · `}</div>
<div className="flex-none my-auto">
<Link target="_blank" href={`/toolbox/${post.tools[0].slug}`}>
<img
className="flex-none w-6 h-6 rounded-2xl my-auto"
src={post.tools[0].logo?.url}
/>
</Link>
</div>
</>
) : (
""
)}

{post.status !== "publish" && post.status !== "draft" && (
<>
<div className="my-auto text-sm text-gray-500">{` · `}</div>
Expand Down Expand Up @@ -154,7 +179,7 @@ const PostCard = ({ post, refetch, user, edit }) => {
</Link>
</div>
)}
{(post.type == "tool" && edit!==false) ? (
{post.type == "tool" && edit !== false ? (
<div className="hidden md:block">
<Link href={`/toolbox/post/${post.id}?step=3`}>
<button className="text-lg bg-white underline text-black p-3 rounded-full hover:bg-gray-100 ">
Expand All @@ -165,37 +190,38 @@ const PostCard = ({ post, refetch, user, edit }) => {
) : (
""
)}
{edit !== false ? (
<div>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton
className="!text-gray-700"
aria-label="Customise options"
>
<DotsThree />
</IconButton>
</DropdownMenuTrigger>

{edit!==false? <div>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton
className="!text-gray-700"
aria-label="Customise options"
>
<DotsThree />
</IconButton>
</DropdownMenuTrigger>

<DropdownMenuContent sideOffset={5}>
{/* <DropdownMenuSeparator /> */}
<DropdownMenuItem
className="group"
onSelect={(e) => {
e.preventDefault()
}}
>
<DeletePostButton
onClick={() => {
deletePost(post.id);
<DropdownMenuContent sideOffset={5}>
{/* <DropdownMenuSeparator /> */}
<DropdownMenuItem
className="group"
onSelect={e => {
e.preventDefault();
}}
/>
</DropdownMenuItem>
>
<DeletePostButton
onClick={() => {
deletePost(post.id);
}}
/>
</DropdownMenuItem>

<DropdownMenuArrow offset={12} />
</DropdownMenuContent>
</DropdownMenu>
</div>:null}
<DropdownMenuArrow offset={12} />
</DropdownMenuContent>
</DropdownMenu>
</div>
) : null}
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion components/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const Editor = ({
// }),
Placeholder.configure({
showOnlyCurrent: false,
includeChildren: true,
includeChildren: false,
placeholder: ({ node }) => {
if (node.type.name === "heading") {
return "Title";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export const getInterViewTemplate = ({ productName }) => {
content: [
{
type: "text",
text: "Q. Who is it for, and how are you discovering your first users?",
text: `Q. Who is ${productName} for, and how are you discovering your first users?`,
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion components/Editor/editorHooks/newPost/useLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const useLoad = ({user, interview, productName}) => {
//it's a new post
setInitialContent(false)
if(interview){
setInitialContent(getInterViewTemplate({productName:'Prototypr Publisher'}));
setInitialContent(getInterViewTemplate({productName:productName}));
}
setLoading(false);
}
Expand Down
2 changes: 1 addition & 1 deletion components/toolbox/AuthorCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function AuthorCard({
</div>

<div className={`my-auto ${size=='small'?"mr-1":"w-3/5"}`}>
{size=='small'&& <h3 className="text-sm tracking-tight text-gray-500 ">Curated by</h3>}
{size=='small'&& <h3 className="text-sm tracking-tight text-gray-500 ">Posted by</h3>}
<p
tabIndex={0}
className="text-base cursor-pointer leading-5 font-semibold text-gray-800"
Expand Down
1 change: 1 addition & 0 deletions lib/queries/creatorArticlesQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query CreatorArticles($status:[String]!, $pageSize: Int, $offset: Int) {
date
status
excerpt
tools
}
count
}
Expand Down
8 changes: 2 additions & 6 deletions lib/queries/getUserRelatedPostsFromPostId.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ query UserArticle($slug:ID!) {
userPostId(id: $slug) {
id
slug
interviews{
slug
}
tools{
slug
}
interviews
tools
}
}
`;
1 change: 1 addition & 0 deletions lib/queries/userArticlesQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query UserArticles($status:[String]!, $pageSize: Int, $offset: Int) {
date
status
excerpt
tools
}
count
}
Expand Down
1 change: 0 additions & 1 deletion pages/toolbox/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
getTool,
// getAllToolsForHomeStatic,
getPopularTopics,
getSlugFromArticleId,
getUserRelatedPostsFromId,
} from "@/lib/api";
// import ToolCard from "@/components/v4/card/ToolCard";
Expand Down
55 changes: 50 additions & 5 deletions pages/toolbox/post/[id]/interview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useCreate from "@/components/Editor/editorHooks/newPost/useCreate";

import { useRouter } from "next/router";
import EditorNav from "@/components/EditorNav";
import { getToolById } from "@/lib/api";

/**
* Write
Expand All @@ -24,9 +25,8 @@ import EditorNav from "@/components/EditorNav";
*
* @returns
*/
export default function InterviewEditor() {
export default function InterviewEditor({tool}) {
const router = useRouter();

const { user } = useUser({
// redirectTo: '/account',
redirectTo: "/onboard",
Expand All @@ -42,7 +42,11 @@ export default function InterviewEditor() {

//useLoad hook
//initialContent is null until loaded - so is 'false' when it's a new post
const { canEdit, loading, initialContent, postStatus } = useLoad({user, interview:true});
const { canEdit, loading, initialContent, postStatus } = useLoad({
user,
interview: true,
productName:tool?.attributes?.title
});

//create new post hook
const { createPost } = useCreate();
Expand Down Expand Up @@ -71,17 +75,32 @@ export default function InterviewEditor() {
try {
const { id } = router.query;

const postInfo = await createPost({ user, editor, forReview, relatedPost:id });
const postInfo = await createPost({
user,
editor,
forReview,
relatedPost: id,
});
//set the new slug
localStorage.removeItem("wipInterview");


router.push(`/toolbox/post/${id}/interview/${postInfo?.id}`);
} catch (e) {
return false;
}
};


if(router.isFallback){
return (
<div className="my-auto h-screen flex flex-col justify-center text-center">
<div className="mx-auto opacity-50">
<Spinner />
</div>
</div>
)
}

return (
<>
<EditorNav postStatus={postStatus} />
Expand Down Expand Up @@ -121,3 +140,29 @@ export default function InterviewEditor() {
</>
);
}

export async function getStaticProps({ params, preview = null, locale }) {
let data;
try {
data = await getToolById(params.id, preview);
} catch (error) {
console.error('Failed to get tool:', error);
return {
notFound: true,
};
}

let tool = data?.posts?.data[0] || null;
return {
props: {
tool: tool || null,
},
};
}

export async function getStaticPaths() {
return {
paths: [],
fallback: 'blocking',
};
}

0 comments on commit d264375

Please sign in to comment.