Skip to content

Commit 810389a

Browse files
committed
Fix sort by date in open dialog
1 parent 05e11ee commit 810389a

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

src/lib/components/OpenCloudDialog.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
$: sortedWheels = apiWheels.sort((a, b) => {
2121
switch (sort) {
2222
case 'updated-desc':
23-
return Number(b.updated || b.created) - Number(a.updated || a.created)
23+
return (b.updated || b.created) - (a.updated || a.created)
2424
case 'updated-asc':
25-
return Number(a.updated || a.created) - Number(b.updated || b.created)
25+
return (a.updated || a.created) - (b.updated || b.created)
2626
case 'title-asc':
2727
return a.title.localeCompare(b.title)
2828
case 'title-desc':
@@ -179,7 +179,7 @@
179179
name="wheel"
180180
value={wheel.path}
181181
>
182-
<div class="min-h-12 flex flex-col justify-center">
182+
<div class="min-h-14 flex flex-col justify-center">
183183
<div class="flex gap-2 justify-center items-center">
184184
<span class="text-lg font-semibold">{wheel.title}</span>
185185
{#if wheel.visibility === 'private'}
@@ -199,6 +199,8 @@
199199
<div class="flex justify-center items-center min-h-14">
200200
No wheels found
201201
</div>
202+
{:else if filteredWheels.length > wheelsPerPage}
203+
<div style="height: {4 * (wheelsPerPage - pageWheels.length)}rem" />
202204
{/if}
203205
</RadioGroup>
204206
{:else if loading}

src/lib/server/FirebaseAdmin.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { initializeApp } from 'firebase-admin/app'
22
import { getFirestore } from 'firebase-admin/firestore'
33
import { FirebaseError } from 'firebase/app'
4-
import { firebaseConfig } from '$lib/utils/Firebase'
4+
import { firebaseConfig, type DbWheelMeta } from '$lib/utils/Firebase'
55
import type {
6-
ApiUser, ApiWheel, ApiWheelMeta, WheelVisibility
6+
ApiUser, ApiWheel, CreateWheelMeta, WheelVisibility
77
} from '$lib/utils/Api'
88

99
try {
@@ -21,7 +21,7 @@ export const getWheel = async (path: string, uid?: string | null) => {
2121
if (!metaSnap.exists) {
2222
return null
2323
}
24-
const meta = metaSnap.data() as ApiWheelMeta
24+
const meta = metaSnap.data() as DbWheelMeta
2525
if (meta.visibility === 'private' && meta.uid !== uid) {
2626
return null
2727
}
@@ -36,7 +36,7 @@ export const getWheels = async (uid: string) => {
3636
const metaSnap = await db.collection('wheel-meta').where(
3737
'uid', '==', uid
3838
).get()
39-
const paths = metaSnap.docs.map(doc => (doc.data() as ApiWheelMeta).path)
39+
const paths = metaSnap.docs.map(doc => (doc.data() as DbWheelMeta).path)
4040
const wheelSnaps = await db.getAll(
4141
...paths.map(path => db.doc(`wheels/${path}`))
4242
)
@@ -59,7 +59,13 @@ export const getWheelMetaForPaths = async (paths: string[]) => {
5959
const metaSnaps = await db.getAll(
6060
...paths.map(path => db.doc(`wheel-meta/${path}`))
6161
)
62-
return metaSnaps.map(snap => snap.data() as ApiWheelMeta)
62+
return metaSnaps.map(
63+
snap => snap.data() as DbWheelMeta
64+
).map(meta => ({
65+
...meta,
66+
created: meta.created._seconds * 1000,
67+
updated: meta.updated ? meta.updated._seconds * 1000 : null
68+
}))
6369
}
6470

6571
export const saveWheel = async (
@@ -74,7 +80,7 @@ export const saveWheel = async (
7480
updated: null,
7581
title: wheel.config.title,
7682
views: 0
77-
} satisfies ApiWheelMeta)
83+
} satisfies CreateWheelMeta)
7884
await db.collection('wheels').doc(path).create(
7985
{ path, ...wheel } satisfies ApiWheel
8086
)
@@ -97,11 +103,11 @@ export const updateWheel = async (
97103
if (!metaSnap.exists) {
98104
return null
99105
}
100-
const meta = metaSnap.data() as ApiWheelMeta
106+
const meta = metaSnap.data() as DbWheelMeta
101107
if (meta.uid !== uid) {
102108
return null
103109
}
104-
const newMeta: Partial<ApiWheelMeta> = { updated: new Date() }
110+
const newMeta: Partial<CreateWheelMeta> = { updated: new Date() }
105111
if (wheel.config && wheel.config.title !== meta.title) {
106112
newMeta.title = wheel.config.title
107113
}

src/lib/utils/Api.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,17 @@ export interface ApiWheelMeta {
111111
path: string
112112
uid: string
113113
visibility: WheelVisibility
114-
created: Date
115-
updated: Date | null
114+
created: number
115+
updated: number | null
116116
title: string
117117
views: number
118118
}
119119

120+
export interface CreateWheelMeta extends Omit<ApiWheelMeta, 'created' | 'updated'> {
121+
created: Date
122+
updated: Date | null
123+
}
124+
120125
export interface CreateWheelData {
121126
wheel: Omit<ApiWheel, 'path'>
122127
visibility: WheelVisibility

src/lib/utils/Firebase.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ import {
1313
PUBLIC_FIREBASE_MESSAGING_SENDER_ID, PUBLIC_FIREBASE_APP_ID,
1414
PUBLIC_FIREBASE_MEASUREMENT_ID
1515
} from '$env/static/public'
16+
import type { ApiWheelMeta } from '$lib/utils/Api'
17+
18+
interface DbDate {
19+
_seconds: number
20+
_nanoseconds: number
21+
}
22+
23+
export interface DbWheelMeta extends Omit<ApiWheelMeta, 'created' | 'updated'> {
24+
created: DbDate,
25+
updated: DbDate | null
26+
}
1627

1728
interface DbUser {
1829
createdAt: Date

0 commit comments

Comments
 (0)