Skip to content

Commit

Permalink
feat: upcoming refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cupcakearmy committed Feb 11, 2023
1 parent 54275df commit 765e801
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 78 deletions.
84 changes: 84 additions & 0 deletions src/lib/components/EventPreview.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<script lang="ts">
import { _ } from 'svelte-i18n'
import Icon from '$lib/components/Icon.svelte'
import { formatDate, type GetLocalisationKeysReturn } from '$lib/locale'
import type { Events, EventsTranslations } from '$lib/sdk/types'
import type { DefaultItem } from '@directus/sdk'
export let event: DefaultItem<Events>
export let keys: GetLocalisationKeysReturn<EventsTranslations>
</script>

<a href={`/events/${event.slug}`}>
<div class="wrapper py-8 flex justify-center items-end">
<div class="details mono">
<div><Icon inline name="date" /> {$formatDate(event.date)}</div>
<div><Icon inline name="location" /> {event.location}</div>
<div><Icon inline name="type" /> {$_(`events.types.${event.type}`)}</div>
</div>
<div class="text">
<h2>{$_(keys.title)}</h2>
</div>
<div class="icon flex">
<Icon name="arrow_right" />
</div>
</div>
</a>

<style>
.wrapper {
box-shadow: 0 var(--line-size) 0 0 currentColor;
transition: var(--transition);
}
a:hover .wrapper {
box-shadow: 0 calc(var(--line-size) * 2) 0 0 currentColor;
transform: translateY(-0.5rem);
}
.details {
width: 16rem;
}
.icon {
font-size: 2rem;
width: 2rem;
}
.text {
padding: 0 1rem;
flex: 1;
}
@media (max-width: 70rem) {
.wrapper {
padding-left: 2rem;
padding-right: 2rem;
}
}
@media (max-width: 50rem) {
.wrapper {
flex-direction: column;
align-items: flex-start;
}
.wrapper > div {
margin: 0;
text-align: left;
}
h2 {
margin-left: -0.075em;
margin-top: 0.75rem;
font-size: max(10vw, 2.5rem) !important;
}
.icon {
display: none;
}
.text {
padding: 0;
}
}
h2 {
font-variation-settings: 'wght' 300;
font-size: min(8vw, 6rem);
}
</style>
47 changes: 47 additions & 0 deletions src/lib/components/EventUpcoming.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script lang="ts">
import { _ } from 'svelte-i18n'
import Icon from '$lib/components/Icon.svelte'
import { formatDate, type GetLocalisationKeysReturn } from '$lib/locale'
import type { Events, EventsTranslations } from '$lib/sdk/types'
import type { DefaultItem } from '@directus/sdk'
export let event: DefaultItem<Events>
export let keys: GetLocalisationKeysReturn<EventsTranslations>
</script>

<a href={`/events/${event.slug}`}>
<div class="wrapper flex flex-col justify-center items-center p-4">
<div class="mono mb-6">
<div><Icon inline name="date" /> {$formatDate(event.date)}</div>
<div><Icon inline name="location" /> {event.location}</div>
<div><Icon inline name="type" /> {$_(`events.types.${event.type}`)}</div>
</div>
<h2 class="text-center">{$_(keys.title)}</h2>
</div>
</a>

<style>
.wrapper {
transition: var(--transition);
border: var(--line-size) solid currentColor;
}
a:hover .wrapper {
transform: translateY(-0.5rem);
border-width: calc(var(--line-size) * 2);
/* box-shadow: 0 calc(var(--line-size) * 2) 0 0 currentColor; */
}
@media (max-width: 50rem) {
h2 {
margin-left: -0.075em;
margin-top: 0.75rem;
font-size: max(10vw, 2.5rem) !important;
}
}
h2 {
font-variation-settings: 'wght' 300;
font-size: min(8vw, 6rem);
padding-bottom: 0.2em;
}
</style>
4 changes: 2 additions & 2 deletions src/lib/components/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
</div>

<!-- Socials -->
<div class="flex ml-4">
<div class="flex gap-2">
{#each socials as { href, icon }}
<a class="text-xl ml-2" {href} target="_blank" rel="noopener noreferrer">
<a class="text-xl" {href} target="_blank" rel="noopener noreferrer">
<Icon name={icon} />
</a>
{/each}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ addMessages('de', de)
export const formatDate = derived(date, (date) => (d: string) => date(DJS(d).toDate(), { dateStyle: 'medium' }))
export const formatTime = (time: string) => time.slice(0, 5)

type GetLocalisationKeysReturn<T extends LocalizedItem> = Record<keyof Omit<T, 'languages_id'>, string>
export type GetLocalisationKeysReturn<T extends LocalizedItem> = Record<keyof Omit<T, 'languages_id'>, string>

/**
* Takes a localised field and registers all the content into the i18n library so the content can be used as regular localization keys.
Expand Down
9 changes: 8 additions & 1 deletion src/routes/(web)/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<script lang="ts">
import EventUpcoming from '$lib/components/EventUpcoming.svelte'
import Intro from '$lib/components/Intro.svelte'
import Nms from '$lib/components/NMS.svelte'
import Transition from '$lib/components/Transition.svelte'
import type { PageData } from './$types'
export let data: PageData
</script>

<Transition>
<div class="wrapper flex justify-center items-center w-full h-full">
<div class="wrapper flex flex-col gap-12 justify-center items-center w-full h-full">
<div class="text-center">
<h2 class="m-0 mb-2"><Nms /></h2>
<Intro />
</div>
{#if data.upcoming}
<EventUpcoming {...data.upcoming} />
{/if}
</div>
</Transition>

Expand Down
29 changes: 29 additions & 0 deletions src/routes/(web)/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { getLocalisationKeys } from '$lib/locale'
import { SDK } from '$lib/sdk'
import { error } from '@sveltejs/kit'
import type { PageLoad } from './[slug]/$types'

export const load: PageLoad = async () => {
const eventsResponse = await SDK.items('events').readByQuery({
limit: 1,
filter: { status: 'published', date: { _gt: new Date() } },
sort: ['date'],
// @ts-ignore
fields: '*.*',
})

if (!eventsResponse.data) throw error(500)

const event = eventsResponse.data[0]
if (!event)
return {
upcoming: null,
}

if (typeof event.translations === 'string') throw error(500)
const keys = getLocalisationKeys(event.slug, event.translations)

return {
upcoming: { event, keys },
}
}
76 changes: 2 additions & 74 deletions src/routes/(web)/events/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts">
import { _ } from 'svelte-i18n'
import type { PageData } from './$types'
import Icon from '$lib/components/Icon.svelte'
import EventPreview from '$lib/components/EventPreview.svelte'
import Page from '$lib/components/Page.svelte'
export let data: PageData
Expand All @@ -11,78 +10,7 @@
<Page title="Events">
<div class="mt-32" />
{#each data.events as { event, keys }}
<a href={`/events/${event.slug}`}>
<div class="wrapper py-8 flex justify-center items-end">
<div class="details mono">
<div><Icon inline name="date" /> {event.date}</div>
<div><Icon inline name="location" /> {event.location}</div>
<div><Icon inline name="type" /> {$_(`events.types.${event.type}`)}</div>
</div>
<div class="text">
<h2>{$_(keys.title)}</h2>
</div>
<div class="icon flex">
<Icon name="arrow_right" />
</div>
</div>
</a>
<EventPreview {event} {keys} />
{/each}
<div class="mb-64" />
</Page>

<style>
.wrapper {
box-shadow: 0 var(--line-size) 0 0 currentColor;
transition: var(--transition);
}
a:hover .wrapper {
box-shadow: 0 calc(var(--line-size) * 2) 0 0 currentColor;
transform: translateY(-0.5rem);
}
.details {
width: 16rem;
}
.icon {
font-size: 2rem;
width: 2rem;
}
.text {
padding: 0 1rem;
flex: 1;
}
@media (max-width: 70rem) {
.wrapper {
padding-left: 2rem;
padding-right: 2rem;
}
}
@media (max-width: 50rem) {
.wrapper {
flex-direction: column;
align-items: flex-start;
}
.wrapper > div {
margin: 0;
text-align: left;
}
h2 {
margin-left: -0.075em;
margin-top: 0.75rem;
font-size: max(10vw, 2.5rem) !important;
}
.icon {
display: none;
}
.text {
padding: 0;
}
}
h2 {
font-variation-settings: 'wght' 300;
font-size: min(8vw, 6rem);
}
</style>

0 comments on commit 765e801

Please sign in to comment.