-
Notifications
You must be signed in to change notification settings - Fork 46
feat(profile): perfil público em /@username #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GabrielFVDev
wants to merge
14
commits into
4.x
Choose a base branch
from
feature/public-profile
base: 4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
343741c
feat(profile): implement public profile feature with routing and view…
GabrielFVDev bdc0fe6
feat(profile): enhance public profile layout and data handling
GabrielFVDev ddbb2d1
feat(profile): add about, links and resume sections to public profile
GabrielFVDev 6822d39
feat(profile): enhance public profile with gamification features and …
GabrielFVDev db6c36b
feat(profile): implement avatar initials fallback and enhance profile…
GabrielFVDev 3bd6e46
feat(profile): enhance public profile with experience details and mem…
GabrielFVDev 4818ba5
feat: Implement public profile projects feature
GabrielFVDev f634d4c
feat(profile): aplicar a variante Aurora no perfil público
GabrielFVDev 0a92cfd
Merge branch '4.x' into feature/public-profile
GabrielFVDev 5984725
feat(profile): implement public profile caching and SEO enhancements
GabrielFVDev 06eeb18
feat(profile): user photo and nickname is clicable
GabrielFVDev ae7ace0
feat(profile): implement profile card feature with dynamic loading an…
GabrielFVDev 1044c45
feat(profile): refactor user avatar handling and implement profile in…
GabrielFVDev 46a1708
feat(profile): implement public profile caching and cache invalidatio…
GabrielFVDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app-modules/identity/tests/Unit/ExternalIdentity/IdentityProviderProfileUrlTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use He4rt\Identity\ExternalIdentity\Enums\IdentityProvider; | ||
|
|
||
| it('builds a profile url for the providers that have one', function (IdentityProvider $provider, string $expected): void { | ||
| expect($provider->profileUrl('danielhe4rt'))->toBe($expected); | ||
| })->with([ | ||
| 'github' => [IdentityProvider::GitHub, 'https://github.com/danielhe4rt'], | ||
| 'twitch' => [IdentityProvider::Twitch, 'https://twitch.tv/danielhe4rt'], | ||
| ]); | ||
|
|
||
| it('returns null for discord, which has no public profile page', function (): void { | ||
| expect(IdentityProvider::Discord->profileUrl('danielhe4rt'))->toBeNull(); | ||
| }); | ||
|
|
||
| it('returns null for providers outside the supported set', function (): void { | ||
| expect(IdentityProvider::Steam->profileUrl('danielhe4rt'))->toBeNull() | ||
| ->and(IdentityProvider::Spotify->profileUrl('danielhe4rt'))->toBeNull(); | ||
| }); | ||
|
|
||
| it('strips a leading @ and surrounding spaces from the handle', function (string $handle): void { | ||
| expect(IdentityProvider::GitHub->profileUrl($handle))->toBe('https://github.com/danielhe4rt'); | ||
| })->with([ | ||
| 'plain' => ['danielhe4rt'], | ||
| 'at prefixed' => ['@danielhe4rt'], | ||
| 'padded' => [' danielhe4rt '], | ||
| 'at prefixed and padded' => [' @danielhe4rt '], | ||
| ]); | ||
|
|
||
| it('passes an already absolute url through untouched', function (): void { | ||
| expect(IdentityProvider::GitHub->profileUrl('https://github.com/danielhe4rt')) | ||
| ->toBe('https://github.com/danielhe4rt'); | ||
| }); | ||
|
|
||
| it('returns null for an empty handle', function (?string $handle): void { | ||
| expect(IdentityProvider::GitHub->profileUrl($handle))->toBeNull(); | ||
| })->with([ | ||
| 'null' => [null], | ||
| 'empty' => [''], | ||
| 'only spaces' => [' '], | ||
| ]); | ||
|
|
||
| it('gives every supported provider a decided answer', function (): void { | ||
| $decided = [ | ||
| IdentityProvider::GitHub->value => 'https://github.com/handle', | ||
| IdentityProvider::Twitch->value => 'https://twitch.tv/handle', | ||
| IdentityProvider::DevTo->value => 'https://dev.to/handle', | ||
| IdentityProvider::Discord->value => null, | ||
| ]; | ||
|
|
||
| foreach (IdentityProvider::supportedProviders() as $provider) { | ||
| expect($decided)->toHaveKey($provider->value) | ||
| ->and($provider->profileUrl('handle'))->toBe($decided[$provider->value]); | ||
| } | ||
| }); |
198 changes: 198 additions & 0 deletions
198
app-modules/panel-app/resources/views/components/profile-link.blade.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| @props (['user' => null]) | ||
|
|
||
| @use('He4rt\Profile\Support\PublicProfileCache') | ||
|
|
||
| @php | ||
| $isLinkable = $user !== null && $user->banned_at === null && filled($user->username); | ||
| @endphp | ||
|
|
||
| @if ($isLinkable) | ||
| <span | ||
| class="contents" | ||
| x-data="{ | ||
| url: @js(route('profile.card', $user->username)), | ||
| ttl: @js(PublicProfileCache::TTL_SECONDS * 1000), | ||
| open: false, | ||
| loading: false, | ||
| html: null, | ||
| hoverable: window.matchMedia('(hover: hover)').matches, | ||
| cardStyle: '', | ||
| openTimer: null, | ||
| closeTimer: null, | ||
|
|
||
| scheduleOpen() { | ||
| if (! this.hoverable) return | ||
|
|
||
| clearTimeout(this.openTimer) | ||
| clearTimeout(this.closeTimer) | ||
| this.openTimer = setTimeout(() => this.show(), 400) | ||
| }, | ||
|
|
||
| scheduleClose() { | ||
| clearTimeout(this.openTimer) | ||
| clearTimeout(this.closeTimer) | ||
| this.closeTimer = setTimeout(() => this.open = false, 300) | ||
| }, | ||
|
|
||
| cancelClose() { | ||
| clearTimeout(this.closeTimer) | ||
| }, | ||
|
|
||
| close() { | ||
| clearTimeout(this.openTimer) | ||
| clearTimeout(this.closeTimer) | ||
| this.open = false | ||
| }, | ||
|
|
||
| position() { | ||
| if (! this.open) return | ||
|
|
||
| const trigger = this.$refs.trigger.getBoundingClientRect() | ||
| const width = this.$refs.card.offsetWidth || 320 | ||
| const height = this.$refs.card.offsetHeight || 200 | ||
| const left = Math.max(8, Math.min(trigger.left, window.innerWidth - width - 8)) | ||
| const fitsBelow = trigger.bottom + 8 + height <= window.innerHeight - 8 | ||
| const fitsAbove = trigger.top - 8 - height >= 8 | ||
| const top = fitsBelow || ! fitsAbove ? trigger.bottom + 8 : trigger.top - 8 - height | ||
|
|
||
| this.cardStyle = 'left: ' + left + 'px; top: ' + Math.max(8, top) + 'px' | ||
| }, | ||
|
|
||
| reposition() { | ||
| this.$nextTick(() => this.position()) | ||
| }, | ||
|
|
||
| cards() { | ||
| window.__profileCards ??= new Map() | ||
|
|
||
| return window.__profileCards | ||
| }, | ||
|
|
||
| cached() { | ||
| const entry = this.cards().get(this.url) | ||
|
|
||
| if (entry === undefined) return null | ||
|
|
||
| if (entry.expiresAt <= Date.now()) { | ||
| this.cards().delete(this.url) | ||
|
|
||
| return null | ||
| } | ||
|
|
||
| return entry | ||
| }, | ||
|
|
||
| request() { | ||
| const cached = this.cached() | ||
|
|
||
| if (cached !== null) return cached | ||
|
|
||
| const entry = { expiresAt: Date.now() + this.ttl, html: null, promise: null } | ||
|
|
||
| entry.promise = fetch(this.url, { | ||
| headers: { 'X-Requested-With': 'XMLHttpRequest' }, | ||
| }) | ||
| .then((response) => (response.ok ? response.text() : null)) | ||
| .catch(() => null) | ||
| .then((html) => { | ||
| if (html === null) { | ||
| this.cards().delete(this.url) | ||
|
|
||
| return null | ||
| } | ||
|
|
||
| entry.html = html | ||
|
|
||
| return html | ||
| }) | ||
|
|
||
| this.cards().set(this.url, entry) | ||
|
|
||
| return entry | ||
| }, | ||
|
|
||
| async show() { | ||
| if (! this.hoverable) return | ||
|
|
||
| this.open = true | ||
| this.reposition() | ||
|
|
||
| if (this.html !== null) return | ||
|
|
||
| const entry = this.request() | ||
|
|
||
| if (entry.html !== null) { | ||
| this.html = entry.html | ||
| this.reposition() | ||
|
|
||
| return | ||
| } | ||
|
|
||
| this.loading = true | ||
|
|
||
| const html = await entry.promise | ||
|
|
||
| this.loading = false | ||
|
|
||
| if (html === null) { | ||
| this.open = false | ||
|
|
||
| return | ||
| } | ||
|
|
||
| this.html = html | ||
| this.reposition() | ||
| }, | ||
| }" | ||
| x-on:keydown.escape.window="close()" | ||
| x-on:scroll.window.passive="reposition()" | ||
| x-on:resize.window.passive="reposition()" | ||
| > | ||
| <a | ||
| href="{{ route('profile.public', $user->username) }}" | ||
| x-ref="trigger" | ||
| x-on:mouseenter="scheduleOpen()" | ||
| x-on:mouseleave="scheduleClose()" | ||
| x-on:focus="show()" | ||
| x-on:blur="scheduleClose()" | ||
| {{ $attributes }} | ||
| > | ||
| {{ $slot }} | ||
| </a> | ||
|
|
||
| <div | ||
| x-ref="card" | ||
| x-cloak | ||
| x-show="open" | ||
| x-bind:style="cardStyle" | ||
| x-transition.opacity.duration.150ms | ||
| x-on:mouseenter="cancelClose()" | ||
| x-on:mouseleave="scheduleClose()" | ||
| class="fixed z-50 w-80 max-w-[calc(100vw-1rem)]" | ||
| > | ||
| <template x-if="loading"> | ||
| <div | ||
| class="rounded-xl border border-gray-200 bg-white p-4 shadow-lg dark:border-white/10 dark:bg-gray-900" | ||
| > | ||
| <div class="flex items-start gap-3"> | ||
| <div class="h-12 w-12 shrink-0 animate-pulse rounded-full bg-gray-200 dark:bg-white/10"></div> | ||
| <div class="flex-1 space-y-2 pt-1"> | ||
| <div class="h-3 w-2/3 animate-pulse rounded bg-gray-200 dark:bg-white/10"></div> | ||
| <div class="h-2.5 w-1/3 animate-pulse rounded bg-gray-200 dark:bg-white/10"></div> | ||
| </div> | ||
| </div> | ||
| <div class="mt-4 space-y-2"> | ||
| <div class="h-2.5 w-full animate-pulse rounded bg-gray-200 dark:bg-white/10"></div> | ||
| <div class="h-2.5 w-1/2 animate-pulse rounded bg-gray-200 dark:bg-white/10"></div> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <template x-if="html !== null"> | ||
| <div x-html="html"></div> | ||
| </template> | ||
| </div> | ||
| </span> | ||
| @else | ||
| <span {{ $attributes }}>{{ $slot }}</span> | ||
| @endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app-modules/panel-app/resources/views/components/user-avatar.blade.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| @props (['user' => null, 'size' => 'md']) | ||
|
|
||
| @use('He4rt\Profile\Support\ProfileInitials') | ||
|
|
||
| @php | ||
| $displayName = $user?->name ?? 'Usuário removido'; | ||
| $avatarUrl = $user?->getFirstMediaUrl('avatar') ?: null; | ||
| $initials = ProfileInitials::for($displayName, $user?->username); | ||
|
|
||
| $sizeClasses = match ($size) { | ||
| 'lg' => 'h-9 w-9 sm:h-10 sm:w-10', | ||
| 'sm' => 'h-7 w-7 sm:h-8 sm:w-8', | ||
| default => 'h-8 w-8', | ||
| }; | ||
|
|
||
| $initialsClasses = match ($size) { | ||
| 'lg' => 'text-xs sm:text-sm', | ||
| 'sm' => 'text-[10px] sm:text-xs', | ||
| default => 'text-xs', | ||
| }; | ||
| @endphp | ||
|
|
||
| @if ($avatarUrl) | ||
| <img | ||
| src="{{ $avatarUrl }}" | ||
| alt="{{ $displayName }}" | ||
| {{ $attributes->class(['shrink-0 rounded-full object-cover', $sizeClasses]) }} | ||
| /> | ||
| @else | ||
| <div | ||
| {{ | ||
| $attributes->class([ | ||
| 'flex shrink-0 items-center justify-center rounded-full bg-gradient-to-br from-purple-500 to-amber-500 font-semibold text-white', | ||
| $sizeClasses, | ||
| $initialsClasses, | ||
| ]) | ||
| }} | ||
| > | ||
| {{ $initials }} | ||
| </div> | ||
| @endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Honor the cache TTL for component-local HTML.
this.htmlbypassescached()after the first fetch. Clear or revalidate it when the TTL expires. Otherwise, an already-mounted timeline item shows stale profile-card data until remount or page reload.🤖 Prompt for AI Agents