Skip to content

Commit

Permalink
feat: added and cleaned code of mod page, fixed auth problems
Browse files Browse the repository at this point in the history
Co-authored-by: fero <[email protected]>
  • Loading branch information
Wamy-Dev and ferothefox committed Aug 11, 2023
1 parent 0063c30 commit 197c2c0
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 19 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"type": "module",
"dependencies": {
"sugar": "^2.0.6",
"tailwind-preset-base": "workspace:^",
"ui": "workspace:^"
}
Expand Down
14 changes: 5 additions & 9 deletions apps/web/src/lib/components/layout/NavBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@
Discover Mods
</Link>
{#if $isAuthenticated}
<Link variant="text" href="/dashboard">
<Button variant="secondary" disabled={false}>
{user.username}
<img slot="trailing" alt="user icon" src={user.avatar} draggable="false" class="w-10 h-10 rounded-full">
</Button>
<Link variant="secondary" href="/dashboard">
{user.username}
<img slot="trailing" alt="user icon" src={user.avatar} draggable="false" class="w-10 h-10 rounded-full">
</Link>
{:else}
<Link variant="text" href="https://discord.gg/HTVrjFENaZ" external>
Discord
</Link>
<Link variant="text" href={env.PUBLIC_GITHUB_CALL_URL}>
<Button variant="secondary" disabled={false}>
Login
</Button>
<Link variant="secondary" href={env.PUBLIC_GITHUB_CALL_URL}>
Login
</Link>
{/if}
</div>
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/lib/stores/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { writable } from "svelte/store";

export const copiedState = writable(false);
5 changes: 3 additions & 2 deletions apps/web/src/routes/callback/github/+page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { env } from '$env/dynamic/public';
import type { PageLoad } from './$types';

export async function load({ url: { searchParams } }) {
export const load = (async ({ url: { searchParams }, fetch }) => {
const code = searchParams.get('code');
if (!code) {
return {
Expand Down Expand Up @@ -35,4 +36,4 @@ export async function load({ url: { searchParams } }) {
};
}
}
}
}) satisfies PageLoad;
120 changes: 120 additions & 0 deletions apps/web/src/routes/mod/[mod]/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<script lang="ts">
import { Pill } from 'ui/pill';
// @ts-nocheck
import type { PageData } from './$types';
import { copiedState } from '$lib/stores/mod';
export let data: PageData;
export let modData = data.body.data;
import Sugar from 'sugar';
import { fade } from 'svelte/transition';
import { CalendarIcon, PersonIcon, DownloadIcon, CopyIcon, GithubIcon, CheckmarkIcon, VerifiedIcon, CategoryIcon, NotVerifiedIcon } from 'ui/icons';
import Button from 'ui/button/Button.svelte';
console.log(modData);
const handleCopy = () => {
navigator.clipboard.writeText(modData.id)
copiedState.set(true)
setTimeout(() => {
copiedState.set(false)
}, 2500)
}
</script>

<div class="h-screen w-screen">
<div class="flex justify-center">
<div class="flex flex-col gap-2 w-full max-w-7xl px-4">
<div
class={`max-w-3xl min-w-full h-56 cover flex justify-center p-3 rounded-t-md ${
modData.cover ? `bg-[url(${modData.cover})]` : 'bg-[url("/images/glowheader.svg")]'
} bg-center`}
/>
<div class="flex p-4 bg-primary-850 h-20 justify-between -mt-4">
<div class="sm:ml-12 -mt-20">
<img
src={modData.icon ? modData.icon : '/icons/default.png'}
alt="icon"
class="w-32 border-primary-850 border-4 rounded-md"
/>
</div>
<div>
<Button variant="gradient">
Download in Client
<p slot="trailing" class="rounded-3xl ml-2 px-2 py-1 bg-[#ffffff44]">v0</p>
</Button>
</div>
</div>
<div class="flex -mt-4 p-4 pb-8 bg-primary-850 rounded-b-md">
<div class="sm:ml-12 overflow-hidden">
<div class="flex">
<h1 class="text-white-100 text-3xl font-bold mt-3">{modData.name}</h1>
</div>
<div class="flex mt-5 gap-4 overflow-x-auto flex-wrap">
<a href={`/profile/${modData.author.id}`} class="whitespace-nowrap">
<Pill label={`by ${modData.author.username}`}>
<PersonIcon className="w-5 h-5" />
</Pill>
</a>
<Pill label={`${Sugar.Number.abbr(modData.stats.downloads)} Downloads`}>
<DownloadIcon className="w-5 h-5" />
</Pill>
<Pill label={`Updated ${Sugar.Date.relative(new Date(modData.updatedAt))}`}>
<CalendarIcon className="w-5 h-5" />
</Pill>
</div>
</div>
</div>
<div class="flex flex-col md:flex-row gap-2">
<div class="sm:p-8 bg-primary-850 rounded-md sm:pl-16 px-3 py-4 w-full">
<h2 class="text-white-100 text-lg font-bold">About</h2>
<p class="text-white-100 text-sm font-semibold py-3 opacity-70 max-w-[68ch]">
{modData.description}
</p>
</div>
<div class="sm:p-8 bg-primary-850 rounded-md sm:pl-16 px-3 py-4 w-full md:w-2/5">
<h2 class="text-white-100 text-lg font-bold">Details</h2>
<div class="flex flex-col gap-2 py-3">
<a href={modData.github} target="_blank">
<Pill label="View GitHub">
<GithubIcon className="w-5 h-5 fill-primary-50" />
</Pill>
</a>
<Button variant="pill" customClasses={`copy-button grid cursor-pointer`} on:click={handleCopy}>
{#if $copiedState}
<div class:copy-button-active={$copiedState} class="flex items-center gap-2" transition:fade={{ duration: 75 }}>
<CheckmarkIcon className="w-5 h-5" />
Copied!
</div>

{:else}
<div class:copy-button-active={$copiedState} class="flex items-center gap-2" transition:fade={{ duration: 75 }}>
<CopyIcon className="w-5 h-5" />
Copy ID
</div>
{/if}
</Button>
<Pill label={`Created ${Sugar.Date.relative(new Date(modData.createdAt))}`}>
<CalendarIcon className="w-5 h-5" />
</Pill>
<Pill label={modData.category.name} customClasses="capitalize" >
<CategoryIcon className="w-5 h-5" />
</Pill>
</div>
</div>
</div>
<div class="sm:p-8 bg-primary-850 rounded-md sm:pl-16 px-3 py-4 w-full">
<h2 class="text-white-100 text-lg font-bold">Versions</h2>
</div>
</div>
</div>
</div>

<style lang="postcss">
:global(html) {
background-color: theme('colors.zinc.900');
}
</style>
67 changes: 67 additions & 0 deletions apps/web/src/routes/mod/[mod]/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type { PageLoad } from './$types';
import { env } from '$env/dynamic/public';

export const load = (async ({ params }) => {
const slug = params.mod;
try {
const response = await fetch(`${env.PUBLIC_API_URL}/graphql`, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
query: `
query ($slug: String!) {
modBySlug(slug: $slug) {
id
name
description
icon
cover
author {
username
avatar
id
}
category {
name
}
stats {
downloads
}
versions {
version
approved
downloadUrl
supportedGameVersions
stats {
downloads
}
createdAt
}
updatedAt
createdAt
}
}
`,
variables: {
slug: slug
}
})
});
let data = await response.json()
return {
status: 200,
body: {
data: data.data.modBySlug
}
};
} catch (error) {
return {
status: 500,
body: {
error: error.message
}
};
}
}) satisfies PageLoad;
9 changes: 9 additions & 0 deletions apps/web/src/routes/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,12 @@
position: absolute;
z-index: 2;
}

.copy-button > * {
grid-area: 1/1/2/2;
}

.copy-button:has(.copy-button-active) {
background: #123017;
color: #4FD264;
}
Binary file added apps/web/static/icons/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/tailwind-preset-base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
600: '#585761',
700: '#3C3D44',
800: '#222326',
850: '#19181b',
900: '#070808',
950: '#000000',
},
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/button/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
// Variants: primary, secondary, download, ghost
export let variant;
// Disabled: boolean
export let disabled;
export let disabled = false;
export let customClasses = '';
const variantClasses = {
primary: 'px-4 py-2 bg-primary-50 hover:bg-primary-100 text-black-950',
secondary: 'px-4 py-2 bg-primary-800 hover:bg-primary-900 text-white',
gradient:
'px-4 py-2 hover:-translate-y-[2px] bg-gradient-to-r from-[#47334f] to-[#2d2c4f] text-white duration-[200ms] ease-[cubic-bezier(0.22,0.61,0.36,1)]',
'will-change-transform px-4 py-2 hover:-translate-y-[2px] bg-gradient-to-r from-[#47334f] to-[#2d2c4f] text-white duration-[200ms] ease-[cubic-bezier(0.22,0.61,0.36,1)]',
ghost: 'bg-transparent fill-white text-white',
pill: 'text-xs bg-primary-700 w-fit px-2 p-1 text-fore-base whitespace-nowrap',
};
let buttonClasses = `outline-none focus:shadow-none focus-visible:ring-4 focus-visible:ring-[#00a8fc] disabled:opacity-50 flex flex-row items-center justify-center transition-all duration-[80ms] rounded-full gap-2 font-bold text-sm ${variantClasses[variant]} ${customClasses}`;
</script>

<button {disabled} class={buttonClasses}>
<button {disabled} class={buttonClasses} on:click>
{#if $$slots.leading}
<slot name="leading" />
{/if}
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/pill/Pill.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Text from '../text/Text.svelte';
export let label;
export let customClasses = '';
</script>

<div
Expand All @@ -13,5 +14,5 @@
{/if}

<slot />
<Text variant="body" customClasses="text-xs font-bold text-fore-base">{label}</Text>
<Text variant="ghost" customClasses={`text-xs font-bold text-fore-base ${customClasses ?? ''}`}>{label}</Text>
</div>
1 change: 1 addition & 0 deletions packages/ui/text/Text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export let customClasses = '';
const variantClasses = {
ghost: '',
headline: 'text-[max(32px,min(5vw,56px))] font-black',
h1: 'text-5xl font-black',
h2: 'text-4xl font-black',
Expand Down
23 changes: 19 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 197c2c0

Please sign in to comment.