Skip to content

Commit f3e6ede

Browse files
authored
Video component (#567)
* Video component * Removed unnecessary props * Made the check conditional * Fixed sorting lessons in groups * Content widget auto added to page while course creation * Fixed the migration; Not throwing error on getCourse * Sanitized URL for video component
1 parent 9857acf commit f3e6ede

40 files changed

+832
-197
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

apps/web/.migrations/24-03-25_00-40-migrate-purchases-to-invoices.js renamed to apps/web/.migrations/24-03-25_00-40-migrate-purchases-to-invoices copy.js

File renamed without changes.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import mongoose from "mongoose";
2+
import { nanoid } from "nanoid";
3+
4+
function generateUniqueId() {
5+
return nanoid();
6+
}
7+
8+
mongoose.connect(process.env.DB_CONNECTION_STRING, {
9+
useNewUrlParser: true,
10+
useUnifiedTopology: true,
11+
});
12+
13+
const WidgetSchema = new mongoose.Schema({
14+
widgetId: { type: String, required: true, default: generateUniqueId },
15+
name: { type: String, required: true },
16+
deleteable: { type: Boolean, required: true, default: true },
17+
shared: { type: Boolean, required: true, default: false },
18+
settings: mongoose.Schema.Types.Mixed,
19+
});
20+
21+
const MediaSchema = new mongoose.Schema({
22+
mediaId: { type: String, required: true },
23+
originalFileName: { type: String, required: true },
24+
mimeType: { type: String, required: true },
25+
size: { type: Number, required: true },
26+
access: { type: String, required: true, enum: ["public", "private"] },
27+
thumbnail: String,
28+
caption: String,
29+
file: String,
30+
});
31+
32+
const PageSchema = new mongoose.Schema(
33+
{
34+
domain: { type: mongoose.Schema.Types.ObjectId, required: true },
35+
pageId: { type: String, required: true },
36+
type: {
37+
type: String,
38+
required: true,
39+
enum: ["product", "site", "blog", "community"],
40+
default: "product",
41+
},
42+
creatorId: { type: String, required: true },
43+
name: { type: String, required: true },
44+
layout: { type: [WidgetSchema], default: [] },
45+
draftLayout: { type: [WidgetSchema], default: [] },
46+
entityId: { type: String },
47+
deleteable: { type: Boolean, required: true, default: false },
48+
title: { type: String },
49+
description: String,
50+
socialImage: MediaSchema,
51+
robotsAllowed: { type: Boolean, default: true },
52+
draftTitle: String,
53+
draftDescription: String,
54+
draftSocialImage: MediaSchema,
55+
draftRobotsAllowed: Boolean,
56+
deleted: { type: Boolean, default: false },
57+
},
58+
{
59+
timestamps: true,
60+
},
61+
);
62+
63+
PageSchema.index(
64+
{
65+
domain: 1,
66+
pageId: 1,
67+
},
68+
{ unique: true },
69+
);
70+
71+
const Page = mongoose.model("Page", PageSchema);
72+
73+
const updateHeroVideo = async (page) => {
74+
console.log(`Updating homepage for domain: ${page.domain}`);
75+
const heroWidgets = page.layout.filter((widget) => widget.name === "hero");
76+
for (const heroWidget of heroWidgets) {
77+
heroWidget.settings.style = "normal";
78+
heroWidget.settings.mediaRadius = 2;
79+
if (
80+
heroWidget &&
81+
heroWidget.settings.youtubeLink &&
82+
!heroWidget.settings.youtubeLink.startsWith(
83+
"https://www.youtube.com/watch?v=",
84+
)
85+
) {
86+
heroWidget.settings.youtubeLink = `https://www.youtube.com/watch?v=${heroWidget.settings.youtubeLink}`;
87+
}
88+
}
89+
const heroWidgetsDraft = page.draftLayout.filter(
90+
(widget) => widget.name === "hero",
91+
);
92+
for (const heroWidget of heroWidgetsDraft) {
93+
heroWidget.settings.style = "normal";
94+
heroWidget.settings.mediaRadius = 2;
95+
if (
96+
heroWidget &&
97+
heroWidget.settings.youtubeLink &&
98+
!heroWidget.settings.youtubeLink.startsWith(
99+
"https://www.youtube.com/watch?v=",
100+
)
101+
) {
102+
heroWidget.settings.youtubeLink = `https://www.youtube.com/watch?v=${heroWidget.settings.youtubeLink}`;
103+
}
104+
}
105+
page.markModified("layout");
106+
page.markModified("draftLayout");
107+
await page.save();
108+
console.log(`Updated homepage for domain: ${page.domain}\n`);
109+
};
110+
111+
const migrateHeroVideo = async () => {
112+
const pages = await Page.find({ pageId: "homepage" });
113+
for (const page of pages) {
114+
try {
115+
await updateHeroVideo(page);
116+
} catch (error) {
117+
console.error(`Error updating homepage for domain: ${page.domain}`);
118+
console.error(error);
119+
}
120+
}
121+
};
122+
123+
(async () => {
124+
await migrateHeroVideo();
125+
mongoose.connection.close();
126+
})();

apps/web/app/(with-contexts)/(with-layout)/blog/blogs-list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useMemo, useState } from "react";
44
import { SkeletonCard } from "./skeleton-card";
5-
import { ContentCard } from "./content-card";
5+
import { BlogContentCard } from "./content-card";
66
import { PaginationControls } from "@components/public/pagination";
77
import { Constants, Course } from "@courselit/common-models";
88
import { useProducts } from "@/hooks/use-products";
@@ -34,7 +34,7 @@ export function BlogsList({
3434
<SkeletonCard key={index} />
3535
))
3636
: products.map((product: Course) => (
37-
<ContentCard
37+
<BlogContentCard
3838
key={product.courseId}
3939
product={product}
4040
/>

apps/web/app/(with-contexts)/(with-layout)/blog/content-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getPlanPrice } from "@courselit/utils";
55
import { truncate } from "@ui-lib/utils";
66
import Image from "next/image";
77

8-
export function ContentCard({ product }: { product: Course }) {
8+
export function BlogContentCard({ product }: { product: Course }) {
99
const defaultPlan = product.paymentPlans?.filter(
1010
(plan) => plan.planId === product.defaultPaymentPlan,
1111
)[0];

apps/web/app/(with-contexts)/(with-layout)/communities/communities-list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { useCommunities } from "@/hooks/use-communities";
4-
import { ContentCard } from "./content-card";
4+
import { CommunityContentCard } from "./content-card";
55
import { PaginationControls } from "@components/public/pagination";
66
import { Community } from "@courselit/common-models";
77
import { Users } from "lucide-react";
@@ -63,7 +63,7 @@ export function CommunitiesList({
6363
<SkeletonCard key={index} />
6464
))
6565
: communities.map((community: Community) => (
66-
<ContentCard
66+
<CommunityContentCard
6767
key={community.communityId}
6868
community={community}
6969
publicView={publicView}

apps/web/app/(with-contexts)/(with-layout)/communities/content-card.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
TooltipTrigger,
1111
} from "@components/ui/tooltip";
1212

13-
export function ContentCard({
13+
export function CommunityContentCard({
1414
community,
1515
publicView = true,
1616
}: {
@@ -50,20 +50,24 @@ export function ContentCard({
5050
members
5151
</span>
5252
</div>
53-
<TooltipProvider>
54-
<Tooltip>
55-
<TooltipTrigger asChild>
56-
{community.enabled ? (
57-
<CheckCircle className="h-4 w-4 text-muted-foreground" />
58-
) : (
59-
<CircleDashed className="h-4 w-4 text-muted-foreground" />
60-
)}
61-
</TooltipTrigger>
62-
<TooltipContent>
63-
{community.enabled ? "Enabled" : "Draft"}
64-
</TooltipContent>
65-
</Tooltip>
66-
</TooltipProvider>
53+
{!publicView && (
54+
<TooltipProvider>
55+
<Tooltip>
56+
<TooltipTrigger asChild>
57+
{community.enabled ? (
58+
<CheckCircle className="h-4 w-4 text-muted-foreground" />
59+
) : (
60+
<CircleDashed className="h-4 w-4 text-muted-foreground" />
61+
)}
62+
</TooltipTrigger>
63+
<TooltipContent>
64+
{community.enabled
65+
? "Enabled"
66+
: "Draft"}
67+
</TooltipContent>
68+
</Tooltip>
69+
</TooltipProvider>
70+
)}
6771
</div>
6872
</CardContent>
6973
</Card>

0 commit comments

Comments
 (0)