Skip to content
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

🎉 NEW: arrived on #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
19 changes: 15 additions & 4 deletions src/components/ui/FormattedNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
export const FormattedNumber = ({ value, unit }: { value: number | undefined | null; unit: string }) => {
export const FormattedNumber = ({
value,
unit,
notation = 'compact',
prefix = '',
}: {
value: number | undefined | null;
unit?: string;
notation?: 'compact' | 'standard';
prefix?: string;
}) => {
if (value === undefined || value === null) return null;

const formattedValue = new Intl.NumberFormat('en-US').format(value);
const compactValue = new Intl.NumberFormat('en-US', { notation: 'compact' }).format(value);
const formattedValue = new Intl.NumberFormat(navigator.languages ?? 'en-US').format(value);
const compactValue = new Intl.NumberFormat(navigator.languages ?? 'en-US', { notation }).format(value);

return (
<span title={`${formattedValue} ${unit}`}>
<span title={`${prefix}${formattedValue} ${unit}`}>
{prefix}
{compactValue} {unit}
</span>
);
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const en = {
reposts: 'reposts',
likes: 'likes',
settings: 'settings',
arrived_on: 'Arrived on #',
},
settings: {
developerMode: {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const fr = {
reposts: 'republications',
likes: 'aimés',
settings: 'paramètres',
arrived_on: 'Arrivé #',
},
settings: {
developerMode: {
Expand Down
14 changes: 12 additions & 2 deletions src/lib/bluesky/hooks/useProfile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from '@tanstack/react-query';
import { useBlueskyStore } from '../store';

export function useProfile({ handle }: { handle?: string }) {
export function useProfile({ handle, forProfilePage }: { handle?: string; forProfilePage?: boolean }) {
const { agent } = useBlueskyStore();

return useQuery({
Expand All @@ -10,7 +10,17 @@ export function useProfile({ handle }: { handle?: string }) {
if (!agent) throw new Error('Not authenticated');
if (!handle) throw new Error('No handle provided');
const response = await agent.api.app.bsky.actor.getProfile({ actor: handle });
return response.data;

let pos_bsky = undefined;
if (forProfilePage) {
try {
const res = await fetch(`https://skyzoo.blue/stats/plc/${response.data.did}`);
const skyzoo_data = (await res.json()) as any;
pos_bsky = skyzoo_data.pos_bsky as number;
} catch (error) {}
}

return { ...response.data, pos_bsky };
},
enabled: !!agent && !!handle,
});
Expand Down
17 changes: 12 additions & 5 deletions src/routes/profile/$handle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function Media() {

function Profile() {
const { handle } = Route.useParams();
const { data: profile, isLoading } = useProfile({ handle });
const { data: profile, isLoading } = useProfile({ handle, forProfilePage: true });
const { experiments } = useSettings();
const { t } = useTranslation(['app', 'profile']);

Expand Down Expand Up @@ -133,10 +133,17 @@ function Profile() {
{<FollowButton handle={handle} following={!!profile.viewer?.following} />}
</div>
{!experiments.zenMode && (
<div className="flex gap-2">
<FormattedNumber value={profile?.followersCount} unit={t('followers')} />
<FormattedNumber value={profile?.followsCount} unit={t('following')} />
<FormattedNumber value={profile?.postsCount} unit={t('posts')} />
<div className="flex justify-between">
<div className="flex gap-2">
<FormattedNumber value={profile?.followersCount} unit={t('followers')} />
<FormattedNumber value={profile?.followsCount} unit={t('following')} />
<FormattedNumber value={profile?.postsCount} unit={t('posts')} />
</div>
{profile?.pos_bsky && (
<a href={'https://skyzoo.blue/stats/' + handle} target="_blank" className="underline">
<FormattedNumber value={profile?.pos_bsky} notation="standard" prefix={t('arrived_on')} />
</a>
)}
</div>
)}
<p>
Expand Down