✨ Added user-screen
This commit is contained in:
@@ -28,6 +28,7 @@ from classquiz.routers import (
|
||||
login,
|
||||
sitemap,
|
||||
remote,
|
||||
community,
|
||||
)
|
||||
from classquiz.socket_server import sio
|
||||
from classquiz.helpers import meilisearch_init, telemetry_ping, bg_tasks
|
||||
@@ -98,5 +99,6 @@ app.include_router(
|
||||
app.include_router(editor.router, tags=["editor"], prefix="/api/v1/editor", include_in_schema=True)
|
||||
app.include_router(eximport.router, tags=["export", "import"], prefix="/api/v1/eximport", include_in_schema=True)
|
||||
app.include_router(sitemap.router, tags=["sitemap"], prefix="/api/v1/sitemap", include_in_schema=True)
|
||||
app.include_router(community.router, tags=["community"], prefix="/api/v1/community", include_in_schema=True)
|
||||
|
||||
app.mount("/", ASGIApp(sio))
|
||||
|
||||
@@ -270,3 +270,12 @@ class GameInLobby(BaseModel):
|
||||
game_pin: str
|
||||
quiz_title: str
|
||||
game_id: uuid.UUID
|
||||
|
||||
|
||||
#
|
||||
# class UserProfileLinks(ormar.Model):
|
||||
# id: int = ormar.Integer(primary_key=True, autoincrement=True)
|
||||
# user: Optional[User] = ormar.ForeignKey(User)
|
||||
# github_username: str | None = ormar.Text(nullable=True)
|
||||
# reddit_username: str | None = ormar.Text(nullable=True)
|
||||
# kahoot_user_id: str | None = ormar.Text(nullable=True)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from uuid import UUID
|
||||
|
||||
from classquiz.db.models import User, Quiz
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
#
|
||||
@router.get("/user/{user_id}", response_model_include={"username", "created_at", "id"}, response_model=User)
|
||||
async def get_user_by_user_id(user_id: UUID):
|
||||
user = await User.objects.get_or_none(id=user_id)
|
||||
# .select_related("quizs")
|
||||
# print(user)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=404, detail="user not found")
|
||||
else:
|
||||
return user
|
||||
|
||||
|
||||
@router.get("/quizzes/{user_id}", response_model_exclude={"questions", "user_id"}, response_model=list[Quiz])
|
||||
async def get_quizzes_from_user(user_id: UUID, imported: bool | None = None):
|
||||
if imported is None:
|
||||
quizzes = await Quiz.objects.all(user_id=user_id, public=True)
|
||||
else:
|
||||
quizzes = await Quiz.objects.all(user_id=user_id, public=True, imported_from_kahoot=imported)
|
||||
if len(quizzes) == 0:
|
||||
raise HTTPException(status_code=404, detail="no quizzes found")
|
||||
else:
|
||||
return quizzes
|
||||
+33
-33
@@ -15,30 +15,30 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@beyonk/svelte-mapbox": "^8.2.0",
|
||||
"@ckeditor/ckeditor5-autoformat": "^35.3.2",
|
||||
"@ckeditor/ckeditor5-basic-styles": "^35.3.2",
|
||||
"@ckeditor/ckeditor5-build-balloon": "^35.3.2",
|
||||
"@ckeditor/ckeditor5-editor-balloon": "^35.3.2",
|
||||
"@ckeditor/ckeditor5-essentials": "^35.3.2",
|
||||
"@ckeditor/ckeditor5-theme-lark": "^35.3.2",
|
||||
"@felte/reporter-tippy": "^1.1.4",
|
||||
"@felte/validator-yup": "^1.0.10",
|
||||
"@ckeditor/ckeditor5-autoformat": "^35.4.0",
|
||||
"@ckeditor/ckeditor5-basic-styles": "^35.4.0",
|
||||
"@ckeditor/ckeditor5-build-balloon": "^35.4.0",
|
||||
"@ckeditor/ckeditor5-editor-balloon": "^35.4.0",
|
||||
"@ckeditor/ckeditor5-essentials": "^35.4.0",
|
||||
"@ckeditor/ckeditor5-theme-lark": "^35.4.0",
|
||||
"@felte/reporter-tippy": "^1.1.5",
|
||||
"@felte/validator-yup": "^1.0.11",
|
||||
"@fontsource/marck-script": "^4.5.11",
|
||||
"@sentry/browser": "^7.23.0",
|
||||
"@sentry/tracing": "^7.23.0",
|
||||
"@sentry/browser": "^7.31.1",
|
||||
"@sentry/tracing": "^7.31.1",
|
||||
"@simplewebauthn/browser": "^6.2.2",
|
||||
"@sveltejs/adapter-auto": "^1.0.0",
|
||||
"@sveltejs/adapter-node": "^1.0.0-next.101",
|
||||
"@sveltejs/kit": "^1.0.1",
|
||||
"@tailwindcss/typography": "^0.5.8",
|
||||
"@sveltejs/adapter-auto": "^1.0.2",
|
||||
"@sveltejs/adapter-node": "^1.1.4",
|
||||
"@sveltejs/kit": "^1.2.2",
|
||||
"@tailwindcss/typography": "^0.5.9",
|
||||
"@types/canvas-confetti": "^1.6.0",
|
||||
"@types/cookie": "^0.5.1",
|
||||
"@types/js-cookie": "^3.0.2",
|
||||
"@types/luxon": "^2.4.0",
|
||||
"@types/qrcode": "^1.5.0",
|
||||
"@types/ua-parser-js": "^0.7.36",
|
||||
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
||||
"@typescript-eslint/parser": "^5.45.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.48.2",
|
||||
"@typescript-eslint/parser": "^5.48.2",
|
||||
"@uppy/compressor": "^1.0.1",
|
||||
"@uppy/core": "^3.0.4",
|
||||
"@uppy/dashboard": "^3.2.0",
|
||||
@@ -54,45 +54,45 @@
|
||||
"cookie": "^0.5.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"cssnano": "^5.1.14",
|
||||
"eslint": "^8.28.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint": "^8.32.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"eslint-plugin-svelte3": "^4.0.0",
|
||||
"felte": "^1.2.6",
|
||||
"felte": "^1.2.7",
|
||||
"fuse.js": "^6.6.2",
|
||||
"highlight.js": "^11.7.0",
|
||||
"i18next-browser-languagedetector": "^7.0.1",
|
||||
"js-cookie": "^3.0.1",
|
||||
"luxon": "^3.1.1",
|
||||
"mapbox-gl": "^2.11.0",
|
||||
"luxon": "^3.2.1",
|
||||
"mapbox-gl": "^2.12.0",
|
||||
"mdsvex": "^0.10.6",
|
||||
"minisearch": "^5.1.0",
|
||||
"pikaso": "^2.7.4",
|
||||
"plausible-tracker": "^0.3.8",
|
||||
"postcss": "^8.4.19",
|
||||
"postcss": "^8.4.21",
|
||||
"postcss-import": "^14.1.0",
|
||||
"postcss-load-config": "^4.0.1",
|
||||
"prettier": "^2.8.0",
|
||||
"prettier-plugin-svelte": "^2.8.1",
|
||||
"prettier": "^2.8.3",
|
||||
"prettier-plugin-svelte": "^2.9.0",
|
||||
"qrcode": "^1.5.1",
|
||||
"sass": "^1.56.1",
|
||||
"sass": "^1.57.1",
|
||||
"socket.io-client": "^4.5.4",
|
||||
"svelte": "^3.53.1",
|
||||
"svelte-check": "^2.10.0",
|
||||
"svelte-preprocess": "^5.0.0",
|
||||
"svelte-range-slider-pips": "^2.1.0",
|
||||
"svelte": "^3.55.1",
|
||||
"svelte-check": "^3.0.2",
|
||||
"svelte-preprocess": "^5.0.1",
|
||||
"svelte-range-slider-pips": "^2.1.1",
|
||||
"svelte-tippy": "^1.3.2",
|
||||
"swiper": "^8.4.5",
|
||||
"swiper": "^8.4.6",
|
||||
"tailwindcss": "^3.2.4",
|
||||
"tippy.js": "^6.3.7",
|
||||
"tslib": "^2.4.1",
|
||||
"typescript": "~4.7.4",
|
||||
"ua-parser-js": "^1.0.32",
|
||||
"vite": "^4.0.1",
|
||||
"ua-parser-js": "^1.0.33",
|
||||
"vite": "^4.0.4",
|
||||
"vite-plugin-iso-import": "^1.0.0",
|
||||
"yup": "^0.32.11"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"i18next": "^22.0.6"
|
||||
"i18next": "^22.4.9"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+558
-573
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,12 @@
|
||||
.normal-background {
|
||||
@apply bg-gradient-to-r from-[#009444] via-[#39b54a] to-[#8dc63f] dark:bg-[#0f2702] dark:from-[#0f2702] dark:via-[#0f2702] dark:to[#0f2702];
|
||||
}
|
||||
|
||||
.admin-button {
|
||||
@apply px-4 py-2 leading-5 text-white transition-colors duration-200 transform bg-gray-700 rounded text-center hover:bg-gray-600 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
@apply px-4 py-2 leading-5 text-black dark:text-white transition-colors duration-200 transform bg-gray-50 dark:bg-gray-700 rounded text-center hover:bg-gray-300 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:hover:bg-gray-600;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
<!--
|
||||
- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
import { getLocalization } from '$lib/i18n';
|
||||
import { onMount } from 'svelte';
|
||||
import { createTippy } from 'svelte-tippy';
|
||||
import { signedIn } from '$lib/stores';
|
||||
import StartGamePopup from '$lib/dashboard/start_game.svelte';
|
||||
|
||||
const { t } = getLocalization();
|
||||
// import { DateTime } from 'luxon';
|
||||
let start_game = null;
|
||||
|
||||
const tippy = createTippy({
|
||||
arrow: true,
|
||||
animation: 'perspective-subtle',
|
||||
placement: 'right'
|
||||
});
|
||||
|
||||
const close_start_game_if_esc_is_pressed = (key: KeyboardEvent) => {
|
||||
if (key.code === 'Escape') {
|
||||
start_game = null;
|
||||
}
|
||||
};
|
||||
onMount(() => {
|
||||
document.body.addEventListener('keydown', close_start_game_if_esc_is_pressed);
|
||||
});
|
||||
export let data: PageData;
|
||||
console.log(data, 'data');
|
||||
</script>
|
||||
|
||||
<div class="h-full">
|
||||
<div class="grid grid-cols-6 h-full">
|
||||
<div class="pl-2">
|
||||
<div class="flex justify-center">
|
||||
<img src={`/api/v1/users/avatar/${data.user.id}`} alt="profile" />
|
||||
</div>
|
||||
<h2 class="text-3xl text-center">
|
||||
@{data.user.username}
|
||||
</h2>
|
||||
<p class="italic text-center">
|
||||
Joined on {new Date(data.user.created_at).toLocaleDateString()}
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
class="col-start-2 col-end-7 border-l border-black h-full p-4 overflow-y-scroll flex flex-col gap-4"
|
||||
>
|
||||
{#each data.quizzes as quiz}
|
||||
<div
|
||||
class="rounded-lg border-2 border-black hover:outline transition-all outline-[#B07156] -outline-offset-2 outline-8"
|
||||
>
|
||||
<div class="grid grid-cols-6 h-[25vh]">
|
||||
<!-- <p
|
||||
style='writing-mode: vertical-lr'
|
||||
class='text-center h-full text-xl p-2'
|
||||
>
|
||||
{@html quiz.title}
|
||||
</p>-->
|
||||
<div class="col-start-2 col-end-6">
|
||||
<h3 class="text-center text-2xl">{@html quiz.title}</h3>
|
||||
<p class="text-center">
|
||||
{@html quiz.description}
|
||||
</p>
|
||||
{#if quiz.cover_image}
|
||||
<div class="flex justify-center align-middle items-center">
|
||||
<div class="h-[20vh] m-auto w-auto max-h-[18vh]">
|
||||
<img
|
||||
class="max-h-full max-w-full block"
|
||||
src={quiz.cover_image}
|
||||
alt="Not provided"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- <div class='flex justify-end'>
|
||||
<p
|
||||
style='writing-mode: sideways-lr'
|
||||
class='text-center text-xl p-2'
|
||||
>
|
||||
{@html quiz.title}
|
||||
</p>
|
||||
</div>-->
|
||||
</div>
|
||||
<div class="flex justify-center">
|
||||
<a href="/view/{quiz.id}" class="action-button w-1/6">{$t('words.view')}</a>
|
||||
</div>
|
||||
<div class="flex justify-center pb-10 pt-8">
|
||||
<div class="grid grid-cols-2 gap-3 w-1/3">
|
||||
{#if $signedIn}
|
||||
<button
|
||||
on:click={() => {
|
||||
start_game = quiz.id;
|
||||
}}
|
||||
class="action-button"
|
||||
>
|
||||
{$t('words.start')}
|
||||
</button>
|
||||
<a
|
||||
href="/api/v1/eximport/{quiz.id}"
|
||||
aria-label="Download the quiz"
|
||||
class="flex justify-center px-4 py-2 leading-5 text-black dark:text-white transition-colors duration-200 transform bg-gray-50 dark:bg-gray-700 rounded text-center hover:bg-gray-300 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:hover:bg-gray-600"
|
||||
><!-- heroicons/download -->
|
||||
<svg
|
||||
class="w-5 h-5"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
{:else}
|
||||
<div
|
||||
use:tippy={{
|
||||
content: 'You need be signed in to start a game.'
|
||||
}}
|
||||
class="w-full"
|
||||
>
|
||||
<button
|
||||
on:click={() => {
|
||||
start_game = quiz.id;
|
||||
}}
|
||||
disabled
|
||||
class="action-button w-full"
|
||||
>
|
||||
{$t('words.start')}
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
use:tippy={{
|
||||
content: 'You need be signed in to download a game.'
|
||||
}}
|
||||
class="w-full"
|
||||
>
|
||||
<button
|
||||
disabled
|
||||
class="action-button w-full flex justify-center"
|
||||
>
|
||||
<svg
|
||||
class="w-5 h-5"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if start_game !== null}
|
||||
<StartGamePopup bind:quiz_id={start_game} />
|
||||
{/if}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
export const load = (async ({ params, fetch }) => {
|
||||
const user_req = await fetch(`/api/v1/community/user/${params.user_id}`);
|
||||
const user = await user_req.json();
|
||||
if (!user) {
|
||||
return {
|
||||
user: undefined,
|
||||
quizzes: undefined
|
||||
};
|
||||
}
|
||||
const quiz_req = await fetch(`/api/v1/community/quizzes/${params.user_id}?imported=false`);
|
||||
const quizzes = await quiz_req.json();
|
||||
return {
|
||||
user,
|
||||
quizzes
|
||||
};
|
||||
}) satisfies PageLoad;
|
||||
Reference in New Issue
Block a user