Skip to content

Commit a32de0c

Browse files
committed
adjust lock and preview
1 parent e7e4c3c commit a32de0c

4 files changed

Lines changed: 42 additions & 11 deletions

File tree

‎frontend/main/src/components/user/MemberValidShow.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ export default function MemberValidShow({
2929
sectionLesson?.access_mode === AccessMode.closed &&
3030
auth?.currentUser?.uid
3131
) {
32-
<CheckMember user={user} notValidComponent={notValidComponent}>
33-
{children}
34-
</CheckMember>;
32+
return (
33+
<CheckMember user={user} notValidComponent={notValidComponent}>
34+
{children}
35+
</CheckMember>
36+
);
3537
}
3638
return <>{notValidComponent}</>;
3739
}
@@ -45,10 +47,9 @@ const CheckMember = ({
4547
children: JSX.Element;
4648
notValidComponent: JSX.Element;
4749
}): JSX.Element => {
48-
const auth = useAuth();
4950
const { member, team } = useIsMember(user);
50-
51-
if (auth?.currentUser?.uid && (member || team)) {
51+
console.log('check', member, team);
52+
if (member || team) {
5253
return <section>{children}</section>;
5354
}
5455
return <>{notValidComponent}</>;

‎frontend/main/src/models/post.model.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { AccessMode } from './access.model';
55
import { ListBlockChildrenResponse } from '@notionhq/client/build/src/api-endpoints';
66
import { NotionBlock } from '@9gustin/react-notion-render';
77
export interface Post {
8-
//Auto Generated By Cloud Function
98
_id?: string;
109
id: string;
1110
_type: PostType;

‎frontend/main/src/pages/[...permalink].tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,13 @@ export const getStaticProps: GetStaticProps<StaticPropsResult> = async ({
166166
}
167167
//If Lesson we need to use different slug and get course
168168
if (lesson === PostType.lesson && lessonPath) {
169+
course = await getNotionPageBlocks({ preview, _type: type, slug });
169170
post = await getNotionPageBlocks({
170171
preview,
171172
_type: PostType.lesson,
172173
slug: lessonPath,
174+
course: course || undefined,
173175
});
174-
course = await getNotionPageBlocks({ preview, _type: type, slug });
175176
} else {
176177
// Moved to Notion June 2022
177178
if (type == PostType.podcast) {

‎frontend/main/src/services/notion.server.ts‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export const getNotionDbByType = (_type: string) => {
4646

4747
// CodingCat.dev
4848

49-
//TODO: Finish theses
5049
export const getPageById = async ({
5150
_id,
5251
_type,
@@ -466,10 +465,38 @@ export const queryByPublished = async (
466465
export const queryNotionDbBySlug = async (
467466
_type: string,
468467
slug: string,
469-
preview?: boolean
468+
preview?: boolean,
469+
course?: Post
470470
) => {
471471
let filter: any;
472472
let sorts: any;
473+
474+
//TODO: If database query with rollup url worked we wouldn't need this
475+
if (course) {
476+
const rawSections = await querySectionsByCourseId(course?.id, preview);
477+
const sectionFromSlug: any = rawSections.results
478+
.filter(
479+
(s: any) =>
480+
`${s.properties?.lesson_slug?.rollup?.array?.at(0)?.url}` ===
481+
`${slug}`
482+
)
483+
?.at(0);
484+
if (
485+
sectionFromSlug?.properties?.lesson_id?.rollup?.array?.at(0)?.formula
486+
?.string
487+
) {
488+
const page = await getPageById({
489+
_id: sectionFromSlug?.properties?.lesson_id?.rollup?.array?.at(0)
490+
?.formula?.string,
491+
_type: PostType.lesson,
492+
});
493+
console.log(page);
494+
const raw = { results: [page] } as QueryDatabaseResponse;
495+
return await formatPosts(raw, _type, preview);
496+
}
497+
return { results: [] };
498+
}
499+
473500
filter = {
474501
and: [
475502
{
@@ -533,23 +560,26 @@ export const queryNotionDbBySlug = async (
533560
filter,
534561
sorts,
535562
});
563+
536564
return await formatPosts(raw, _type, preview);
537565
};
538566

539567
export const getNotionPageBlocks = async ({
540568
_type,
541569
slug,
542570
preview,
571+
course,
543572
}: {
544573
_type: PostType;
545574
slug?: string;
546575
preview: boolean | undefined;
576+
course?: Post;
547577
}) => {
548578
let pageId;
549579
let page;
550580

551581
if (slug) {
552-
let raw = await queryNotionDbBySlug(_type, slug, preview);
582+
let raw = await queryNotionDbBySlug(_type, slug, preview, course);
553583
if (!raw.results.length) {
554584
return null;
555585
}

0 commit comments

Comments
 (0)