Skip to content

Commit 6e3dc16

Browse files
merged dev and fixed conflict
2 parents 4eeea1b + 6b196f3 commit 6e3dc16

File tree

5 files changed

+121
-87
lines changed

5 files changed

+121
-87
lines changed

backend/firebase/functions/src/posts/posts.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ export const onPostCreate = functions.firestore
2222
}
2323

2424
// Rules should require that all posts have a status of
25-
// history on initial create
25+
// history on initial create, that the course is closed.
2626
const id = uuid();
27-
await firestore
28-
.doc(`posts/${context.params.postId}/history/${id}`)
29-
.set({ ...post, id, postId: context.params.postId, authors });
27+
await firestore.doc(`posts/${context.params.postId}/history/${id}`).set({
28+
...post,
29+
id,
30+
postId: context.params.postId,
31+
authors,
32+
accessSettings: {
33+
accessMode: 'closed',
34+
},
35+
});
3036

3137
// Set current post to history
3238
return firestore
@@ -60,6 +66,7 @@ export const onHistoryWrite = functions.firestore
6066
.document('posts/{postId}/history/{id}')
6167
.onWrite(async (snap, context) => {
6268
const post = snap.before.data();
69+
const postUpdate = snap.after.data();
6370

6471
if (!post) {
6572
console.log('post missing data');
@@ -75,13 +82,32 @@ export const onHistoryWrite = functions.firestore
7582
if (author) {
7683
authors.push(author);
7784
}
78-
79-
return firestore
85+
console.log('Adding missing author.');
86+
await firestore
8087
.doc(`posts/${context.params.postId}/history/${context.params.id}`)
8188
.set({ authors }, { merge: true });
82-
} else {
83-
return;
8489
}
90+
91+
// Update Missing post settings
92+
if (!post.accessSettings && postUpdate && !postUpdate.accessSettings) {
93+
console.log(
94+
'History had accessSettings of: ',
95+
JSON.stringify(post.accessSettings)
96+
);
97+
console.log('Updating those to be closed.');
98+
99+
await firestore
100+
.doc(`posts/${context.params.postId}/history/${context.params.id}`)
101+
.set(
102+
{
103+
accessSettings: {
104+
accessMode: 'closed',
105+
},
106+
},
107+
{ merge: true }
108+
);
109+
}
110+
return false;
85111
});
86112

87113
async function getPostCreatorProfile(post: any) {

frontend/main/src/components/settings/SettingsLinks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function UserProfile() {
1616
<a className={links}>Membership</a>
1717
</Link>
1818
</li>
19-
<li>
19+
{/* <li>
2020
<Link href="/user/notifications">
2121
<a className={links}>Notifications</a>
2222
</Link>
@@ -25,7 +25,7 @@ export default function UserProfile() {
2525
<Link href="/user/support">
2626
<a className={links}>Contact Support</a>
2727
</Link>
28-
</li>
28+
</li> */}
2929
</ul>
3030
</nav>
3131
);

frontend/main/src/components/settings/UserProfile.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ export default function UserProfile(): JSX.Element {
6464

6565
return (
6666
<section className="grid gap-4">
67-
<section className="grid gap-4 p-4 rounded-md bg-primary-900 text-basics-50">
67+
<section className="grid gap-2 p-4 rounded-md bg-primary-900 text-basics-50">
6868
<h2 className="font-sans text-2xl">User</h2>
6969
<form className="grid gap-4">
70-
<div className="grid gap-1">
70+
<div className="grid gap-4">
7171
{profile.photoURL ? (
7272
<img
7373
className="w-24"
@@ -85,13 +85,11 @@ export default function UserProfile(): JSX.Element {
8585
alt="Avatar Image Placeholder"
8686
/>
8787
)}
88-
<div className="w-48 ">
89-
<UserProfileCloudinaryUpload
90-
profile={profile}
91-
setProfile={setProfile}
92-
user={user}
93-
/>
94-
</div>
88+
<UserProfileCloudinaryUpload
89+
profile={profile}
90+
setProfile={setProfile}
91+
user={user}
92+
/>
9593
</div>
9694
<div className="grid gap-1">
9795
<label htmlFor="name">Name</label>

frontend/main/src/layout/Footer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default function Footer({
109109
</section>
110110
</section>
111111
{/* HELPFUL LINKS */}
112-
<section className="grid grid-cols-1 gap-4 lg:justify-self-end 2xl:justify-self-center">
112+
<section className="grid grid-cols-1 lg:justify-self-end 2xl:justify-self-center">
113113
<h4 className="underline whitespace-nowrap">Helpful Links</h4>
114114
<div className="grid w-64 grid-cols-2 gap-4">
115115
{site?.pageLinks?.map((pageLink, i) => (
@@ -136,10 +136,10 @@ export default function Footer({
136136
</div>
137137
</section>
138138
{/* NEWSLETTER */}
139-
<section className="grid grid-cols-1 gap-4 lg:col-start-1 lg:col-end-3 lg:justify-self-center 2xl:justify-self-end 2xl:col-start-3 2xl:col-end-4">
139+
<section className="grid grid-cols-1 lg:col-start-1 lg:col-end-3 lg:justify-self-center 2xl:justify-self-end 2xl:col-start-3 2xl:col-end-4">
140140
<h4 className="underline">Newsletter</h4>
141-
<p>Subscribe for all the latest updates.</p>
142-
<form className="grid grid-cols-1 gap-4">
141+
<p className="text-xl">Subscribe for all the latest updates.</p>
142+
<form className="grid grid-cols-1">
143143
<label htmlFor="subEmail">Email</label>
144144
<div className="flex flex-wrap gap-4 lg:flex-nowrap">
145145
<input

frontend/main/src/pages/course/[coursePath]/index.tsx

Lines changed: 74 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import OutsideClick from '@/components/OutsideClick';
2424
import { useUser } from '@/utils/auth/useUser';
2525
import { useEffect } from 'react';
2626
import { isUserCourseSub, isUserMember, isUserTeam } from '@/services/api';
27-
import { combineLatest } from 'rxjs';
27+
import { combineLatest, of } from 'rxjs';
2828
import { take } from 'rxjs/operators';
2929
import BreakBarLeft from '@/components/home/BreakBarLeft';
3030

@@ -52,14 +52,15 @@ export default function Post({
5252
const { user } = useUser();
5353

5454
useEffect(() => {
55-
if (user && user.uid && product) {
55+
if (user && user.uid) {
5656
const isUserTeam$ = isUserTeam(user.uid);
5757
const isUserMember$ = isUserMember(user.uid);
58-
const isUserCourseSub$ = isUserCourseSub(user.uid, product.id);
58+
const isUserCourseSub$ = product
59+
? isUserCourseSub(user.uid, product.id)
60+
: of(false);
5961
combineLatest([isUserTeam$, isUserMember$, isUserCourseSub$])
6062
.pipe(take(1))
6163
.subscribe((c) => {
62-
console.log(c);
6364
setMember(c.includes(true));
6465
});
6566
}
@@ -76,7 +77,7 @@ export default function Post({
7677
{post.title}
7778
</h1>
7879
<div className="flex-shrink-0">
79-
<Link href={`/${post.type}`}>
80+
<Link href={`/courses`}>
8081
<a role="link" className="no-underline btn-secondary">
8182
{/* capitalize Courses */}
8283
{`back to ${
@@ -91,27 +92,23 @@ export default function Post({
9192
<>
9293
<section className="flex items-center gap-2">
9394
{post.authors?.map((author, i) => (
94-
<>
95-
<section
96-
className="flex items-center flex-shrink-0 space-x-4"
97-
key={i}
98-
>
99-
{author.photoURL && (
100-
<img
101-
src={author.photoURL}
102-
alt="instructor"
103-
className="w-12 border-2 rounded-full border-primary-50 dark:border-primary-50"
104-
/>
105-
)}
95+
<section
96+
className="flex items-center flex-shrink-0 space-x-4"
97+
key={i}
98+
>
99+
{author.photoURL && (
100+
<img
101+
src={author.photoURL}
102+
alt="instructor"
103+
className="w-12 border-2 rounded-full border-primary-50 dark:border-primary-50"
104+
/>
105+
)}
106106

107-
<div className="grid content-start">
108-
<h3 className="m-0 text-base font-light">Author</h3>
109-
<h4 className="m-0 text-xl">
110-
{author.displayName}
111-
</h4>
112-
</div>
113-
</section>
114-
</>
107+
<div className="grid content-start">
108+
<h3 className="m-0 text-base font-light">Author</h3>
109+
<h4 className="m-0 text-xl">{author.displayName}</h4>
110+
</div>
111+
</section>
115112
))}
116113
</section>
117114

@@ -171,53 +168,66 @@ export default function Post({
171168
</div>
172169
)}
173170
<div className="grid grid-cols-1 gap-2 p-4 justify-items-center">
174-
{member ? (
171+
{post.accessSettings?.accessMode !== AccessMode.open ? (
175172
<>
176-
{post.sections &&
177-
post.sections.map((section, i) => {
178-
return (
179-
<>
180-
{section.lessons && (
181-
<Link
182-
href={`/course/${post.slug}/lesson/${section.lessons[0].slug}`}
183-
>
184-
<a>
185-
<button className="btn-primary">
186-
Start Course
187-
</button>
188-
</a>
189-
</Link>
190-
)}
191-
</>
192-
);
193-
})}
173+
{member ? (
174+
<>
175+
{post.sections &&
176+
post.sections[0] &&
177+
post.sections[0].lessons &&
178+
post.sections[0].lessons[0] && (
179+
<Link
180+
href={`/course/${post.slug}/lesson/${post.sections[0].lessons[0].slug}`}
181+
>
182+
<a>
183+
<button className="btn-primary">
184+
Start Course
185+
</button>
186+
</a>
187+
</Link>
188+
)}
189+
</>
190+
) : (
191+
<>
192+
{product && (
193+
<p className="p-2 text-xl text-basics-900">
194+
${post.accessSettings?.price}
195+
</p>
196+
)}
197+
<div className="flex items-center justify-center space-x-4 flex-nowrap">
198+
{product && (
199+
<CourseBuy
200+
product={product}
201+
setShowMustSignin={setShowMustSignin}
202+
/>
203+
)}
204+
<Link href="/membership">
205+
<a>
206+
<button className="btn-primary">
207+
Become a Member
208+
</button>
209+
</a>
210+
</Link>
211+
</div>
212+
</>
213+
)}
194214
</>
195215
) : (
196216
<>
197-
{product && (
198-
<p className="p-2 text-xl text-basics-900">
199-
${post.accessSettings?.price}
200-
</p>
201-
)}
202-
<div className="flex items-center justify-center space-x-4 flex-nowrap">
203-
{product && (
204-
<CourseBuy
205-
product={product}
206-
setShowMustSignin={setShowMustSignin}
207-
/>
208-
)}
209-
{post.accessSettings?.accessMode !== AccessMode.open ? (
210-
<Link href="/membership">
217+
{post.sections &&
218+
post.sections[0] &&
219+
post.sections[0].lessons &&
220+
post.sections[0].lessons[0] && (
221+
<Link
222+
href={`/course/${post.slug}/lesson/${post.sections[0].lessons[0].slug}`}
223+
>
211224
<a>
212225
<button className="btn-primary">
213-
Become a Member
226+
Start Course
214227
</button>
215228
</a>
216229
</Link>
217-
) : (
218-
<p className="text-2xl">No Membership Needed ❤️</p>
219230
)}
220-
</div>
221231
</>
222232
)}
223233
</div>
@@ -235,7 +245,7 @@ export default function Post({
235245
post.sections.map((section, i) => {
236246
return (
237247
<section
238-
key={i}
248+
key={`section-${i}`}
239249
className="grid grid-cols-1 gap-4 p-2 bg-basics-50"
240250
>
241251
<h3 className="font-sans text-lg border-b-2 text-secondary-600 dark:text-secondary-600 border-primary-900 dark:border-primary-900">
@@ -244,7 +254,7 @@ export default function Post({
244254
<ol className="grid grid-cols-1 gap-4">
245255
{section.lessons?.map((lesson, i) => {
246256
return (
247-
<li key={i}>
257+
<li key={`lesson-${i}`}>
248258
<Link
249259
href={`/course/${post.slug}/lesson/${lesson.slug}`}
250260
key={lesson.id}

0 commit comments

Comments
 (0)