Skip to content

Commit 24f28b1

Browse files
committed
fix embeds and weird layouting
1 parent 8fe798d commit 24f28b1

File tree

14 files changed

+111
-79
lines changed

14 files changed

+111
-79
lines changed

backend/app/profile/fetch.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/gin-gonic/gin"
99
"go.uber.org/zap"
10+
"gorm.io/gorm"
1011
)
1112

1213
type partialProfile struct {
@@ -51,6 +52,14 @@ func Fetch(c *gin.Context, d *types.Dependencies) {
5152
First(&prof).
5253
Error
5354
if err != nil {
55+
if err == gorm.ErrRecordNotFound {
56+
c.JSON(http.StatusNotFound, gin.H{
57+
"error": "User not found",
58+
"requestID": requestID,
59+
})
60+
return
61+
}
62+
5463
c.JSON(http.StatusInternalServerError, gin.H{
5564
"error": "Could not fetch profile",
5665
"requestID": requestID,

frontend/src/app.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
@@ -9,7 +9,7 @@
99
%sveltekit.head%
1010
</head>
1111
<body>
12-
<div style="display: contents">%sveltekit.body%</div>
12+
<div>%sveltekit.body%</div>
1313
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
1414
</body>
1515
<script>

frontend/src/lib/api/User.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type UserUpdate = {
2828
*/
2929
export async function GetUser(fetch: typeof window.fetch): Promise<User> {
3030
const req = await fetch(`${PUBLIC_BASE_URL}/api/users`, {
31-
credentials: 'include'
31+
credentials: typeof window !== 'undefined' ? 'include' : undefined
3232
})
3333
const body = await req.json()
3434

frontend/src/lib/components/dashboard/List.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</div>
2323
{:else}
2424
{#each $videos as video, i (video.id)}
25-
<Card {video} {isProfile} {i} />
25+
<Card {video} {isProfile} {i} animDelay={Math.min((i % 10) * 0.025, 0.5)} />
2626
{/each}
2727
{/if}
2828
</div>

frontend/src/lib/components/video/Card.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
type Props = {
1010
video: Video
1111
isProfile?: boolean
12+
animDelay: number
1213
i: number
1314
}
1415
@@ -18,7 +19,7 @@
1819
animationSpeed = parseFloat(localStorage.getItem('optAnimationSpeed') || '1')
1920
})
2021
21-
let { video, isProfile = false, i }: Props = $props()
22+
let { video, isProfile = false, i, animDelay }: Props = $props()
2223
2324
function handleOnTick(e: Event) {
2425
const input = e.target as HTMLInputElement
@@ -42,7 +43,7 @@
4243
-->
4344

4445
{#if $dashboardView === 'list'}
45-
<div class="row justify-content-center card-animate" style="animation-delay:{i * 0.025}s" onanimationend={(e) => e.currentTarget.classList.remove('card-animate')}>
46+
<div class="row justify-content-center card-animate" style="animation-delay:{animDelay}s" onanimationend={(e) => e.currentTarget.classList.remove('card-animate')}>
4647
<div class="col-xl-10">
4748
<div class="card d-flex flex-row align-items-center border-0 rounded-3 bg-body-tertiary shadow-sm mb-1">
4849
<input type="checkbox" class="form-check-input m-3" aria-label="Select video" checked={$selected.includes(video.id)} onchange={handleOnTick} />
@@ -84,7 +85,7 @@
8485
</div>
8586
</div>
8687
{:else}
87-
<div class="col-sm-6 col-12 col-lg-4 col-xl-3 mb-3 card-animate" style="animation-delay:{i * 0.02}s" onanimationend={(e) => e.currentTarget.classList.remove('card-animate')}>
88+
<div class="col-sm-6 col-12 col-lg-4 col-xl-3 mb-3 card-animate" style="animation-delay:{animDelay}s" onanimationend={(e) => e.currentTarget.classList.remove('card-animate')}>
8889
<div class="card h-100 border-0 rounded-3 bg-body-tertiary shadow-sm">
8990
<div class="thumb position-relative bg-black rounded-3 aspect-video overflow-hidden">
9091
{#if video.state == 'processing'}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { derived, writable } from "svelte/store";
2-
import { loadedVideosCount, user } from "./AppVars";
1+
import { writable } from "svelte/store"
32

43
export const shouldRefetch = writable(true)
54
export const selectedVideos = writable<Array<string>>([])
65

7-
export const dashboardView = writable<'grid' | 'list'>('grid')
6+
export const dashboardView = writable<string>('grid')
87

98
// Filtering options
10-
export const perPage = writable('20')
9+
export const perPage = writable('20')
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { PUBLIC_CDN_URL } from '$env/static/public'
2+
import { GetUser } from '$lib/api/User'
3+
import { toastStore } from '$lib/stores/ToastStore'
4+
import type { LayoutServerLoad } from './$types'
5+
6+
export const load: LayoutServerLoad = async ({ cookies, fetch }) => {
7+
if (cookies.get('logged_in') !== '1') return null
8+
9+
const data = await GetUser(fetch).catch((err) => {
10+
throw toastStore.error({
11+
title: 'Failed to fetch user data',
12+
message: err.message
13+
})
14+
})
15+
16+
if (!data) return null
17+
18+
const vids = data.videos || []
19+
20+
for (let i = 0; i < vids.length; i++) {
21+
const v = vids[i]
22+
23+
vids[i].thumbnail_url = `${PUBLIC_CDN_URL}/${v.file_key.split('.')[0]}.webp`
24+
vids[i].video_url = `${PUBLIC_CDN_URL}/${v.file_key}${v.version > 1 ? `?v=${v.version}` : ''}`
25+
}
26+
27+
data.videos = vids
28+
return data
29+
}

frontend/src/routes/+layout.svelte

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,27 @@
11
<script lang="ts">
2-
import { goto } from '$app/navigation'
3-
import { PUBLIC_CDN_URL } from '$env/static/public'
4-
import { GetUser } from '$lib/api/User'
2+
import { type User } from '$lib/api/User'
53
import ToastContainer from '$lib/components/toast/ToastContainer.svelte'
4+
import { dashboardView } from '$lib/stores/appControl'
65
import { isLoggedIn, loadedVideosCount, user } from '$lib/stores/AppVars'
7-
import { toastStore } from '$lib/stores/ToastStore'
8-
import { dashboardView, shouldRefetch } from '$lib/stores/appControl'
96
import { videos } from '$lib/stores/VideoStore'
7+
import { onMount } from 'svelte'
108
import '../app.css'
11-
import { getCookie } from '$lib/utils/cookies'
129
13-
const { children } = $props()
14-
let isLoading = $state(true)
10+
const { children, data }: { children: any; data: User | null } = $props()
1511
16-
async function loadData() {
17-
try {
18-
if (getCookie('logged_in') !== '1') return
12+
if (data) {
13+
user.set(data)
14+
videos.set(data.videos)
1915
20-
const data = await GetUser(fetch)
21-
if (data) {
22-
const vids = data.videos || []
23-
24-
for (let i = 0; i < vids.length; i++) {
25-
const v = vids[i]
26-
27-
vids[i].thumbnail_url = `${PUBLIC_CDN_URL}/${v.file_key.split('.')[0]}.webp`
28-
vids[i].video_url = `${PUBLIC_CDN_URL}/${v.file_key}${v.version > 1 ? `?v=${v.version}` : ''}`
29-
}
30-
31-
user.set(data)
32-
videos.set(vids)
33-
isLoggedIn.set(true)
34-
loadedVideosCount.set(data.videos?.length ?? 0)
35-
dashboardView.set(localStorage.getItem('view') || 'list' as any)
36-
} else {
37-
toastStore.error({
38-
title: 'Session expired',
39-
message: 'Please log in again',
40-
duration: 10000
41-
})
42-
goto('/login')
43-
}
44-
} catch (err) {
45-
console.error(err)
46-
} finally {
47-
isLoading = false
48-
}
16+
isLoggedIn.set(true)
17+
loadedVideosCount.set(data.videos?.length ?? 0)
4918
}
5019
51-
$effect(() => {
52-
if ($shouldRefetch) {
53-
loadData().finally(() => {
54-
shouldRefetch.set(false)
55-
})
56-
}
20+
onMount(() => {
21+
dashboardView.set(localStorage.getItem('view') || 'grid')
5722
})
5823
</script>
5924

60-
{#if isLoading}
61-
<div></div>
62-
{:else}
63-
{@render children?.()}
64-
{/if}
25+
{@render children?.()}
6526

6627
<ToastContainer />

frontend/src/routes/u/[username]/+layout.server.ts

Whitespace-only changes.

frontend/src/routes/u/[username]/+layout.svelte

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)