Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
126 changes: 126 additions & 0 deletions apps/web/.migrations/30-03-25_00-40-migrate-hero-video.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import mongoose from "mongoose";
import { nanoid } from "nanoid";

function generateUniqueId() {
return nanoid();
}

mongoose.connect(process.env.DB_CONNECTION_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true,
});

const WidgetSchema = new mongoose.Schema({
widgetId: { type: String, required: true, default: generateUniqueId },
name: { type: String, required: true },
deleteable: { type: Boolean, required: true, default: true },
shared: { type: Boolean, required: true, default: false },
settings: mongoose.Schema.Types.Mixed,
});

const MediaSchema = new mongoose.Schema({
mediaId: { type: String, required: true },
originalFileName: { type: String, required: true },
mimeType: { type: String, required: true },
size: { type: Number, required: true },
access: { type: String, required: true, enum: ["public", "private"] },
thumbnail: String,
caption: String,
file: String,
});

const PageSchema = new mongoose.Schema(
{
domain: { type: mongoose.Schema.Types.ObjectId, required: true },
pageId: { type: String, required: true },
type: {
type: String,
required: true,
enum: ["product", "site", "blog", "community"],
default: "product",
},
creatorId: { type: String, required: true },
name: { type: String, required: true },
layout: { type: [WidgetSchema], default: [] },
draftLayout: { type: [WidgetSchema], default: [] },
entityId: { type: String },
deleteable: { type: Boolean, required: true, default: false },
title: { type: String },
description: String,
socialImage: MediaSchema,
robotsAllowed: { type: Boolean, default: true },
draftTitle: String,
draftDescription: String,
draftSocialImage: MediaSchema,
draftRobotsAllowed: Boolean,
deleted: { type: Boolean, default: false },
},
{
timestamps: true,
},
);

PageSchema.index(
{
domain: 1,
pageId: 1,
},
{ unique: true },
);

const Page = mongoose.model("Page", PageSchema);

const updateHeroVideo = async (page) => {
console.log(`Updating homepage for domain: ${page.domain}`);
const heroWidgets = page.layout.filter((widget) => widget.name === "hero");
for (const heroWidget of heroWidgets) {
heroWidget.settings.style = "normal";
heroWidget.settings.mediaRadius = 2;
if (
heroWidget &&
heroWidget.settings.youtubeLink &&
!heroWidget.settings.youtubeLink.startsWith(
"https://www.youtube.com/watch?v=",
)
) {
heroWidget.settings.youtubeLink = `https://www.youtube.com/watch?v=${heroWidget.settings.youtubeLink}`;
}
}
const heroWidgetsDraft = page.draftLayout.filter(
(widget) => widget.name === "hero",
);
for (const heroWidget of heroWidgetsDraft) {
heroWidget.settings.style = "normal";
heroWidget.settings.mediaRadius = 2;
if (
heroWidget &&
heroWidget.settings.youtubeLink &&
!heroWidget.settings.youtubeLink.startsWith(
"https://www.youtube.com/watch?v=",
)
) {
heroWidget.settings.youtubeLink = `https://www.youtube.com/watch?v=${heroWidget.settings.youtubeLink}`;
}
}
page.markModified("layout");
page.markModified("draftLayout");
await page.save();
console.log(`Updated homepage for domain: ${page.domain}\n`);
};

const migrateHeroVideo = async () => {
const pages = await Page.find({ pageId: "homepage" });
for (const page of pages) {
try {
await updateHeroVideo(page);
} catch (error) {
console.error(`Error updating homepage for domain: ${page.domain}`);
console.error(error);
}
}
};

(async () => {
await migrateHeroVideo();
mongoose.connection.close();
})();
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useMemo, useState } from "react";
import { SkeletonCard } from "./skeleton-card";
import { ContentCard } from "./content-card";
import { BlogContentCard } from "./content-card";
import { PaginationControls } from "@components/public/pagination";
import { Constants, Course } from "@courselit/common-models";
import { useProducts } from "@/hooks/use-products";
Expand Down Expand Up @@ -34,7 +34,7 @@ export function BlogsList({
<SkeletonCard key={index} />
))
: products.map((product: Course) => (
<ContentCard
<BlogContentCard
key={product.courseId}
product={product}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getPlanPrice } from "@courselit/utils";
import { truncate } from "@ui-lib/utils";
import Image from "next/image";

export function ContentCard({ product }: { product: Course }) {
export function BlogContentCard({ product }: { product: Course }) {
const defaultPlan = product.paymentPlans?.filter(
(plan) => plan.planId === product.defaultPaymentPlan,
)[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { useCommunities } from "@/hooks/use-communities";
import { ContentCard } from "./content-card";
import { CommunityContentCard } from "./content-card";
import { PaginationControls } from "@components/public/pagination";
import { Community } from "@courselit/common-models";
import { Users } from "lucide-react";
Expand Down Expand Up @@ -63,7 +63,7 @@ export function CommunitiesList({
<SkeletonCard key={index} />
))
: communities.map((community: Community) => (
<ContentCard
<CommunityContentCard
key={community.communityId}
community={community}
publicView={publicView}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TooltipTrigger,
} from "@components/ui/tooltip";

export function ContentCard({
export function CommunityContentCard({
community,
publicView = true,
}: {
Expand Down Expand Up @@ -50,20 +50,24 @@ export function ContentCard({
members
</span>
</div>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
{community.enabled ? (
<CheckCircle className="h-4 w-4 text-muted-foreground" />
) : (
<CircleDashed className="h-4 w-4 text-muted-foreground" />
)}
</TooltipTrigger>
<TooltipContent>
{community.enabled ? "Enabled" : "Draft"}
</TooltipContent>
</Tooltip>
</TooltipProvider>
{!publicView && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
{community.enabled ? (
<CheckCircle className="h-4 w-4 text-muted-foreground" />
) : (
<CircleDashed className="h-4 w-4 text-muted-foreground" />
)}
</TooltipTrigger>
<TooltipContent>
{community.enabled
? "Enabled"
: "Draft"}
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
</div>
</CardContent>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SiteInfoContext } from "@components/contexts";
import { Badge } from "@components/ui/badge";
import { truncate } from "@ui-lib/utils";

export function ContentCard({ product }: { product: Course }) {
export function ProductContentCard({ product }: { product: Course }) {
const siteinfo = useContext(SiteInfoContext);
const defaultPlan = product.paymentPlans?.filter(
(plan) => plan.planId === product.defaultPaymentPlan,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use client";

import { useState, useEffect, useContext } from "react";
// import { ContentCard } from "@/components/admin/my-content/content-card";
// import { SkeletonCard } from "@/components/admin/my-content/skeleton-card";
import type { ContentItem } from "@/components/admin/my-content/content";
import { AddressContext, ProfileContext } from "@components/contexts";
import { MY_CONTENT_HEADER } from "@ui-config/strings";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ export default function ContentPage() {
(a: any, b: any) =>
(
section.lessonsOrder as any[]
).indexOf(a.lessonId) -
)?.indexOf(a.lessonId) -
(
section.lessonsOrder as any[]
).indexOf(b.lessonId),
)?.indexOf(b.lessonId),
)
.map((lesson: Lesson) => ({
id: lesson.lessonId,
Expand Down
1 change: 1 addition & 0 deletions apps/web/components/admin/page-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export default function PageEditor({
onDelete={deleteWidget}
state={state as AppState}
dispatch={dispatch || (() => {})}
key={selectedWidget}
/>
),
[selectedWidget],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ function LessonSection({
)
.sort(
(a: any, b: any) =>
(group.lessonsOrder as any[]).indexOf(
(group.lessonsOrder as any[])?.indexOf(
a.lessonId,
) -
(group.lessonsOrder as any[]).indexOf(
(group.lessonsOrder as any[])?.indexOf(
b.lessonId,
),
)
Expand Down
26 changes: 18 additions & 8 deletions apps/web/graphql/courses/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const setupCourse = async ({
ctx,
});
page.entityId = course.courseId;
page.layout = getInitialLayout();
page.layout = getInitialLayout(type);
await page.save();

return course;
Expand Down Expand Up @@ -205,8 +205,8 @@ export const setupBlog = async ({
return course;
};

const getInitialLayout = () => {
return [
const getInitialLayout = (type: "course" | "download") => {
const layout: Record<string, any>[] = [
{
name: "header",
deleteable: false,
Expand All @@ -215,10 +215,20 @@ const getInitialLayout = () => {
{
name: "banner",
},
{
name: "footer",
deleteable: false,
shared: true,
},
];
if (type === Constants.CourseType.COURSE) {
layout.push({
name: "content",
settings: {
title: "Curriculum",
headerAlignment: "center",
},
});
}
layout.push({
name: "footer",
deleteable: false,
shared: true,
});
return layout;
};
2 changes: 1 addition & 1 deletion apps/web/graphql/courses/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const getCourse = async (
// course.groups = accessibleGroups;
return await formatCourse(course.courseId, ctx);
} else {
throw new Error(responses.item_not_found);
return null;
}
};

Expand Down
4 changes: 2 additions & 2 deletions apps/web/graphql/lessons/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export const getGroupedLessons = async (
)
.sort(
(a: GroupLessonItem, b: GroupLessonItem) =>
group.lessonsOrder.indexOf(a.lessonId) -
group.lessonsOrder.indexOf(b.lessonId),
group.lessonsOrder?.indexOf(a.lessonId) -
group.lessonsOrder?.indexOf(b.lessonId),
),
);
}
Expand Down
6 changes: 3 additions & 3 deletions apps/web/graphql/pages/page-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export const homePageTemplate = [
},
buttonAction: "/products",
buttonCaption: "Ask user to take action",
youtubeLink: "VLVcZB2-udk",
youtubeLink: "https://www.youtube.com/watch?v=VLVcZB2-udk",
alignment: "right",
style: "card",
style: "normal",
buttonForeground: "#fefbfb",
mediaRadius: 56,
mediaRadius: 2,
horizontalPadding: 100,
verticalPadding: 88,
titleFontSize: 5,
Expand Down
4 changes: 2 additions & 2 deletions apps/web/pages/course/[slug]/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ export function formatCourse(
.filter((lesson: Lesson) => lesson.groupId === group.id)
.sort(
(a: any, b: any) =>
group.lessonsOrder.indexOf(a.lessonId) -
group.lessonsOrder.indexOf(b.lessonId),
group.lessonsOrder?.indexOf(a.lessonId) -
group.lessonsOrder?.indexOf(b.lessonId),
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/common-widgets/src/content/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export default function Widget({
.filter((lesson: Lesson) => lesson.groupId === group.id)
.sort(
(a: any, b: any) =>
group.lessonsOrder.indexOf(a.lessonId) -
group.lessonsOrder.indexOf(b.lessonId),
group.lessonsOrder?.indexOf(a.lessonId) -
group.lessonsOrder?.indexOf(b.lessonId),
);
});
setFormattedCourse(formattedCourse);
Expand Down
Loading
Loading