Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog extensions: Reviews and Ratings #861

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
aafa26c
feat(blogreaction): setup started
Sep 13, 2024
eab7642
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Sep 13, 2024
5b41f68
chore(blogLike): reaction mock changed
Sep 16, 2024
c8d9b2d
feat(blogLike): deco records bug fix
Sep 16, 2024
a563bc5
feat(bloglike): extension loaders ended
Sep 16, 2024
6401764
feat(bloglike): submit extension
Sep 16, 2024
64a827d
fix(bloglike): action fix
Sep 17, 2024
e85fab2
chore(bloglike): prettify code
Sep 17, 2024
d6e7437
feat(blogpost): comment feat started
Sep 17, 2024
e348e9f
feat(blogpost): comment action added
Sep 17, 2024
49ad269
Merge pull request #868 from deco-cx/feat-blog-comment
aka-sacci-ccr Sep 17, 2024
b26b7f6
fix(blog): changed schema
Sep 18, 2024
8af05b2
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-comment
Sep 18, 2024
214d7b7
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Sep 18, 2024
62983ae
Merge branch 'feat-blog-like' of github.com:deco-cx/apps into feat-bl…
Sep 18, 2024
7d68653
Merge branch 'feat-blog-like' of github.com:deco-cx/apps into feat-bl…
Sep 18, 2024
164649b
Merge pull request #870 from deco-cx/feat-blog-comment
aka-sacci-ccr Sep 18, 2024
e270c56
feat(blog): extension props
Sep 18, 2024
29026f7
Merge branch 'feat-blog-like' of github.com:deco-cx/apps into feat-bl…
Sep 18, 2024
c943a79
Merge pull request #871 from deco-cx/feat-blog-extesions
aka-sacci-ccr Sep 18, 2024
dba5261
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Sep 23, 2024
8885171
feat(blogpost): new types for carousel
Sep 23, 2024
1695e4e
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Sep 30, 2024
861292a
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Oct 7, 2024
6627bf4
feat(blogextensions): update database script
Oct 7, 2024
af2a955
feat(blogextensions): script workaround
Oct 7, 2024
76b6520
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Oct 11, 2024
1791251
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Oct 15, 2024
2cd96b8
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Oct 21, 2024
b49c320
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Oct 30, 2024
e5ebdde
feat(most-viewed): order by most viewed started
Oct 30, 2024
6ccb944
feat(most-viewed): loader and orderBy finished
Oct 30, 2024
5d46609
feat(most-viewed): action finished
Oct 30, 2024
ff7a1d0
chore(blog): blogposting core logic archives
Oct 31, 2024
f9b53bd
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Nov 27, 2024
863cc25
feat(blogpost): listing now supports slugs lists
Nov 27, 2024
84d9107
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Dec 17, 2024
7f07d5a
sync main
Dec 20, 2024
69e78c9
Merge branch 'main' of github.com:deco-cx/apps into feat-blog-like
Jan 6, 2025
7e5f637
sync main
Jan 14, 2025
caf5c58
fix(blog): deploy error
Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sync main
  • Loading branch information
decobot committed Dec 20, 2024
commit 7f07d5a2de889997f8b141dd69edb2347f88ef19
34 changes: 31 additions & 3 deletions blog/core/handlePosts.ts
Original file line number Diff line number Diff line change
@@ -115,6 +115,19 @@ export const filterPostsByCategory = (posts: BlogPost[], slug?: string) =>
export const filterPostsBySlugs = (posts: BlogPost[], postSlugs: string[]) =>
posts.filter(({ slug }) => postSlugs.includes(slug));

/**
* Returns an filtered BlogPost list
*
* @param posts Posts to be handled
* @param term Term to be filter
*/
export const filterPostsByTerm = (posts: BlogPost[], term: string) =>
posts.filter(({ content, excerpt, title }) =>
[content, excerpt, title].some((field) =>
field.toLowerCase().includes(term.toLowerCase())
)
);

/**
* Returns an filtered and sorted BlogPost list
*
@@ -132,6 +145,22 @@ export const slicePosts = (
return posts.slice(startIndex, endIndex);
};

const filterPosts = (
posts: BlogPost[],
slug?: string,
postSlugs?: string[],
term?: string,
): BlogPost[] => {
const firstFilter = postSlugs && postSlugs.length > 0
? filterPostsBySlugs(posts, postSlugs)
: filterPostsByCategory(posts, slug);

const filteredByTerm = term
? filterPostsByTerm(firstFilter, term)
: firstFilter;
return filteredByTerm;
};

/**
* Returns an filtered and sorted BlogPost list. It dont slice
*
@@ -146,10 +175,9 @@ export default async function handlePosts(
ctx: AppContext,
slug?: string,
postSlugs?: string[],
term?: string,
) {
const filteredPosts = postSlugs && postSlugs.length > 0
? filterPostsBySlugs(posts, postSlugs)
: filterPostsByCategory(posts, slug);
const filteredPosts = filterPosts(posts, slug, postSlugs, term);

if (!filteredPosts || filteredPosts.length === 0) {
return null;
9 changes: 8 additions & 1 deletion blog/loaders/BlogpostList.ts
Original file line number Diff line number Diff line change
@@ -42,6 +42,10 @@ export interface Props {
* @description The sorting option. Default is "date_desc"
*/
sortBy?: SortBy;
/**
* @description Overrides the query term at url
*/
query?: string;
}

/**
@@ -54,7 +58,7 @@ export interface Props {
* @returns A promise that resolves to an array of blog posts.
*/
export default async function BlogPostList(
{ page, count, slug, sortBy, postSlugs }: Props,
{ page, count, slug, sortBy, postSlugs, query }: Props,
req: Request,
ctx: AppContext,
): Promise<BlogPost[] | null> {
@@ -63,6 +67,8 @@ export default async function BlogPostList(
const pageNumber = Number(page ?? url.searchParams.get("page") ?? 1);
const pageSort = sortBy ?? url.searchParams.get("sortBy") as SortBy ??
"date_desc";
const term = query ?? url.searchParams.get("q") ?? undefined;

const posts = await getRecordsByPath<BlogPost>(
ctx,
COLLECTION_PATH,
@@ -76,6 +82,7 @@ export default async function BlogPostList(
ctx,
slug,
postSlugs,
term,
);

if (!handledPosts) {
17 changes: 15 additions & 2 deletions blog/loaders/BlogpostListing.ts
Original file line number Diff line number Diff line change
@@ -38,6 +38,10 @@ export interface Props {
* @description The sorting option. Default is "date_desc"
*/
sortBy?: SortBy;
/**
* @description Overrides the query term at url
*/
query?: string;
}

/**
@@ -50,7 +54,7 @@ export interface Props {
* @returns A promise that resolves to an array of blog posts.
*/
export default async function BlogPostList(
{ page, count, slug, sortBy }: Props,
{ page, count, slug, sortBy, query }: Props,
req: Request,
ctx: AppContext,
): Promise<BlogPostListingPage | null> {
@@ -60,14 +64,23 @@ export default async function BlogPostList(
const pageNumber = Number(page ?? params.get("page") ?? 1);
const pageSort = sortBy ?? params.get("sortBy") as SortBy ??
"date_desc";
const term = query ?? params.get("q") ?? undefined;

const posts = await getRecordsByPath<BlogPost>(
ctx,
COLLECTION_PATH,
ACCESSOR,
);

try {
const handledPosts = await handlePosts(posts, pageSort, ctx, slug);
const handledPosts = await handlePosts(
posts,
pageSort,
ctx,
slug,
undefined,
term,
);

if (!handledPosts) {
return null;
2 changes: 2 additions & 0 deletions commerce/types.ts
Original file line number Diff line number Diff line change
@@ -351,6 +351,8 @@ export interface Review extends Omit<Thing, "@type"> {
id?: string;
/** Author of the */
author?: Author[];
/** The date that the order was created, in ISO 8601 date format.*/
dateCreated?: string;
/** The date that the review was published, in ISO 8601 date format.*/
datePublished?: string;
/** The item that is being reviewed/rated. */
1 change: 1 addition & 0 deletions deco.ts
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ const config = {
app("linx-impulse"),
app("shopify"),
app("nuvemshop"),
app("streamshop"),
app("website"),
app("commerce"),
app("workflows"),
1 change: 1 addition & 0 deletions decohub/apps/streamshop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, preview } from "../../streamshop/mod.ts";
34 changes: 18 additions & 16 deletions decohub/manifest.gen.ts
Original file line number Diff line number Diff line change
@@ -24,14 +24,15 @@ import * as $$$$$$$$$$$18 from "./apps/resend.ts";
import * as $$$$$$$$$$$19 from "./apps/shopify.ts";
import * as $$$$$$$$$$$20 from "./apps/smarthint.ts";
import * as $$$$$$$$$$$21 from "./apps/sourei.ts";
import * as $$$$$$$$$$$22 from "./apps/typesense.ts";
import * as $$$$$$$$$$$23 from "./apps/verified-reviews.ts";
import * as $$$$$$$$$$$24 from "./apps/vnda.ts";
import * as $$$$$$$$$$$25 from "./apps/vtex.ts";
import * as $$$$$$$$$$$26 from "./apps/wake.ts";
import * as $$$$$$$$$$$27 from "./apps/wap.ts";
import * as $$$$$$$$$$$28 from "./apps/weather.ts";
import * as $$$$$$$$$$$29 from "./apps/workflows.ts";
import * as $$$$$$$$$$$22 from "./apps/streamshop.ts";
import * as $$$$$$$$$$$23 from "./apps/typesense.ts";
import * as $$$$$$$$$$$24 from "./apps/verified-reviews.ts";
import * as $$$$$$$$$$$25 from "./apps/vnda.ts";
import * as $$$$$$$$$$$26 from "./apps/vtex.ts";
import * as $$$$$$$$$$$27 from "./apps/wake.ts";
import * as $$$$$$$$$$$28 from "./apps/wap.ts";
import * as $$$$$$$$$$$29 from "./apps/weather.ts";
import * as $$$$$$$$$$$30 from "./apps/workflows.ts";

const manifest = {
"apps": {
@@ -57,14 +58,15 @@ const manifest = {
"decohub/apps/shopify.ts": $$$$$$$$$$$19,
"decohub/apps/smarthint.ts": $$$$$$$$$$$20,
"decohub/apps/sourei.ts": $$$$$$$$$$$21,
"decohub/apps/typesense.ts": $$$$$$$$$$$22,
"decohub/apps/verified-reviews.ts": $$$$$$$$$$$23,
"decohub/apps/vnda.ts": $$$$$$$$$$$24,
"decohub/apps/vtex.ts": $$$$$$$$$$$25,
"decohub/apps/wake.ts": $$$$$$$$$$$26,
"decohub/apps/wap.ts": $$$$$$$$$$$27,
"decohub/apps/weather.ts": $$$$$$$$$$$28,
"decohub/apps/workflows.ts": $$$$$$$$$$$29,
"decohub/apps/streamshop.ts": $$$$$$$$$$$22,
"decohub/apps/typesense.ts": $$$$$$$$$$$23,
"decohub/apps/verified-reviews.ts": $$$$$$$$$$$24,
"decohub/apps/vnda.ts": $$$$$$$$$$$25,
"decohub/apps/vtex.ts": $$$$$$$$$$$26,
"decohub/apps/wake.ts": $$$$$$$$$$$27,
"decohub/apps/wap.ts": $$$$$$$$$$$28,
"decohub/apps/weather.ts": $$$$$$$$$$$29,
"decohub/apps/workflows.ts": $$$$$$$$$$$30,
},
"name": "decohub",
"baseUrl": import.meta.url,
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -62,5 +62,5 @@
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"version": "0.64.6"
"version": "0.64.11"
}
37 changes: 37 additions & 0 deletions konfidency/actions/submitReviews.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AppContext } from "../mod.ts";
import { ResponseWriteReview, WriteReview } from "../utils/types.ts";
import { logger } from "@deco/deco/o11y";

export interface Props {
/**
* @title Product SKU
*/
sku: string;
review: WriteReview;
}

export default async function action(
props: Props,
_req: Request,
ctx: AppContext,
): Promise<ResponseWriteReview | null> {
const { customer, api } = ctx;
const { review, sku } = props;

try {
const response = await api[`POST /:customer/:sku/review`]({
sku: sku,
customer,
}, {
body: {
...review,
},
}).then((r) => r.json());
return await response;
} catch (error) {
const errorObj = error as { name: string; message: string };
logger.error(`{ errorName: ${errorObj.name},
errorMessage: ${errorObj.message} }`);
return null;
}
}
27 changes: 20 additions & 7 deletions konfidency/loaders/productDetailsPage.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,16 @@ import { AppContext } from "../mod.ts";
import { toReview } from "../utils/transform.ts";
import { logger } from "@deco/deco/o11y";
export interface Props {
/**
* @description Rating type, default: helpfulScore
* @default "helpfulScore"
*/
sortField?: "helpfulScore" | "created" | "rating";
/**
* @description Default value: asc
* @default "asc"
*/
sortOrder?: "asc" | "desc";
/**
* @description The default value is 5
*/
@@ -14,7 +24,8 @@ export interface Props {
page?: number;
}
export default function productDetailsPage(
{ pageSize = 5, page = 1 }: Props,
{ pageSize = 5, page = 1, sortField = "helpfulScore", sortOrder = "asc" }:
Props,
_req: Request,
ctx: AppContext,
): ExtensionOf<ProductDetailsPage | null> {
@@ -24,12 +35,14 @@ export default function productDetailsPage(
return null;
}
try {
const reviews = await api["GET /:customer/:sku/summary"]({
customer,
page,
pageSize,
sku: productDetailsPage.product.inProductGroupWithID as string,
}).then((res) => res.json());
const reviews = await api
["GET /:customer/:sku/summary/:sortField,:sortOrder"]({
customer,
"sortField,:sortOrder": `${sortField},${sortOrder}`,
page,
pageSize,
sku: productDetailsPage.product.inProductGroupWithID as string,
}).then((res) => res.json());
const { aggregateRating, review } = toReview(reviews.reviews[0]);
return {
...productDetailsPage,
4 changes: 4 additions & 0 deletions konfidency/manifest.gen.ts
Original file line number Diff line number Diff line change
@@ -3,11 +3,15 @@
// This file is automatically updated during development when running `dev.ts`.

import * as $$$0 from "./loaders/productDetailsPage.ts";
import * as $$$$$$$$$0 from "./actions/submitReviews.ts";

const manifest = {
"loaders": {
"konfidency/loaders/productDetailsPage.ts": $$$0,
},
"actions": {
"konfidency/actions/submitReviews.ts": $$$$$$$$$0,
},
"name": "konfidency",
"baseUrl": import.meta.url,
};
9 changes: 7 additions & 2 deletions konfidency/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import type { PDPReview } from "./types.ts";
import type { PDPReview, ResponseWriteReview, WriteReview } from "./types.ts";

export interface API {
"GET /:customer/:sku/summary": {
"GET /:customer/:sku/summary/:sortField,:sortOrder": {
response: PDPReview;
searchParams: {
page: number;
pageSize: number;
};
};

"POST /:customer/:sku/review": {
response: ResponseWriteReview;
body: WriteReview;
};
}
24 changes: 24 additions & 0 deletions konfidency/utils/types.ts
Original file line number Diff line number Diff line change
@@ -42,3 +42,27 @@ export interface Composition {
export interface CustomerSettings {
minStarsHighlightPDP: number;
}

export interface WriteReview {
userId: string;
email: string;
rating: number;
text: string;
recommended?: boolean;
}

export interface ResponseWriteReview {
helpful: number;
unhelpful: number;
verified: boolean;
status: string;
_id: string;
created: string;
customer: string;
userId: string;
name: string;
sku: string;
text: string;
recommended: boolean;
rating: number;
}
Binary file added streamshop/1ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added streamshop/2ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added streamshop/3ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.