From cc0bcee1a4f1beea928b81b2235e831a595e8d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Felipe=20Gon=C3=A7alves?= Date: Sun, 4 Feb 2024 11:33:51 -0300 Subject: [PATCH 1/5] feat(lastFm): create new types and functions --- src/shared/lib/lastFm.ts | 102 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 4 deletions(-) diff --git a/src/shared/lib/lastFm.ts b/src/shared/lib/lastFm.ts index 888632be..4b096267 100644 --- a/src/shared/lib/lastFm.ts +++ b/src/shared/lib/lastFm.ts @@ -24,9 +24,30 @@ export type Track = { '@attr': { rank: string } } +type ImageSize = 'small' | 'medium' | 'large' | 'extralarge' +type Period = 'overall' | '7day' | '1month' | '3month' | '6month' | '12month' + +type RecentTrack = { + artist: { + mbid: string + '#text': string + } + streamable: '0' | '1' + image: { + size: ImageSize + '#text': string + }[] + + mbid: string + album: { mbid: string; '#text': string } + name: string + url: string + date: { uts: string; '#text': string } +} + type RecentTracksBody = { recenttracks: { - track: Track[] + track: RecentTrack[] } } @@ -88,15 +109,34 @@ export async function getLastFmTopArtists() { return artist } +type TopTrack = { + streamable: { fulltrack: '0' | '1'; '#text': '0' | '1' } + mbid: string + name: string + image: { + size: ImageSize + '#text': string + }[] + artist: { + url: string + name: string + mbid: string + } + url: string + duration: string + '@attr': { rank: string } + playcount: string +} + type TopTracksBody = { toptracks: { - track: Track[] + track: TopTrack[] } } -export async function getLastFmTopTracks() { +export async function getLastFmTopTracks(period: Period = '6month') { const lastFmApiRequest = await fetch( - `http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=mateusfg7&api_key=${process.env.LASTFM_API_KEY}&format=json&period=6month` + `http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=mateusfg7&api_key=${process.env.LASTFM_API_KEY}&format=json&period=${period}` ) if (!lastFmApiRequest.ok) { @@ -115,6 +155,60 @@ export async function getLastFmTopTracks() { return tracks } +type TrackInfoBody = { + track: { + name: string + mbid: string + url: string + duration: string + streamable: { '#text': '0' | '1'; fulltrack: '0' | '1' } + listeners: string + playcount: string + artist: { + name: string + mbid: string + url: string + } + album: { + artist: string + title: string + mbid: string + url: string + image: { + size: ImageSize + '#text': string + }[] + '@attr': { position: string } + } + toptags: { tag: { name: string; url: string }[] } + } +} + +export async function getTrackInfo({ + trackName, + artistName +}: { + trackName: string + artistName: string +}) { + const lastFmApiRequest = await fetch( + `http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=${process.env.LASTFM_API_KEY}&artist=${artistName}&track=${trackName}&format=json` + ) + + if (!lastFmApiRequest.ok) { + console.log(lastFmApiRequest) + throw new ApiError({ + message: lastFmApiRequest.statusText, + status: lastFmApiRequest.status, + url: lastFmApiRequest.url + }) + } + + const { track }: TrackInfoBody = await lastFmApiRequest.json() + + return track +} + type User = { name: string playcount: string From c70fc3878b10beccc2d228f2ce55b73fdc87ee1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Felipe=20Gon=C3=A7alves?= Date: Sun, 4 Feb 2024 11:35:18 -0300 Subject: [PATCH 2/5] feat(ui): replace "last track" sectionby "top track" section --- .../spotify-dashboard/cards/top-track.tsx | 49 +++++++++++++++++++ .../components/spotify-dashboard/index.tsx | 8 ++- .../spotify-dashboard/skeleton/index.tsx | 6 ++- .../skeleton/top-track-skeleton.tsx | 19 +++++++ 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/app/about/statistics/components/spotify-dashboard/cards/top-track.tsx create mode 100644 src/app/about/statistics/components/spotify-dashboard/skeleton/top-track-skeleton.tsx diff --git a/src/app/about/statistics/components/spotify-dashboard/cards/top-track.tsx b/src/app/about/statistics/components/spotify-dashboard/cards/top-track.tsx new file mode 100644 index 00000000..072ad9da --- /dev/null +++ b/src/app/about/statistics/components/spotify-dashboard/cards/top-track.tsx @@ -0,0 +1,49 @@ +import Image from 'next/image' +import { MusicNotes } from '@phosphor-icons/react/dist/ssr' + +import { placeholder } from '@/shared/lib/placeholder' +import { getLastFmTopTracks, getTrackInfo } from '@/shared/lib/lastFm' + +export async function TopTrack() { + const tracks = await getLastFmTopTracks('1month') + + const topTrack = await getTrackInfo({ + artistName: tracks[0].artist.name, + trackName: tracks[0].name + }) + const imageUrl = topTrack.album.image.filter( + image => image.size === 'extralarge' + )[0]['#text'] + + return ( +
+
+ + Top Played + + + + From last month + + + + {topTrack.name} - {topTrack.artist.name} + + +
+ Artist Image +
+ ) +} diff --git a/src/app/about/statistics/components/spotify-dashboard/index.tsx b/src/app/about/statistics/components/spotify-dashboard/index.tsx index 7c6334ed..a3717c9c 100644 --- a/src/app/about/statistics/components/spotify-dashboard/index.tsx +++ b/src/app/about/statistics/components/spotify-dashboard/index.tsx @@ -3,7 +3,8 @@ import { ErrorBoundary } from 'react-error-boundary' import { FallbackError } from '../fallback-error' -import { LastTrack } from './cards/last-track' +// import { LastTrack } from './cards/last-track' +import { TopTrack } from './cards/top-track' import { TopTracks } from './cards/top-tracks' import { TopArtists } from './cards/top-artists' @@ -15,8 +16,11 @@ export function SpotifyDashboard() { }>
- +
+ {/*
+ +
*/} diff --git a/src/app/about/statistics/components/spotify-dashboard/skeleton/index.tsx b/src/app/about/statistics/components/spotify-dashboard/skeleton/index.tsx index f6f35cf1..9bb3b4d3 100644 --- a/src/app/about/statistics/components/spotify-dashboard/skeleton/index.tsx +++ b/src/app/about/statistics/components/spotify-dashboard/skeleton/index.tsx @@ -1,12 +1,16 @@ import { LastTrackSkeleton } from './last-track-skeleton' import { TopArtistsSkeleton } from './top-artists.skeleton' +import { TopTrackSkeleton } from './top-track-skeleton' import { TopTracksSkeleton } from './top-tracks-skeleton' export function SpotifyStatsSkeleton() { return (
-
+ {/*
+
*/} +
+
diff --git a/src/app/about/statistics/components/spotify-dashboard/skeleton/top-track-skeleton.tsx b/src/app/about/statistics/components/spotify-dashboard/skeleton/top-track-skeleton.tsx new file mode 100644 index 00000000..298773d0 --- /dev/null +++ b/src/app/about/statistics/components/spotify-dashboard/skeleton/top-track-skeleton.tsx @@ -0,0 +1,19 @@ +import { MusicNotes } from '@phosphor-icons/react/dist/ssr' + +export function TopTrackSkeleton() { + return ( +
+
+ + Top Played + + + +
+
+
+
+
+
+ ) +} From d1409811c8586107a78ce156b70824ca6842fd74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Felipe=20Gon=C3=A7alves?= Date: Sun, 4 Feb 2024 11:52:36 -0300 Subject: [PATCH 3/5] feat(ui): replace "last track" sectionby "top track" section --- .../sections/statistics/cards/last-track.tsx | 39 ------------------- .../about/sections/statistics/cards/posts.tsx | 14 +++++++ src/app/about/sections/statistics/index.tsx | 4 +- 3 files changed, 16 insertions(+), 41 deletions(-) delete mode 100644 src/app/about/sections/statistics/cards/last-track.tsx create mode 100644 src/app/about/sections/statistics/cards/posts.tsx diff --git a/src/app/about/sections/statistics/cards/last-track.tsx b/src/app/about/sections/statistics/cards/last-track.tsx deleted file mode 100644 index e822a976..00000000 --- a/src/app/about/sections/statistics/cards/last-track.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import Image from 'next/image' -import { SpotifyLogo } from '@phosphor-icons/react/dist/ssr' - -import { getLastFmRecentTracks } from '@/shared/lib/lastFm' -import { placeholder } from '@/shared/lib/placeholder' - -import { Card } from '../card' - -export async function LastTrack() { - const recentTracks = await getLastFmRecentTracks() - const lastTrack = recentTracks[0] - - return ( - } - content={ - - Artist Image - - {lastTrack.name} - {lastTrack.artist['#text']} - - - } - /> - ) -} diff --git a/src/app/about/sections/statistics/cards/posts.tsx b/src/app/about/sections/statistics/cards/posts.tsx new file mode 100644 index 00000000..06ba89d3 --- /dev/null +++ b/src/app/about/sections/statistics/cards/posts.tsx @@ -0,0 +1,14 @@ +import { Article } from '@phosphor-icons/react/dist/ssr' +import { allPosts } from 'contentlayer/generated' + +import { Card } from '../card' + +export async function BlogPosts() { + return ( + } + content={allPosts.length} + /> + ) +} diff --git a/src/app/about/sections/statistics/index.tsx b/src/app/about/sections/statistics/index.tsx index 2d3a33f6..00b76f11 100644 --- a/src/app/about/sections/statistics/index.tsx +++ b/src/app/about/sections/statistics/index.tsx @@ -6,7 +6,7 @@ import { ArrowUpRight } from '@phosphor-icons/react/dist/ssr' import { AgeCard } from './cards/age' import { GithubFollowers } from './cards/github-followers' import { GithubStars } from './cards/github-stars' -import { LastTrack } from './cards/last-track' +import { BlogPosts } from './cards/posts' import { SpotifyPlays } from './cards/spotify-plays' import { TopArtist } from './cards/top-artist' @@ -21,9 +21,9 @@ export function StatisticsGrid() { + -
Date: Sun, 4 Feb 2024 11:53:38 -0300 Subject: [PATCH 4/5] chore(release): v8.12.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ecce6b25..d1b15c56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mateusf.com", - "version": "8.12.0", + "version": "8.12.1", "homepage": "https://mateusf.com", "license": "GPL-3.0", "author": "Mateus Felipe Gonçalves (mateusfg7) ", From 2ace843320d13dd7379f468cf1b7bbdc3160e5ae Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 4 Feb 2024 14:54:21 +0000 Subject: [PATCH 5/5] docs(CHANGELOG): v8.12.1 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12035c8e..7e19b541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [8.12.1](https://github.com/mateusfg7/mateusf.com/compare/8.12.0...8.12.1) (2024-02-04) + + +### Features + +* **lastFm:** create new types and functions ([cc0bcee](https://github.com/mateusfg7/mateusf.com/commit/cc0bcee1a4f1beea928b81b2235e831a595e8d71)) +* **ui:** replace "last track" sectionby "top track" section ([d140981](https://github.com/mateusfg7/mateusf.com/commit/d1409811c8586107a78ce156b70824ca6842fd74)) +* **ui:** replace "last track" sectionby "top track" section ([c70fc38](https://github.com/mateusfg7/mateusf.com/commit/c70fc3878b10beccc2d228f2ce55b73fdc87ee1a)) + ## [8.12.0](https://github.com/mateusfg7/mateusf.com/compare/8.11.3...8.12.0) (2024-01-23)