Skip to content

Commit

Permalink
refactor tracklist pages to use API
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewelsby committed Jul 17, 2024
1 parent d2e8f34 commit a44969d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 48 deletions.
4 changes: 2 additions & 2 deletions components/Episode/EpisodeListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export default {
return classes
},
formattedDate() {
if (this.episode.published_at) {
if (this.episode.publishedAt || this.episode.published_at) {
return new Intl.DateTimeFormat('en-US', {
dateStyle: 'long',
}).format(Date.parse(this.episode.published_at))
}).format(Date.parse(this.episode.publishedAt || this.episode.published_at))
} else {
return 'INVALID DATE'
}
Expand Down
40 changes: 19 additions & 21 deletions pages/tracklists/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,30 @@
</template>

<script>
import { useFilteredShows } from '~/compositions'
export default {
name: 'SoulectionTracklists',
async asyncData({ $sentry, $supabase, $config, error }) {
const {
error: err,
shows,
tagsWithCounts,
totalCount,
count,
} = await useFilteredShows({
$supabase,
$config,
})
if (err) {
$sentry.captureException(err)
async asyncData({ $axios, error }) {
const page = 1;
const config = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};
try {
const {data, headers} = await $axios.get(`https://v5-api-soulectiontracklists-com.fly.dev/shows?page=${page}`, config);
return {
latestShow: data[0],
shows: data,
tagsWithCounts: {},
count: parseInt(headers['total-count']) || 999,
totalCount: parseInt(headers['total-count']) || 999
}
} catch (err) {
error({ statusCode: 500, message: err })
}
return {
latestShow: shows[0],
shows,
tagsWithCounts,
count,
totalCount,
}
},
head() {
return {
Expand Down
43 changes: 18 additions & 25 deletions pages/tracklists/page/_page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,28 @@
</template>

<script>
import { useFilteredShows } from '~/compositions'
export default {
async asyncData({ $sentry, $supabase, params, $config, error }) {
const {
error: err,
shows,
tagsWithCounts,
totalCount,
count,
} = await useFilteredShows(
{
$supabase,
$config,
},
null,
params.page
)
if (err) {
$sentry.captureException(err)
async asyncData({ $axios, params, error }) {
const config = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};
try {
const {data, headers} = await $axios.get(`https://v5-api-soulectiontracklists-com.fly.dev/shows?page=${params.page}`, config);
console.log(parseInt(headers['total-count']))

Check warning on line 32 in pages/tracklists/page/_page.vue

View workflow job for this annotation

GitHub Actions / Lint 🚨

Unexpected console statement
return {
latestShow: data[0],
shows: data,
tagsWithCounts: {},
count: parseInt(headers['total-count']) || 999,
totalCount: parseInt(headers['total-count']) || 999
}
} catch (err) {
error({ statusCode: 500, message: err })
}
return {
latestShow: shows[0],
shows,
tagsWithCounts,
count,
totalCount,
}
},
head() {
return {
Expand Down

0 comments on commit a44969d

Please sign in to comment.