Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions apps/web/src/routes/devcard/[id]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<script lang="ts">
import { onDestroy } from 'svelte';
import { PLATFORMS } from '@devcard/shared';

let { data } = $props();
const card = $derived(data.card);

let toastMessage = $state('');
let toastTimer: ReturnType<typeof setTimeout> | null = null;

function getPlatformColor(platform: string) {
const colors: Record<string, string> = {
github: '#181717',
Expand All @@ -10,14 +16,33 @@
instagram: '#E4405F',
youtube: '#FF0000',
devto: '#0A0A0A',
hashnode: '#2962FF'
hashnode: '#2962FF',
discord: '#5865F2',
};
return colors[platform.toLowerCase()] || '#6366F1';
}

function handlePlatformClick(link: any) {
window.open(link.url, '_blank');
function showToast(message: string) {
toastMessage = message;
if (toastTimer) clearTimeout(toastTimer);
toastTimer = setTimeout(() => { toastMessage = ''; }, 3000);
}
Comment on lines 8 to +29

async function handlePlatformClick(link: any) {
const platform = PLATFORMS[link.platform];
if (platform?.followStrategy === 'copy') {
try {
await navigator.clipboard.writeText(link.username);
showToast('Copied to clipboard!');
} catch {
showToast('Failed to copy. Please copy manually.');
}
} else {
window.open(link.url, '_blank', 'noopener,noreferrer');
}
}

onDestroy(() => { if (toastTimer) clearTimeout(toastTimer); });
</script>

<svelte:head>
Expand Down Expand Up @@ -101,6 +126,10 @@
</div>
</div>

{#if toastMessage}
<div class="toast" role="status" aria-live="polite" aria-atomic="true">{toastMessage}</div>
{/if}

<style>
:global(body) {
margin: 0;
Expand Down Expand Up @@ -334,4 +363,23 @@
text-decoration: none;
font-weight: 600;
}

.toast {
position: fixed;
bottom: 1.5rem;
left: 50%;
transform: translateX(-50%);
background: #1e293b;
color: #f8fafc;
border: 1px solid #334155;
border-radius: 8px;
padding: 0.625rem 1.25rem;
font-size: 0.875rem;
font-weight: 500;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
z-index: 1000;
pointer-events: none;
}


</style>
103 changes: 88 additions & 15 deletions apps/web/src/routes/u/[username]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { onDestroy } from 'svelte';
import { PLATFORMS, getProfileUrl } from '@devcard/shared';

let { data } = $props();
Expand All @@ -12,6 +13,26 @@
leetcode: '#FFA116', hackerrank: '#00EA64', discord: '#5865F2',
telegram: '#26A5E4', email: '#EA4335', portfolio: '#6366F1', custom: '#8B5CF6',
};

let toastMessage = $state('');
let toastTimer: ReturnType<typeof setTimeout> | null = null;

function showToast(message: string) {
toastMessage = message;
if (toastTimer) clearTimeout(toastTimer);
toastTimer = setTimeout(() => { toastMessage = ''; }, 3000);
}
Comment on lines +17 to +24

async function handleCopy(text: string) {
try {
await navigator.clipboard.writeText(text);
showToast('Copied to clipboard!');
} catch {
showToast('Failed to copy. Please copy manually.');
}
}

onDestroy(() => { if (toastTimer) clearTimeout(toastTimer); });
</script>

<svelte:head>
Expand Down Expand Up @@ -66,21 +87,39 @@
{#each profile.links as link}
{@const platform = PLATFORMS[link.platform]}
{@const color = platformColors[link.platform] || '#6366f1'}
<a
href={link.url || getProfileUrl(link.platform, link.username)}
target="_blank"
rel="noopener noreferrer"
class="platform-tile"
>
<div class="tile-icon" style="background: {color}">
{platform?.name.charAt(0) || '?'}
</div>
<div class="tile-info">
<span class="tile-name">{platform?.name || link.platform}</span>
<span class="tile-username">{link.username}</span>
</div>
<span class="tile-arrow">→</span>
</a>
{@const isCopy = platform?.followStrategy === 'copy'}
{#if isCopy}
<button
class="platform-tile"
onclick={() => handleCopy(link.username)}
aria-label="Copy {platform?.name || link.platform} username to clipboard"
>
<div class="tile-icon" style="background: {color}">
{platform?.name.charAt(0) || '?'}
</div>
<div class="tile-info">
<span class="tile-name">{platform?.name || link.platform}</span>
<span class="tile-username">{link.username}</span>
</div>
<span class="tile-arrow">⎘</span>
</button>
{:else}
<a
href={link.url || getProfileUrl(link.platform, link.username)}
target="_blank"
rel="noopener noreferrer"
class="platform-tile"
>
<div class="tile-icon" style="background: {color}">
{platform?.name.charAt(0) || '?'}
</div>
<div class="tile-info">
<span class="tile-name">{platform?.name || link.platform}</span>
<span class="tile-username">{link.username}</span>
</div>
<span class="tile-arrow">→</span>
</a>
{/if}
{/each}
</div>
</div>
Expand All @@ -95,6 +134,10 @@
Powered by <a href="/">DevCard</a> — Open Source Developer Profiles
</footer>
</main>

{#if toastMessage}
<div class="toast" role="status" aria-live="polite" aria-atomic="true">{toastMessage}</div>
{/if}
{/if}

<style>
Expand Down Expand Up @@ -302,4 +345,34 @@
.profile-page { padding: 1rem 0.75rem; }
.display-name { font-size: 1.5rem; }
}

/* Copy button — matches anchor tile styles */
button.platform-tile {
background: var(--bg-elevated);
border: 1px solid var(--border);
cursor: pointer;
font: inherit;
text-align: left;
width: 100%;
}
Comment on lines +349 to +357

/* Toast notification */
.toast {
position: fixed;
bottom: 1.5rem;
left: 50%;
transform: translateX(-50%);
background: #1e293b;
color: #f8fafc;
border: 1px solid #334155;
border-radius: 8px;
padding: 0.625rem 1.25rem;
font-size: 0.875rem;
font-weight: 500;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
z-index: 1000;
pointer-events: none;
}


</style>