Skip to content

Commit

Permalink
style: change look and feel of the "mark visited" button
Browse files Browse the repository at this point in the history
  • Loading branch information
SchutteJan committed Jul 7, 2024
1 parent 6f517a2 commit ab8f8c0
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 7 deletions.
5 changes: 4 additions & 1 deletion frontend/src/api/bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export async function get_bars(): Promise<Response> {

export async function visitBar(id: number): Promise<Response> {
return fetch(get_api_base_url() + '/visit/bar/' + id, {
method: 'POST'
method: 'POST',
headers: {
Accept: 'application/json'
}
})
}
51 changes: 45 additions & 6 deletions frontend/src/lib/BarItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import { localDate } from '$lib/time'
import { user } from '$lib/stores'
import { visitBar } from '../api/bars'
import Checkmark from './Checkmark.svelte'
export let bar: LocationResponse
export let isLoggedIn: boolean = false
user.subscribe((value) => (isLoggedIn = value !== undefined))
const placeholder =
'https://images.jan.tf/ecmAqc89DiQEu0HlPMBcNxDFyigWMJI-xUJCNJAbklQ/fill/512/512/no/1/bG9jYWw6Ly8vYmFyLXBsYWNlaG9sZGVyLnBuZw.jpg'
function handleVisitBar(id: number) {
visitBar(id).then(() => {
function handleVisitBar() {
if (bar.visited_at) {
// TODO: Remove visit
return
}
visitBar(bar.id).then(() => {
bar.visited_at = new Date().toISOString()
})
}
Expand All @@ -22,11 +27,19 @@
<div class="bar-content">
<h3>{bar.name}</h3>
<p>{bar.description ?? 'No Description'}</p>
{#if bar.visited_at && isLoggedIn}
<p>Visited on: {localDate(bar.visited_at)}</p>
{:else if isLoggedIn}
{#if isLoggedIn}
<p>
<button on:click={() => handleVisitBar(bar.id)} class="outline">Mark Visited</button>
<button
on:click={() => handleVisitBar()}
class="visit-button outline"
class:visited={bar.visited_at}
>
{#if bar.visited_at}
<span class="checkmark"><Checkmark /></span> {localDate(bar.visited_at)}
{:else}
Mark Visited
{/if}
</button>
</p>
{/if}
</div>
Expand All @@ -51,4 +64,30 @@
object-fit: cover;
align-self: center;
}
.bar-content {
flex-grow: 1;
}
.visit-button {
border-radius: 999rem;
padding: 0.5rem 0.75rem 0.5rem 0.75rem;
float: right;
color: var(--pico-color-zinc-200);
border-color: var(--pico-color-zinc-200);
}
.visit-button.visited {
color: var(--pico-color-green-400);
border-color: var(--pico-color-green-400);
cursor: auto;
}
.checkmark {
width: 1em;
display: inline-block;
vertical-align: middle;
margin-right: 2px;
margin-bottom: 0.1em;
}
</style>
105 changes: 105 additions & 0 deletions frontend/src/lib/Checkmark.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<script lang="ts">
// https://codepen.io/elevaunt/pen/JYRBzJ
export let success: boolean = true
</script>

{#if success}
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130.2 130.2">
<circle
class="path circle success"
fill="none"
stroke-width="10"
stroke-miterlimit="10"
cx="65.1"
cy="65.1"
r="62.1"
/>
<polyline
class="path check success"
fill="none"
stroke-width="10"
stroke-linecap="round"
stroke-miterlimit="10"
points="100.2,40.2 51.5,88.8 29.8,67.5 "
/>
</svg>
{:else}
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130.2 130.2">
<circle
class="path circle error"
fill="none"
stroke-width="10"
stroke-miterlimit="10"
cx="65.1"
cy="65.1"
r="62.1"
/>
<line
class="path line error"
fill="none"
stroke-width="10"
stroke-linecap="round"
stroke-miterlimit="10"
x1="34.4"
y1="37.9"
x2="95.8"
y2="92.3"
/>
<line
class="path line error"
fill="none"
stroke-width="10"
stroke-linecap="round"
stroke-miterlimit="10"
x1="95.8"
y1="38"
x2="34.4"
y2="92.2"
/>
</svg>
{/if}

<style>
svg {
display: block;
overflow: visible;
}
.path {
stroke-dasharray: 1000;
stroke-dashoffset: 0;
}
.success {
stroke: var(--pico-color-green-400);
}
.error {
stroke: var(--pico-color-red-400);
}
.path.circle {
animation: dash 0.9s ease-in-out;
}
.path.line {
stroke-dashoffset: 1000;
animation: dash 0.9s 0.35s ease-in-out forwards;
}
.path.check {
stroke-dashoffset: -100;
animation: dash-check 0.9s 0.35s ease-in-out forwards;
}
@keyframes dash {
0% {
stroke-dashoffset: 1000;
}
100% {
stroke-dashoffset: 0;
}
}
@keyframes dash-check {
0% {
stroke-dashoffset: -100;
}
100% {
stroke-dashoffset: 900;
}
}
</style>
1 change: 1 addition & 0 deletions frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import '@picocss/pico'
import '@picocss/pico/css/pico.colors.css'
import '$lib/pico-settings.css'
import { user } from '$lib/stores'
import ThemeSwitcher from '$lib/ThemeSwitcher.svelte'
Expand Down

0 comments on commit ab8f8c0

Please sign in to comment.