Skip to content

Commit e096d72

Browse files
committed
Created independent content-management for videos
1 parent 099d235 commit e096d72

File tree

13 files changed

+152
-47
lines changed

13 files changed

+152
-47
lines changed

app/(root)/resources/[id]/page.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ const Page = async ({ params }: { params: { id: string } }) => {
3838
</div>
3939
)}
4040
<div>
41-
<DownloadButton
42-
downloadLink={resource.downloadLink}
43-
id={resource._id}
44-
/>
41+
<DownloadButton link={resource.link} id={resource._id} />
4542

4643
<div className="relative ml-28 mt-6 hidden h-[218px] w-[425px] lg:flex">
4744
{resource.sequel && (

app/(root)/resources/page.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ const Page = async ({ searchParams }: Props) => {
1818
query: searchParams?.query || "",
1919
category: searchParams?.category || "",
2020
page: 1,
21+
type: "resource",
2122
});
2223

23-
const resourcesPlaylist: ResourcePlaylist[] = await getResourcesPlaylist();
24+
const resourcesPlaylist: ResourcePlaylist[] = await getResourcesPlaylist({
25+
type: "resource",
26+
});
2427

2528
return (
2629
<main className="flex-center paddings mx-auto w-full max-w-screen-2xl flex-col">
@@ -50,7 +53,7 @@ const Page = async ({ searchParams }: Props) => {
5053
id={resource._id}
5154
image={resource.image}
5255
downloadNumber={resource.views}
53-
downloadLink={resource.downloadLink}
56+
link={resource.link}
5457
/>
5558
))
5659
) : (
@@ -79,7 +82,7 @@ const Page = async ({ searchParams }: Props) => {
7982
id={resource._id}
8083
image={resource.image}
8184
downloadNumber={resource.views}
82-
downloadLink={resource.downloadLink}
85+
link={resource.link}
8386
/>
8487
))}
8588
</div>

app/(root)/videos/page.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ const Page = async ({ searchParams }: Props) => {
1818
query: searchParams?.query || "",
1919
category: searchParams?.category || "",
2020
page: 1,
21+
type: "video",
2122
});
2223

23-
const resourcesPlaylist: ResourcePlaylist[] = await getResourcesPlaylist();
24+
const resourcesPlaylist: ResourcePlaylist[] = await getResourcesPlaylist({
25+
type: "video",
26+
});
2427

2528
return (
2629
<main className="flex-center paddings mx-auto w-full max-w-screen-2xl flex-col">
@@ -49,8 +52,8 @@ const Page = async ({ searchParams }: Props) => {
4952
title={resource.title}
5053
id={resource._id}
5154
image={resource.image}
52-
downloadNumber={resource.views}
53-
downloadLink={resource.downloadLink}
55+
downloadNumber={resource.category}
56+
link={resource.link}
5457
isVideo
5558
/>
5659
))
@@ -79,8 +82,8 @@ const Page = async ({ searchParams }: Props) => {
7982
title={resource.title}
8083
id={resource._id}
8184
image={resource.image}
82-
downloadNumber={resource.views}
83-
downloadLink={resource.downloadLink}
85+
downloadNumber={resource.category}
86+
link={resource.link}
8487
isVideo
8588
/>
8689
))}

components/atoms/DownloadButton.tsx

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

33
import { Button } from "@/components/ui/button";
44

5-
import { incrementDownloadsById } from "@/sanity/actions";
5+
import { newInteractById } from "@/sanity/actions";
66

77
import type { DownloadButtonProps } from "@/types";
88

9-
const DownloadButton = ({ downloadLink, id }: DownloadButtonProps) => {
9+
const DownloadButton = ({ link, id }: DownloadButtonProps) => {
1010
const handleClick = async (): Promise<void> => {
11-
await incrementDownloadsById({ id });
11+
await newInteractById({ id });
1212

1313
const newWindow: Window | null = window.open(
14-
downloadLink,
14+
link,
1515
"_blank",
1616
"noopener,noreferrer"
1717
);

components/shared/ContentCard.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const ContentCard = ({
1010
title,
1111
image,
1212
downloadNumber,
13-
downloadLink,
13+
link,
1414
isVideo,
1515
}: ContentCardProps) => {
16-
const href = isVideo ? downloadLink : `/resources/${id}`;
16+
const href = isVideo ? link : `/resources/${id}`;
1717

1818
return (
1919
<Card
@@ -62,20 +62,28 @@ const ContentCard = ({
6262
</CardHeader>
6363
</Link>
6464
<CardContent className="flex-between mt-4 p-0">
65-
<div className="flex-center body-medium gap-1.5 text-slate-950 dark:text-white">
66-
<Image
67-
src="/assets/icons/downloads.svg"
68-
width={20}
69-
height={20}
70-
alt="download"
71-
/>
65+
<div
66+
className={`flex-center body-medium gap-1.5 ${
67+
isVideo
68+
? "capitalize text-slate-400 dark:text-white-500"
69+
: "text-slate-950 dark:text-white"
70+
}`}
71+
>
72+
{!isVideo && (
73+
<Image
74+
src="/assets/icons/downloads.svg"
75+
width={20}
76+
height={20}
77+
alt="download"
78+
/>
79+
)}
7280
{downloadNumber}
7381
</div>
7482
<Link
7583
href={href}
7684
className="flex-center text-gradient_purple-blue body-semibold gap-1.5"
7785
>
78-
Download Now
86+
{isVideo ? "Watch" : "Download"} Now
7987
<Image
8088
src="/assets/icons/arrow-blue.svg"
8189
width={13}

components/shared/SearchForm.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const SearchForm = () => {
3434
}
3535

3636
router.push(newUrl, { scroll: false });
37-
console.log("newUrl", newUrl);
3837
}, 300);
3938

4039
return () => clearTimeout(delayDebounceFn);

constants/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ export const filterOptions: string[] = [
4444
"all",
4545
"math",
4646
"computer science",
47-
"Software Engineering",
47+
"software engineering",
48+
];
49+
50+
export const videoFilterOptions: string[] = [
51+
"frontend",
52+
"backend",
53+
"fullstack",
54+
"hybrid",
4855
];
4956

5057
/**

sanity/actions.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { groq } from "next-sanity";
22
import { readClient, writeClient } from "./lib/client";
33
import { buildQuery } from "./utils";
44

5-
import type { GetResourcesParams } from "@/types";
5+
import type { DocTypeParams, GetResourcesParams } from "@/types";
66

77
/**
88
* Fetch a list of resources based on search criteria.
@@ -11,26 +11,27 @@ import type { GetResourcesParams } from "@/types";
1111
* @param {string} params.query - The search query to filter resources by title or content.
1212
* @param {string | undefined} params.category - The category to filter resources by.
1313
* @param {number} params.page - The page number for paginated results.
14+
* @param {string} params.type - The type of resource to fetch.
1415
* @returns {Promise<Object[] | undefined>} A promise that resolves to an array of resource objects if found, or undefined if an error occurred.
1516
*
1617
* @throws {Error} Throws an error if there was an issue fetching the resources.
1718
*/
1819
export const getResources = async (
1920
params: GetResourcesParams
2021
): Promise<Object[] | undefined | any> => {
21-
const { query, category, page }: GetResourcesParams = params;
22+
const { query, category, page, type }: GetResourcesParams = params;
2223

2324
try {
2425
const resources = await readClient.fetch(
2526
groq`${buildQuery({
26-
type: "resource",
27+
type,
2728
query,
2829
category,
29-
page: page,
30+
page,
3031
})}{
3132
_id,
3233
title,
33-
downloadLink,
34+
link,
3435
"image": poster.asset->url,
3536
views,
3637
slug,
@@ -58,18 +59,22 @@ export const getResources = async (
5859
*
5960
* @throws {Error} Throws an error if there was an issue fetching the playlist.
6061
*/
61-
export const getResourcesPlaylist = async (): Promise<
62-
Object[] | undefined | any
63-
> => {
62+
export const getResourcesPlaylist = async (
63+
params: DocTypeParams
64+
): Promise<Object[] | undefined | any> => {
65+
const { type }: DocTypeParams = params;
66+
6467
try {
6568
const resources = await readClient.fetch(
66-
groq`*[_type == "resourcePlaylist"]{
69+
groq`*[_type == "${
70+
type === "video" ? "videoPlaylist" : "resourcePlaylist"
71+
}"]{
6772
_id,
6873
title,
6974
resources[0...6]->{
7075
title,
7176
_id,
72-
downloadLink,
77+
link,
7378
"image": poster.asset->url,
7479
views,
7580
category
@@ -101,7 +106,7 @@ export const getResourceById = async ({
101106
groq`*[_type == "resource" && _id == "${id}"]{
102107
_id,
103108
title,
104-
downloadLink,
109+
link,
105110
"image": poster.asset->url,
106111
views,
107112
slug,
@@ -129,7 +134,7 @@ export const getResourceById = async ({
129134
*
130135
* @throws {Error} Throws an error if there was an issue incrementing the download count.
131136
*/
132-
export const incrementDownloadsById = async ({
137+
export const newInteractById = async ({
133138
id,
134139
}: {
135140
id: string;
@@ -145,9 +150,9 @@ export const incrementDownloadsById = async ({
145150
throw new Error(`Resource with ID ${id} not found.`);
146151
}
147152

148-
const views = resource[0].views + 1;
153+
const updatedValue = resource[0].views + 1;
149154

150-
await writeClient.patch(id).set({ views }).commit();
155+
await writeClient.patch(id).inc({ views: updatedValue });
151156
} catch (error) {
152157
console.error(error);
153158
}

sanity/schemas/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import resource from "./resource.schema";
2+
import video from "./video.schema";
23
import resourcePlaylist from "./resource-playlist.schema";
4+
import videoPlaylist from "./video-playlist.schema";
35

4-
const schemas = [resource, resourcePlaylist];
6+
const schemas = [resource, resourcePlaylist, video, videoPlaylist];
57

68
export default schemas;

sanity/schemas/resource.schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const schema = {
4040
to: [{ type: "resource" }],
4141
},
4242
{
43-
name: "downloadLink",
44-
title: "Download Link",
43+
name: "link",
44+
title: "Link",
4545
type: "url",
4646
validation: (Rule: any) => Rule.required(),
4747
},

0 commit comments

Comments
 (0)