Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f807f0

Browse files
Release 2023-10-28 (#496)
* redirect with 303 to not use POST (#492) Co-authored-by: Alex Patterson <[email protected]> * 3-16 podcast (#493) * 3-16 podcast * change to md * add author * add button example --------- Co-authored-by: Alex Patterson <[email protected]> * redirect with 303 to not use POST (#494) Co-authored-by: Alex Patterson <[email protected]> * Feature/bookmarks clientside (#495) * bookmarks * update firbase message * clientside checkmarks * removed prerender * add settings and bookmarks clientside * change bookmarks and complete to sub collection * add preview * fix nav on card * fix preview * ugh * bookmarks as full item * rename to procourse * fix names * add bookmared and completed full * consolidate types * fix icon * fix lesson * add dashboard bookmarks * add completed --------- Co-authored-by: Alex Patterson <[email protected]> --------- Co-authored-by: Alex Patterson <[email protected]>
1 parent 943e02d commit 3f807f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+998
-349
lines changed

apps/codingcatdev/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"firebase": "^10.4.0",
6262
"gsap": "^3.12.2",
6363
"prism-svelte": "^0.5.0",
64-
"prism-themes": "^1.9.0"
64+
"prism-themes": "^1.9.0",
65+
"sveltefire": "^0.4.2"
6566
}
6667
}

apps/codingcatdev/src/lib/client/firebase.ts

+35-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import { browser } from '$app/environment';
22

3-
import { initializeApp, getApps, FirebaseError } from 'firebase/app';
3+
import { initializeApp, getApps } from 'firebase/app';
44
import {
55
getAuth,
6-
setPersistence,
7-
browserSessionPersistence,
86
signInWithEmailAndPassword,
97
signInWithPopup,
108
type AuthProvider,
119
type Auth,
1210
createUserWithEmailAndPassword
1311
} from 'firebase/auth';
14-
import { getFirestore, collection, doc, addDoc, onSnapshot, Firestore } from 'firebase/firestore';
12+
import {
13+
getFirestore,
14+
collection,
15+
doc,
16+
addDoc,
17+
onSnapshot,
18+
Firestore,
19+
setDoc,
20+
type DocumentData,
21+
initializeFirestore
22+
} from 'firebase/firestore';
1523
import { httpsCallable, getFunctions, type Functions } from 'firebase/functions';
1624
import {
1725
getAnalytics,
@@ -32,11 +40,11 @@ export const firebaseConfig = {
3240
measurementId: env.PUBLIC_FB_MEASUREMENT_ID
3341
};
3442

35-
let app = getApps().at(0);
36-
let auth: Auth;
37-
let db: Firestore;
38-
let functions: Functions;
39-
let analytics: Analytics;
43+
export let app = getApps().at(0);
44+
export let auth: Auth;
45+
export let firestore: Firestore;
46+
export let functions: Functions;
47+
export let analytics: Analytics;
4048

4149
if (
4250
!app &&
@@ -50,15 +58,25 @@ if (
5058
firebaseConfig.measurementId
5159
) {
5260
app = initializeApp(firebaseConfig);
53-
5461
auth = getAuth(app);
62+
5563
// As httpOnly cookies are to be used, do not persist any state client side.
56-
setPersistence(auth, browserSessionPersistence);
57-
db = getFirestore(app);
64+
// setPersistence(auth, browserSessionPersistence);
65+
firestore = initializeFirestore(app, { ignoreUndefinedProperties: true });
5866
functions = getFunctions(app);
5967
analytics = getAnalytics(app);
6068
} else {
61-
console.debug('Skipping Firebase Initialization, check firebaseconfig.');
69+
if (
70+
browser &&
71+
(!firebaseConfig.apiKey ||
72+
!firebaseConfig.authDomain ||
73+
!firebaseConfig.projectId ||
74+
!firebaseConfig.storageBucket ||
75+
!firebaseConfig.messagingSenderId ||
76+
!firebaseConfig.appId ||
77+
!firebaseConfig.measurementId)
78+
)
79+
console.debug('Skipping Firebase Initialization, check firebaseconfig.');
6280
}
6381

6482
/* AUTH */
@@ -100,10 +118,13 @@ export const ccdSignInWithPopUp = async (provider: AuthProvider) => {
100118
};
101119

102120
/* DB */
121+
export const updateUser = async (docRef: string, data: DocumentData) => {
122+
return setDoc(doc(firestore, docRef), data, { merge: true });
123+
};
103124

104125
/* STRIPE */
105126
export const addSubscription = async (price: string, uid: string) => {
106-
const userDoc = doc(collection(db, 'stripe-customers'), uid);
127+
const userDoc = doc(collection(firestore, 'stripe-customers'), uid);
107128
return await addDoc(collection(userDoc, 'checkout_sessions'), {
108129
price,
109130
success_url: window.location.href,

apps/codingcatdev/src/lib/components/content/Button.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
let count = 0;
33
</script>
44

5-
<button class="btn variant-filled-primary" on:click={() => count++}>{count}</button>
5+
<button class="btn variant-filled-primary" on:click={() => count++}
6+
>{count ? count : 'Click Me'}</button
7+
>

apps/codingcatdev/src/lib/server/firebase.ts

+1-30
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getFirestore } from 'firebase-admin/firestore';
55
import { env as publicEnv } from '$env/dynamic/public';
66

77
import { env as privateEnv } from '$env/dynamic/private';
8+
import type { UserDoc } from '$lib/types';
89

910
export let app = getApps().at(0);
1011

@@ -101,33 +102,3 @@ export const getStripeProducts = async () => {
101102
}
102103
return products;
103104
};
104-
105-
export interface UserSettings {
106-
settings: {
107-
showDrafts?: boolean;
108-
};
109-
}
110-
111-
export const getUser = async (uid?: string) => {
112-
if (!uid) return undefined;
113-
114-
// Check if user is Pro and wants drafts
115-
const auth = getAuth(app);
116-
const user = await auth.getUser(uid);
117-
118-
const db = getFirestore();
119-
const doc = await db.collection('users').doc(user.uid).get();
120-
return doc.data() as UserSettings;
121-
};
122-
123-
export const updateUser = async (uid?: string, userSettings?: UserSettings) => {
124-
if (!uid) return undefined;
125-
if (!userSettings) return;
126-
127-
// Check if user is Pro and wants drafts
128-
const auth = getAuth(app);
129-
const user = await auth.getUser(uid);
130-
131-
const db = getFirestore();
132-
await db.collection('users').doc(user.uid).set(userSettings, { merge: true });
133-
};

apps/codingcatdev/src/lib/types/index.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ export enum ContentType {
7575
page = 'page',
7676
podcast = 'podcast',
7777
post = 'post',
78-
sponsor = 'sponsor',
78+
sponsor = 'sponsor'
7979
}
8080

8181
export enum PodcastType {
82-
codingcatdev = 'codingcatdev',
82+
codingcatdev = 'codingcatdev'
8383
}
8484

8585
export interface Socials {
@@ -151,3 +151,25 @@ export interface DirectoryStub {
151151
}
152152

153153
export type Stub = FileStub | DirectoryStub;
154+
export interface UserDoc {
155+
pro?: Pro;
156+
}
157+
export interface Pro {
158+
settings?: {
159+
showDrafts?: boolean;
160+
};
161+
completed?: PathDate[];
162+
bookmarked?: PathDate[];
163+
}
164+
165+
export interface PathDate {
166+
path: string;
167+
date: number;
168+
}
169+
170+
export interface Saved extends Content, Lesson {
171+
savedId: string;
172+
savedUpdated: Date;
173+
savedComplete: boolean;
174+
lesson?: Saved[];
175+
}

apps/codingcatdev/src/routes/(content-list)/ContentCards.svelte

+34-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
import Image from '$lib/components/content/Image.svelte';
33
import { ContentPublished, type Content, type Course } from '$lib/types';
44
import { ContentType } from '$lib/types';
5-
export let data: { contentType: ContentType; content: Content[] & Course[]; next?: any };
5+
import type { LayoutData } from '../$types';
6+
import ProCourseMark from '../(content-single)/course/ProCourseMark.svelte';
7+
export let data: {
8+
contentType: ContentType;
9+
content: Content[] & Course[];
10+
next?: any;
11+
user: LayoutData['user'];
12+
};
613
714
let next = data.next;
815
const contentType = data.contentType;
@@ -18,7 +25,8 @@
1825
data = {
1926
contentType,
2027
content: [...data.content, ...d.content],
21-
next
28+
next,
29+
user: data?.user
2230
};
2331
next = d.next;
2432
};
@@ -58,13 +66,30 @@
5866
<section class="grid h-full grid-cols-1 gap-2 p-4">
5967
<div class="space-y-2">
6068
{#if contentType === ContentType.course}
61-
{#if content?.lesson?.filter((l) => l.locked).length}
62-
<span class="chip variant-filled-primary py-1 px-4 rounded-full text-sm"
63-
>Pro</span
64-
>
65-
{:else}
66-
<span class="chip variant-ringed py-1 px-4 rounded-full text-sm">Free</span>
67-
{/if}
69+
<div class="flex justify-between">
70+
{#if content?.lesson?.filter((l) => l.locked).length}
71+
<span class="chip variant-filled-primary py-1 px-4 rounded-full text-sm"
72+
>Pro</span
73+
>
74+
{:else}
75+
<span class="chip variant-ringed py-1 px-4 rounded-full text-sm">Free</span>
76+
{/if}
77+
<ProCourseMark
78+
data={{
79+
course: content,
80+
user: data.user
81+
}}
82+
/>
83+
</div>
84+
{:else}
85+
<div class="flex justify-end h-6">
86+
<ProCourseMark
87+
data={{
88+
content,
89+
user: data.user
90+
}}
91+
/>
92+
</div>
6893
{/if}
6994
<h3 class="font-sans text-lg tracking-wide text-bold">
7095
{content.title}
@@ -88,9 +113,3 @@
88113
</div>
89114
</div>
90115
{/if}
91-
92-
<style>
93-
.grid-cols-fit {
94-
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
95-
}
96-
</style>

apps/codingcatdev/src/routes/(content-list)/authors/AuthorCards.svelte

-6
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,3 @@
7070
</div>
7171
</div>
7272
{/if}
73-
74-
<style>
75-
.grid-cols-fit {
76-
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
77-
}
78-
</style>

apps/codingcatdev/src/routes/(content-list)/guests/GuestCards.svelte

-6
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,3 @@
7171
</div>
7272
</div>
7373
{/if}
74-
75-
<style>
76-
.grid-cols-fit {
77-
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
78-
}
79-
</style>

apps/codingcatdev/src/routes/(content-list)/sponsors/SponsorCards.svelte

-6
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,3 @@
6363
</div>
6464
</div>
6565
{/if}
66-
67-
<style>
68-
.grid-cols-fit {
69-
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
70-
}
71-
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
type: guest
3+
cover: https://media.codingcat.dev/image/upload/v1698251838/main-codingcatdev-photo/podcast-guest/b5mz5aTv_400x400.png
4+
name: pngwn
5+
published: published
6+
slug: pngwn
7+
start: January 1, 2000
8+
socials:
9+
twitter: https://twitter.com/evilpingwin
10+
---
11+
12+
## About
13+
14+
🐧 brrrrrrr!

0 commit comments

Comments
 (0)