Skip to content

Commit

Permalink
Add page to update view params (#2036)
Browse files Browse the repository at this point in the history
* Add dev page to update params

* Update type

* Update place vote event

* Update types

* Update config

* Update config

* Cleanup

* Fix formulas

* Add create endpoint

* Render config

* Fix name

* Check logged state

* Add type
  • Loading branch information
harsh-mn-yral authored Nov 29, 2023
1 parent 027064a commit 5a99daa
Show file tree
Hide file tree
Showing 6 changed files with 444 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export type UpDownVoteDetails = {
score: number
result?: VoteRecord['result']
}
export type VoteRecordWithId = VoteRecord & {
id: string
}
</script>
<script lang="ts">
Expand Down Expand Up @@ -106,10 +110,12 @@ async function handlePlaceVote(vote: UpDownVoteDetails) {
vote.direction,
)
voteDetails = vote
registerEvent('like_video', {
registerEvent('place_vote', {
userId: $authState.userId,
video_id: post.id,
likes: post.likes_count,
amount: vote.voteAmount,
direction: vote.direction,
anon: !!$authState.isLoggedIn,
})
} catch (e) {
Expand Down
39 changes: 38 additions & 1 deletion packages/experiments/src/lib/db/db.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type CollectionName =
| 'votes'
| 'referrals'
| 'views'
| 'view-change-parameters'

export type UpDownSubCollections =
| 'likes'
Expand Down Expand Up @@ -95,7 +96,6 @@ export type ShareRecord = {
}

export type VoteRecord = {
id: string
uid: string
videoId: string
videoOid: number
Expand Down Expand Up @@ -169,3 +169,40 @@ export type VideoRef = {
videoUoid: string
videoUid: string
}

export type ViewChangeParameters = {
liked: {
yes: number
no: number
}
disliked: {
yes: number
no: number
}
shared: {
yes: number
no: number
}
watched: {
divisor: number
multiplier: number
}
threshold: {
minPercentage: number
yes: number
no: number
}
fullyWatched: {
yes: number
no: number
}
minutePassed: number
viewsPerMinute: {
divisor: number
threshold: number
yes: number
no: number
}
created_at: number
created_by: string
}
22 changes: 22 additions & 0 deletions packages/experiments/src/lib/db/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { BACKEND_HOST } from './index'
import { getHeaders } from './db.utils'
import type { ViewChangeParameters } from './db.types'

export async function isDev() {
const d = await fetch(`${BACKEND_HOST}/feed/view-change/canChange`, {
method: 'GET',
headers: getHeaders('GET'),
})
return d.json()
}

export async function createNewConfig(config: ViewChangeParameters) {
const d = await fetch(`${BACKEND_HOST}/feed/view-change`, {
method: 'POST',
headers: getHeaders('POST'),
body: JSON.stringify({
...config,
}),
})
return d.json()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { collection, getDocs, orderBy, query, where } from 'firebase/firestore'
import { onMount, tick } from 'svelte'
import { fade } from 'svelte/transition'
import ResultCard from './ResultCard.svelte'
import type { VoteRecordWithId } from '$components/up-down/UpDownVote.svelte'
let votes: VoteRecord[] = []
let votes: VoteRecordWithId[] = []
let loading = true
async function getVotes() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script lang="ts">
import Avatar from '$components/avatar/Avatar.svelte'
import Icon from '$components/icon/Icon.svelte'
import type { VoteRecordWithId } from '$components/up-down/UpDownVote.svelte'
import type { VoteRecord } from '$lib/db/db.types'
import { getThumbnailUrl } from '$lib/utils/cloudflare'
import { getMsLeftForResult, getVoteEndTime } from '$lib/utils/countdown'
import { pluralize } from '$lib/utils/pluralize'
import userProfile from '$stores/userProfile'
export let vote: VoteRecord
export let vote: VoteRecordWithId
const timeLeft = getMsLeftForResult(new Date(vote.result_at))
</script>
Expand Down
Loading

0 comments on commit 5a99daa

Please sign in to comment.