Skip to content

Commit 337382f

Browse files
authored
Merge pull request #43 from techulus/develop
Replace post type with tags
2 parents 2400698 + d931cd9 commit 337382f

File tree

12 files changed

+91
-74
lines changed

12 files changed

+91
-74
lines changed

apps/page/components/post.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PostType } from "@changes-page/supabase/types/page";
12
import { PostTypeBadge } from "@changes-page/ui";
23
import classNames from "classnames";
34
import dynamic from "next/dynamic";
@@ -47,11 +48,15 @@ export default function Post({
4748
>
4849
<div className="absolute top-3 ml-[-20px] h-[0.0725rem] w-3.5 bg-gray-700 dark:bg-gray-400"></div>
4950
<div className="min-w-0 w-full space-y-3">
50-
<span className="inline-flex text-sm space-x-2 whitespace-nowrap text-gray-500 dark:text-gray-400">
51+
<span className="inline-flex flex-col md:flex-row text-sm md:space-x-2 space-y-2 md:space-y-0 whitespace-nowrap text-gray-500 dark:text-gray-400">
5152
<PostDateTime publishedAt={publishedAt} />
5253

5354
<div className="flex items-center -mt-0.5">
54-
<PostTypeBadge type={post?.type} />
55+
{(post?.tags ?? []).map((tag, idx) => (
56+
<div key={tag} className={classNames(idx ? "ml-2" : "")}>
57+
<PostTypeBadge type={tag as PostType} />
58+
</div>
59+
))}
5560
{isPinned && <PostTypeBadge type="pinned" className="ml-2" />}
5661
</div>
5762
</span>

apps/page/lib/data.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export const BLACKLISTED_SLUGS = [
7070
"press-kit",
7171
];
7272

73+
const postSelectParams =
74+
"id,title,content,tags,publication_date,updated_at,created_at,allow_reactions";
75+
7376
function translateHostToPageIdentifier(host: string): {
7477
page: string | null;
7578
domain: string | null;
@@ -209,12 +212,9 @@ async function fetchPosts(
209212
): Promise<{ posts: IPost[]; postsCount: number }> {
210213
const postsQuery = supabaseAdmin
211214
.from("posts")
212-
.select(
213-
"id,title,content,type,publication_date,updated_at,created_at,allow_reactions",
214-
{
215-
count: "exact",
216-
}
217-
)
215+
.select(postSelectParams, {
216+
count: "exact",
217+
})
218218
.eq("page_id", String(pageId))
219219
.eq("status", "published")
220220
.range(
@@ -242,9 +242,7 @@ async function fetchPosts(
242242
// Get pinned post
243243
const { data: pinnedPost, error: pinnedPostError } = await supabaseAdmin
244244
.from("posts")
245-
.select(
246-
"id,title,content,type,publication_date,updated_at,created_at,allow_reactions"
247-
)
245+
.select(postSelectParams)
248246
.eq("id", pinned_post_id)
249247
.eq("status", "published")
250248
.maybeSingle();
@@ -283,7 +281,7 @@ export type IPostPublicData = Pick<
283281
| "id"
284282
| "title"
285283
| "content"
286-
| "type"
284+
| "tags"
287285
| "publication_date"
288286
| "updated_at"
289287
| "created_at"
@@ -299,9 +297,7 @@ async function fetchPostById(
299297
}> {
300298
const { data: post, error: postError } = await supabaseAdmin
301299
.from("posts")
302-
.select(
303-
"id,title,content,type,publication_date,updated_at,created_at,allow_reactions"
304-
)
300+
.select(postSelectParams)
305301
.eq("id", String(postId))
306302
.eq("page_id", String(pageId))
307303
.eq("status", "published")

apps/page/pages/_sites/[site]/plain.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
IPage,
33
IPageSettings,
44
IPost,
5+
PostType,
56
PostTypeToLabel,
67
} from "@changes-page/supabase/types/page";
78
import { DateTime } from "@changes-page/utils";
@@ -61,7 +62,10 @@ export default function Index({
6162
<h2 className="post-title text-xl font-bold">{post.title}</h2>
6263

6364
<div className="min-w-0 w-full">
64-
{PostTypeToLabel[post?.type]},{" "}
65+
{(post.tags ?? [])
66+
.map((tag) => PostTypeToLabel[tag as PostType])
67+
.join(", ")}
68+
{" | "}
6569
<span className="inline-flex text-sm space-x-2 whitespace-nowrap">
6670
<time dateTime="2020-09-20" suppressHydrationWarning>
6771
{DateTime.fromISO(

apps/page/pages/api/latest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getPageUrl, getPostUrl } from "../../lib/url";
77

88
type IPostWithUrl = Pick<
99
IPost,
10-
"id" | "title" | "content" | "type" | "created_at"
10+
"id" | "title" | "content" | "tags" | "created_at"
1111
> & { url: string };
1212

1313
async function handler(
@@ -32,7 +32,7 @@ async function handler(
3232
// fetch latest post for page
3333
const { data, error: postsError } = await supabaseAdmin
3434
.from("posts")
35-
.select("id,title,content,type,publication_date,updated_at,created_at")
35+
.select("id,title,content,tags,publication_date,updated_at,created_at")
3636
.eq("page_id", String(page?.id))
3737
.eq("status", "published")
3838
.order("publication_date", { ascending: false })

apps/page/pages/api/pinned.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getPageUrl, getPostUrl } from "../../lib/url";
77

88
type IPostWithUrl = Pick<
99
IPost,
10-
"id" | "title" | "content" | "type" | "created_at"
10+
"id" | "title" | "content" | "tags" | "created_at"
1111
> & { url: string };
1212

1313
async function handler(
@@ -32,7 +32,7 @@ async function handler(
3232
// fetch pinned post for page
3333
const { data, error: postsError } = await supabaseAdmin
3434
.from("posts")
35-
.select("id,title,content,type,publication_date,updated_at,created_at")
35+
.select("id,title,content,tags,publication_date,updated_at,created_at")
3636
.eq("page_id", String(page?.id))
3737
.eq("status", "published")
3838
.eq("id", String(settings?.pinned_post_id))

apps/page/pages/api/posts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function handler(
2121
try {
2222
const { data: posts } = await supabaseAdmin
2323
.from("posts")
24-
.select("id,title,content,type,publication_date,updated_at,created_at")
24+
.select("id,title,content,tags,publication_date,updated_at,created_at")
2525
.eq("page_id", String(page_id))
2626
.eq("status", "published")
2727
.range(Number(offset), Number(PAGINATION_LIMIT - 1 + Number(offset)))

apps/web/components/forms/post-form.component.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { useFormik } from "formik";
1919
import { Fragment, useCallback, useEffect, useMemo, useState } from "react";
2020
import ReactMarkdown from "react-markdown";
2121
import { v4 } from "uuid";
22-
import { InferType, boolean, mixed, object, string } from "yup";
22+
import { InferType, array, boolean, mixed, object, string } from "yup";
2323
import { track } from "../../utils/analytics";
2424
import { useUserData } from "../../utils/useUser";
2525
import { PrimaryButton } from "../core/buttons.component";
@@ -40,9 +40,9 @@ export const NewPostSchema = object().shape({
4040
.required("Content cannot be empty")
4141
.min(2, "Content too Short!")
4242
.max(9669, "Content too Long!"),
43-
type: mixed<PostType>()
44-
.oneOf(Object.values(PostType))
45-
.required("Enter valid type"),
43+
tags: array()
44+
.of(mixed<PostType>().oneOf(Object.values(PostType)))
45+
.required("Enter valid tags"),
4646
status: mixed<PostStatus>()
4747
.oneOf(Object.values(PostStatus))
4848
.required("Enter valid status"),
@@ -120,7 +120,7 @@ export default function PostFormComponent({
120120
initialValues: {
121121
title: "",
122122
content: "",
123-
type: Object.keys(PostType)[0] as PostType,
123+
tags: [Object.keys(PostType)[0]] as PostType[],
124124
status: PostStatus.published,
125125
page_id: "",
126126
images_folder: "",
@@ -201,21 +201,29 @@ export default function PostFormComponent({
201201
<div className="overflow-hidden md:rounded-md md:border border-gray-300 dark:border-gray-700 shadow-sm focus-within:border-indigo-500 focus-within:ring-1 focus-within:ring-indigo-500">
202202
<Listbox
203203
as="div"
204-
value={formik.values.type}
205-
onChange={(type) => formik.setFieldValue("type", type)}
204+
multiple
205+
value={formik.values.tags}
206+
onChange={(tags) => {
207+
formik.setFieldValue("tags", tags);
208+
if (!tags.length) {
209+
formik.setFieldValue("tags", [Object.keys(PostType)[0]]);
210+
}
211+
}}
206212
className="flex-shrink-0 bg-white dark:bg-gray-900 p-2"
207213
>
208-
{({ open }) => (
214+
{({ open, value }) => (
209215
<>
210216
<Listbox.Label className="sr-only">
211217
{" "}
212218
Add a label{" "}
213219
</Listbox.Label>
214220
<div className="relative">
215-
<Listbox.Button className="relative p-0 pl-1 scale-110">
216-
<PostTypeBadge
217-
type={formik.values.type ?? PostType.fix}
218-
/>
221+
<Listbox.Button className="relative p-0 pl-1 scale-110 w-auto text-left">
222+
{value.map((tag: PostType) => (
223+
<div key={tag} className="inline-block ml-2">
224+
<PostTypeBadge type={tag} />
225+
</div>
226+
))}
219227
</Listbox.Button>
220228

221229
<Transition
@@ -241,6 +249,12 @@ export default function PostFormComponent({
241249
>
242250
<div className="flex items-center">
243251
<span className="block truncate font-medium">
252+
{value.includes(label) ? (
253+
<CheckIcon
254+
className="h-5 w-5 inline mr-2"
255+
aria-hidden="true"
256+
/>
257+
) : null}
244258
{PostTypeToLabel[label]}
245259
</span>
246260
</div>

apps/web/components/post/post.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
IPost,
55
PostStatus,
66
PostStatusToLabel,
7+
PostType,
78
} from "@changes-page/supabase/types/page";
89
import { PostDateTime, PostTypeBadge } from "@changes-page/ui";
910
import { Menu } from "@headlessui/react";
@@ -76,11 +77,15 @@ export function Post({
7677
<div className="flex items-center justify-between space-x-4 relative">
7778
<div className="absolute top-3 ml-[-20px] h-[0.0725rem] w-3.5 bg-gray-700 dark:bg-gray-400"></div>
7879
<div className="min-w-0 w-full space-y-3">
79-
<span className="inline-flex text-sm space-x-2 whitespace-nowrap text-gray-500 dark:text-gray-400">
80+
<span className="inline-flex flex-col md:flex-row text-sm md:space-x-2 space-y-2 md:space-y-0 whitespace-nowrap text-gray-500 dark:text-gray-400">
8081
<PostDateTime publishedAt={publishedAt} startWithFullDate />
8182

8283
<div className="flex items-center -mt-0.5">
83-
<PostTypeBadge type={post?.type} />
84+
{(post?.tags ?? []).map((tag: PostType, idx) => (
85+
<div key={tag} className={classNames(idx ? "ml-2" : "")}>
86+
<PostTypeBadge type={tag} />
87+
</div>
88+
))}
8489
{settings?.pinned_post_id === post.id && (
8590
<PostTypeBadge type="pinned" className="ml-2" />
8691
)}

apps/web/pages/api/integrations/zapier/trigger-new-post.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
export default async function handler(
1212
req: NextApiRequest,
1313
res: NextApiResponse<
14-
| Pick<IPost, "id" | "title" | "content" | "type" | "created_at">[]
14+
| Pick<IPost, "id" | "title" | "content" | "tags" | "created_at">[]
1515
| null
1616
| IErrorResponse
1717
>
@@ -38,7 +38,7 @@ export default async function handler(
3838

3939
const { data: posts } = await supabaseAdmin
4040
.from("posts")
41-
.select("id,title,content,type,created_at")
41+
.select("id,title,content,tags,created_at")
4242
.eq("page_id", String(pageDetails.id))
4343
.eq("status", String(status))
4444
.order("created_at", { ascending: false })

apps/web/pages/api/posts/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const createNewPost = async (req: NextApiRequest, res: NextApiResponse) => {
1010
page_id,
1111
title,
1212
content,
13-
type,
13+
tags,
1414
status,
1515
images_folder,
1616
publish_at,
@@ -39,7 +39,7 @@ const createNewPost = async (req: NextApiRequest, res: NextApiResponse) => {
3939
page_id,
4040
title,
4141
content,
42-
type,
42+
tags,
4343
status,
4444
images_folder,
4545
publish_at,

0 commit comments

Comments
 (0)