Skip to content

Commit

Permalink
fix unsub not getting called onDestroy
Browse files Browse the repository at this point in the history
for more info onDestroy not getting called refer 'sveltejs/svelte#5268'
add alias fro stores -> $stores
format imports
  • Loading branch information
SymphonySimper committed Oct 8, 2022
1 parent 2f071fe commit 70b02a3
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 30 deletions.
7 changes: 4 additions & 3 deletions src/routes/+layout.svelte
@@ -1,13 +1,14 @@
<script lang="ts">
import './styles.css';
import { isLoggedIn, user } from '../stores/auth';
import { auth } from '../lib/firebase';
import { onAuthStateChanged } from 'firebase/auth';
import { goto } from '$app/navigation';
import { Modals, closeModal } from 'svelte-modals';
import { browser } from '$app/environment';
import Profile from './Profile.svelte';
import { auth } from '$lib/firebase';
import type { User } from '$lib/types';
import { isLoggedIn, user } from '$stores/auth';
import Profile from './Profile.svelte';
onAuthStateChanged(auth, (authUser) => {
if (!!authUser) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+page.svelte
@@ -1,5 +1,5 @@
<script lang="ts">
import { isLoggedIn } from '../stores/auth';
import { isLoggedIn } from '$stores/auth';
import CardList from './CardList.svelte';
import AddNote from './AddNote.svelte';
</script>
Expand Down
7 changes: 4 additions & 3 deletions src/routes/AddNote.svelte
@@ -1,10 +1,11 @@
<script lang="ts">
import { addDoc, collection } from 'firebase/firestore';
import { db } from '../lib/firebase';
import { user, isLoggedIn } from '../stores/auth';
import { user, isLoggedIn } from '$stores/auth';
import { db } from '$lib/firebase';
import type { Note } from '$lib/types';
import InputFields from './InputFields.svelte';
import getTime from '$lib/time';
import InputFields from './InputFields.svelte';
let note: Note = { note: '' } as Note;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Card.svelte
Expand Up @@ -5,7 +5,7 @@
import type { Note, NoteWithId } from '$lib/types';
import InputFieldsModal from './InputFieldsModal.svelte';
import { user } from '../stores/auth';
import { user } from '$stores/auth';
export let note: NoteWithId;
Expand Down
16 changes: 7 additions & 9 deletions src/routes/CardList.svelte
@@ -1,17 +1,15 @@
<script lang="ts">
import { flip } from 'svelte/animate';
import { fade } from 'svelte/transition';
import { notes } from '../stores/notes';
import Card from './Card.svelte';
import { collection, query, onSnapshot, orderBy } from 'firebase/firestore';
import { onDestroy } from 'svelte';
import type { NoteWithId, Note } from '$lib/types';
import { db } from '$lib/firebase';
import { user } from '../stores/auth';
import { onDestroy } from 'svelte';
import { user } from '$stores/auth';
import { notes } from '$stores/notes';
import Card from './Card.svelte';
const q = query(collection(db, 'users', $user.uid, 'notes'), orderBy('time'));
const unsub = onSnapshot(q, (querySnapshot) => {
export const unsub = onSnapshot(q, (querySnapshot) => {
notes.reset();
querySnapshot.forEach((doc) => {
let note: NoteWithId = {
Expand All @@ -28,7 +26,7 @@
<div>
{#if $notes.length != 0}
{#each $notes as note, id (id)}
<div transition:fade={{ duration: 400 }} animate:flip={{ duration: 400 }}>
<div>
<Card {note} />
</div>
{/each}
Expand Down
3 changes: 2 additions & 1 deletion src/routes/InputFields.svelte
@@ -1,7 +1,8 @@
<script lang="ts">
import type { Note } from '$lib/types';
import { afterUpdate } from 'svelte';
import type { Note } from '$lib/types';
export let note: Note;
export let onClose: () => void;
export let onSubmit: () => void;
Expand Down
22 changes: 12 additions & 10 deletions src/routes/Profile.svelte
@@ -1,21 +1,23 @@
<script lang="ts">
import { isLoggedIn, user } from '../stores/auth';
import { auth } from '../lib/firebase';
import { signOut } from 'firebase/auth';
import { goto } from '$app/navigation';
import { browser } from '$app/environment';
import { auth } from '$lib/firebase';
import { isLoggedIn, user } from '$stores/auth';
import { notes } from '$stores/notes';
let expand = false;
const logout = async () => {
try {
await signOut(auth);
isLoggedIn.set(false);
user.reset();
browser && goto('/signin');
} catch (err) {
console.error(err);
}
await signOut(auth)
.then(() => {
isLoggedIn.set(false);
user.reset();
notes.reset();
browser && goto('/signin');
})
.catch((err) => console.error(err));
expand = !expand;
};
</script>
Expand Down
5 changes: 3 additions & 2 deletions src/routes/signin/+page.svelte
@@ -1,9 +1,10 @@
<script lang="ts">
import { isLoggedIn, user } from '../../stores/auth';
import { auth } from '$lib/firebase';
import { signInWithPopup, GoogleAuthProvider } from 'firebase/auth';
import { goto } from '$app/navigation';
import { auth } from '$lib/firebase';
import type { User } from '$lib/types';
import { isLoggedIn, user } from '$stores/auth';
const loginWithGoogle = async () => {
const provider = new GoogleAuthProvider();
Expand Down

0 comments on commit 70b02a3

Please sign in to comment.