Current scrore
diff --git a/packages/experiments/src/components/up-down/UpDownVoteOutcome.svelte b/packages/experiments/src/components/up-down/UpDownVoteOutcome.svelte
index fa089ea13..fe806cdf6 100644
--- a/packages/experiments/src/components/up-down/UpDownVoteOutcome.svelte
+++ b/packages/experiments/src/components/up-down/UpDownVoteOutcome.svelte
@@ -1,29 +1,28 @@
{
- console.log('player mount', index)
-
if (playFormat === 'mp4' || ios) {
//Force mp4 playback on iOS
videoEl.src = `${getMp4Url(uid)}${ios ? '#t=0.1' : ''}`
diff --git a/packages/experiments/src/lib/db/index.ts b/packages/experiments/src/lib/db/index.ts
index f7f81ab9d..cfda12f36 100644
--- a/packages/experiments/src/lib/db/index.ts
+++ b/packages/experiments/src/lib/db/index.ts
@@ -13,7 +13,14 @@ const firebaseConfig = {
// Initialize Firebase
export let app: FirebaseApp
-export let db: Firestore
+let db: Firestore
+
+export function getDb() {
+ if (!db) {
+ initDb()
+ }
+ return db
+}
export function initDb() {
try {
diff --git a/packages/experiments/src/lib/helpers/feed.ts b/packages/experiments/src/lib/helpers/feed.ts
index f45dc9237..989cd2c72 100644
--- a/packages/experiments/src/lib/helpers/feed.ts
+++ b/packages/experiments/src/lib/helpers/feed.ts
@@ -4,19 +4,16 @@ import {
getDocs,
limit,
QueryDocumentSnapshot,
- startAt,
} from 'firebase/firestore/lite'
import type { CollectionName, UpDownPost } from './db.type'
-import { db } from '$lib/db'
+import { getDb } from '$lib/db'
export async function getVideos(lastRef?: QueryDocumentSnapshot) {
try {
+ console.log({ lastRef })
const videos: UpDownPost[] = []
- const q = query(
- collection(db, 'ud-videos' as CollectionName),
- limit(30),
- startAt(lastRef),
- )
+ const db = getDb()
+ const q = query(collection(db, 'ud-videos' as CollectionName), limit(30))
const snapshot = await getDocs(q)
if (snapshot.empty) {
return { ok: true, videos, more: false }
@@ -29,6 +26,7 @@ export async function getVideos(lastRef?: QueryDocumentSnapshot) {
more: true,
}
} catch (e) {
+ console.log('Error fetching videos', e)
return { ok: false }
}
}
diff --git a/packages/experiments/src/lib/utils/timeLeft.ts b/packages/experiments/src/lib/utils/timeLeft.ts
new file mode 100644
index 000000000..9beb43227
--- /dev/null
+++ b/packages/experiments/src/lib/utils/timeLeft.ts
@@ -0,0 +1,51 @@
+import { readable } from 'svelte/store'
+
+// const ONE_HOUR_MS = 36_00_000
+const SECONDS_MS = 1000
+const MINUTES_MS = SECONDS_MS * 60
+const HOURS_MS = MINUTES_MS * 60
+const DAYS_MS = HOURS_MS * 24
+
+type TimeParts = {
+ minutes: number
+ seconds: number
+ days: number
+ hours: number
+}
+
+export function getTimeLeft(startTime: Date, endTime: Date) {
+ let diff = endTime.getTime() - startTime.getTime()
+ if (diff > 0) {
+ return readable(getTimeStringFromMs(diff), (set) => {
+ const updateMs = () => {
+ diff -= 1000
+ if (diff > 0) {
+ set(getTimeStringFromMs(diff))
+ } else {
+ clearInterval(interval)
+ }
+ }
+
+ const interval = setInterval(updateMs, 1000)
+
+ return () => {
+ clearInterval(interval)
+ }
+ })
+ } else {
+ return readable({ minutes: 0, seconds: 0, days: 0, hours: 0 })
+ }
+}
+
+export function getTimeStringFromMs(timeMs: number) {
+ const days = Math.floor(timeMs / DAYS_MS)
+ const hours = Math.round((timeMs % DAYS_MS) / HOURS_MS)
+ const minutes = Math.floor((timeMs % HOURS_MS) / MINUTES_MS)
+ const seconds = Math.floor((timeMs % MINUTES_MS) / 1000)
+ return {
+ minutes,
+ seconds,
+ days,
+ hours,
+ }
+}
diff --git a/packages/experiments/src/routes/(feed)/(splash)/up-down/+page.ts b/packages/experiments/src/routes/(feed)/(splash)/up-down/+page.ts
index 49208ea22..a70ec1182 100644
--- a/packages/experiments/src/routes/(feed)/(splash)/up-down/+page.ts
+++ b/packages/experiments/src/routes/(feed)/(splash)/up-down/+page.ts
@@ -1,6 +1,6 @@
export const ssr = false
-import { db } from '$lib/db'
+import { getDb } from '$lib/db'
import { collection, getDocs, limit, query } from 'firebase/firestore/lite'
import type { PageLoad } from './$types'
import { redirect } from '@sveltejs/kit'
@@ -14,7 +14,7 @@ export const load: PageLoad = async () => {
// `/up-down/${cachedVideos[0].publisher_canister_id}@${cachedVideos[0].post_id}`,
// )
// }
-
+ const db = getDb()
const q = query(collection(db, 'ud-videos' as CollectionName), limit(1))
const res = await getDocs(q)
if (res.empty) {
diff --git a/packages/experiments/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.svelte b/packages/experiments/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.svelte
index aeaaeadb9..f2f10defb 100644
--- a/packages/experiments/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.svelte
+++ b/packages/experiments/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.svelte
@@ -31,18 +31,20 @@ let errorCount = 0
let showError = false
async function fetchNextVideos() {
+ console.log('called fetchNextVideos')
if (noMoreVideos) {
- console.info('No more videos to load')
+ console.log('No more videos to load')
return
}
if (videos.length - currentVideoIndex > fetchWhenVideosLeft) {
- console.info('Waiting to scroll down more')
+ console.log('Waiting to scroll down more')
return
}
loading = true
const res = await getVideos()
+ console.log({ res })
if (!res.ok || !res.videos) {
return
}
@@ -115,7 +117,7 @@ beforeNavigate(() => {
uid={post.video_uid} />
-
+
{/if}
@@ -154,7 +156,7 @@ beforeNavigate(() => {
There are no more videos to vote on
-
+
diff --git a/packages/experiments/src/routes/(feed)/(splash)/up-down/results/+page.svelte b/packages/experiments/src/routes/(feed)/(splash)/up-down/results/+page.svelte
index 9aff2cf4e..cc072aab9 100644
--- a/packages/experiments/src/routes/(feed)/(splash)/up-down/results/+page.svelte
+++ b/packages/experiments/src/routes/(feed)/(splash)/up-down/results/+page.svelte
@@ -3,6 +3,7 @@ import Avatar from '$components/avatar/Avatar.svelte'
import Icon from '$components/icon/Icon.svelte'
import getDefaultImageUrl from '$lib/utils/getDefaultImageUrl'
import { pluralize } from '$lib/utils/pluralize'
+import { authState } from '$stores/auth'
import { fade } from 'svelte/transition'
let img =
@@ -13,36 +14,40 @@ let username = 'Avid'