Skip to content

Release 2023-10-28 #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/codingcatdev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"firebase": "^10.4.0",
"gsap": "^3.12.2",
"prism-svelte": "^0.5.0",
"prism-themes": "^1.9.0"
"prism-themes": "^1.9.0",
"sveltefire": "^0.4.2"
}
}
49 changes: 35 additions & 14 deletions apps/codingcatdev/src/lib/client/firebase.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { browser } from '$app/environment';

import { initializeApp, getApps, FirebaseError } from 'firebase/app';
import { initializeApp, getApps } from 'firebase/app';
import {
getAuth,
setPersistence,
browserSessionPersistence,
signInWithEmailAndPassword,
signInWithPopup,
type AuthProvider,
type Auth,
createUserWithEmailAndPassword
} from 'firebase/auth';
import { getFirestore, collection, doc, addDoc, onSnapshot, Firestore } from 'firebase/firestore';
import {
getFirestore,
collection,
doc,
addDoc,
onSnapshot,
Firestore,
setDoc,
type DocumentData,
initializeFirestore
} from 'firebase/firestore';
import { httpsCallable, getFunctions, type Functions } from 'firebase/functions';
import {
getAnalytics,
Expand All @@ -32,11 +40,11 @@ export const firebaseConfig = {
measurementId: env.PUBLIC_FB_MEASUREMENT_ID
};

let app = getApps().at(0);
let auth: Auth;
let db: Firestore;
let functions: Functions;
let analytics: Analytics;
export let app = getApps().at(0);
export let auth: Auth;
export let firestore: Firestore;
export let functions: Functions;
export let analytics: Analytics;

if (
!app &&
Expand All @@ -50,15 +58,25 @@ if (
firebaseConfig.measurementId
) {
app = initializeApp(firebaseConfig);

auth = getAuth(app);

// As httpOnly cookies are to be used, do not persist any state client side.
setPersistence(auth, browserSessionPersistence);
db = getFirestore(app);
// setPersistence(auth, browserSessionPersistence);
firestore = initializeFirestore(app, { ignoreUndefinedProperties: true });
functions = getFunctions(app);
analytics = getAnalytics(app);
} else {
console.debug('Skipping Firebase Initialization, check firebaseconfig.');
if (
browser &&
(!firebaseConfig.apiKey ||
!firebaseConfig.authDomain ||
!firebaseConfig.projectId ||
!firebaseConfig.storageBucket ||
!firebaseConfig.messagingSenderId ||
!firebaseConfig.appId ||
!firebaseConfig.measurementId)
)
console.debug('Skipping Firebase Initialization, check firebaseconfig.');
}

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

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

/* STRIPE */
export const addSubscription = async (price: string, uid: string) => {
const userDoc = doc(collection(db, 'stripe-customers'), uid);
const userDoc = doc(collection(firestore, 'stripe-customers'), uid);
return await addDoc(collection(userDoc, 'checkout_sessions'), {
price,
success_url: window.location.href,
Expand Down
4 changes: 3 additions & 1 deletion apps/codingcatdev/src/lib/components/content/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
let count = 0;
</script>

<button class="btn variant-filled-primary" on:click={() => count++}>{count}</button>
<button class="btn variant-filled-primary" on:click={() => count++}
>{count ? count : 'Click Me'}</button
>
31 changes: 1 addition & 30 deletions apps/codingcatdev/src/lib/server/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getFirestore } from 'firebase-admin/firestore';
import { env as publicEnv } from '$env/dynamic/public';

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

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

Expand Down Expand Up @@ -101,33 +102,3 @@ export const getStripeProducts = async () => {
}
return products;
};

export interface UserSettings {
settings: {
showDrafts?: boolean;
};
}

export const getUser = async (uid?: string) => {
if (!uid) return undefined;

// Check if user is Pro and wants drafts
const auth = getAuth(app);
const user = await auth.getUser(uid);

const db = getFirestore();
const doc = await db.collection('users').doc(user.uid).get();
return doc.data() as UserSettings;
};

export const updateUser = async (uid?: string, userSettings?: UserSettings) => {
if (!uid) return undefined;
if (!userSettings) return;

// Check if user is Pro and wants drafts
const auth = getAuth(app);
const user = await auth.getUser(uid);

const db = getFirestore();
await db.collection('users').doc(user.uid).set(userSettings, { merge: true });
};
26 changes: 24 additions & 2 deletions apps/codingcatdev/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export enum ContentType {
page = 'page',
podcast = 'podcast',
post = 'post',
sponsor = 'sponsor',
sponsor = 'sponsor'
}

export enum PodcastType {
codingcatdev = 'codingcatdev',
codingcatdev = 'codingcatdev'
}

export interface Socials {
Expand Down Expand Up @@ -151,3 +151,25 @@ export interface DirectoryStub {
}

export type Stub = FileStub | DirectoryStub;
export interface UserDoc {
pro?: Pro;
}
export interface Pro {
settings?: {
showDrafts?: boolean;
};
completed?: PathDate[];
bookmarked?: PathDate[];
}

export interface PathDate {
path: string;
date: number;
}

export interface Saved extends Content, Lesson {
savedId: string;
savedUpdated: Date;
savedComplete: boolean;
lesson?: Saved[];
}
49 changes: 34 additions & 15 deletions apps/codingcatdev/src/routes/(content-list)/ContentCards.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
import Image from '$lib/components/content/Image.svelte';
import { ContentPublished, type Content, type Course } from '$lib/types';
import { ContentType } from '$lib/types';
export let data: { contentType: ContentType; content: Content[] & Course[]; next?: any };
import type { LayoutData } from '../$types';
import ProCourseMark from '../(content-single)/course/ProCourseMark.svelte';
export let data: {
contentType: ContentType;
content: Content[] & Course[];
next?: any;
user: LayoutData['user'];
};

let next = data.next;
const contentType = data.contentType;
Expand All @@ -18,7 +25,8 @@
data = {
contentType,
content: [...data.content, ...d.content],
next
next,
user: data?.user
};
next = d.next;
};
Expand Down Expand Up @@ -58,13 +66,30 @@
<section class="grid h-full grid-cols-1 gap-2 p-4">
<div class="space-y-2">
{#if contentType === ContentType.course}
{#if content?.lesson?.filter((l) => l.locked).length}
<span class="chip variant-filled-primary py-1 px-4 rounded-full text-sm"
>Pro</span
>
{:else}
<span class="chip variant-ringed py-1 px-4 rounded-full text-sm">Free</span>
{/if}
<div class="flex justify-between">
{#if content?.lesson?.filter((l) => l.locked).length}
<span class="chip variant-filled-primary py-1 px-4 rounded-full text-sm"
>Pro</span
>
{:else}
<span class="chip variant-ringed py-1 px-4 rounded-full text-sm">Free</span>
{/if}
<ProCourseMark
data={{
course: content,
user: data.user
}}
/>
</div>
{:else}
<div class="flex justify-end h-6">
<ProCourseMark
data={{
content,
user: data.user
}}
/>
</div>
{/if}
<h3 class="font-sans text-lg tracking-wide text-bold">
{content.title}
Expand All @@ -88,9 +113,3 @@
</div>
</div>
{/if}

<style>
.grid-cols-fit {
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,3 @@
</div>
</div>
{/if}

<style>
.grid-cols-fit {
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,3 @@
</div>
</div>
{/if}

<style>
.grid-cols-fit {
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,3 @@
</div>
</div>
{/if}

<style>
.grid-cols-fit {
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
type: guest
cover: https://media.codingcat.dev/image/upload/v1698251838/main-codingcatdev-photo/podcast-guest/b5mz5aTv_400x400.png
name: pngwn
published: published
slug: pngwn
start: January 1, 2000
socials:
twitter: https://twitter.com/evilpingwin
---

## About

🐧 brrrrrrr!
Loading