Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Vleerapp/Vleer
Browse files Browse the repository at this point in the history
  • Loading branch information
0PandaDEV committed Apr 18, 2024
2 parents 58d674f + bd23726 commit b2e253a
Show file tree
Hide file tree
Showing 3 changed files with 348 additions and 327 deletions.
15 changes: 10 additions & 5 deletions assets/styles/pages/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.element {
padding: 0 !important;
overflow: hidden;
}

.index {
Expand All @@ -10,7 +11,8 @@
font-size: 14px;
width: 100%;
height: 100%;
overflow: auto;
overflow: hidden;
overflow-y: auto;
}

.ascii {
Expand All @@ -27,8 +29,8 @@

.recently-played {
.cards {
width: 100%;
padding-bottom: 10px;
overflow-y: auto;
display: flex;
flex-direction: row;
gap: 16px;
Expand All @@ -38,9 +40,13 @@
flex-direction: column;
gap: 8px;
cursor: pointer;
width: 100%;

.info {
width: 100%;

p {
width: 140px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
Expand All @@ -53,9 +59,8 @@
}

.cover {
flex: 1;
max-width: 240px;
min-width: 150px;
width: 100%;
aspect-ratio: 1 / 1;
}
}
}
Expand Down
43 changes: 37 additions & 6 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

<div class="recently-played">
<div class="title">Recently played</div>
<div class="cards">
<div class="cards" ref="cards">
<div v-for="song in sortedRecentlyPlayed" :key="song.id" @click="play(song.id)" class="song">
<img :src="song.coverURL" :alt="song.title" class="cover" />
<div class="info">
<p class="title">{{ truncate(song.title) }}</p>
<p class="artist">{{ truncate(song.artist) }}</p>
<p class="title" :title="song.title">{{ song.title }}</p>
<p class="artist" :title="song.artist">{{ song.artist }}</p>
</div>
</div>
</div>
Expand All @@ -31,13 +31,37 @@
</div>
</template>

<script lang="ts" setup>
<script setup lang="ts">
import { type Song } from "~/types/types";
import { computed, ref, onMounted } from 'vue';
import { computed, ref, onMounted, onUnmounted, watch } from 'vue';
import { useNuxtApp } from '#imports';
const { $music } = useNuxtApp();
const songs = ref<Song[]>([]);
const cards = ref(null);
const maxCards = ref(5);
const cardsWidth = ref(0);
const cardMinWidth = 140;
const cardMaxWidth = 180;
const cardGap = 16;
const updateWidth = () => {
cardsWidth.value = cards.value?.clientWidth || 0;
updateMaxCards();
};
const updateMaxCards = () => {
const maxPossible = Math.floor(cardsWidth.value / (cardMinWidth + cardGap));
const minPossible = Math.floor(cardsWidth.value / (cardMaxWidth + cardGap));
maxCards.value = maxPossible;
};
watch(cards, (newVal, oldVal) => {
if (newVal !== oldVal) {
updateWidth();
}
});
onMounted(async () => {
const loadedSongs = await $music.getSongs();
Expand All @@ -48,13 +72,19 @@ onMounted(async () => {
})
);
songs.value = songArray;
updateWidth();
window.addEventListener('resize', updateWidth);
});
onUnmounted(() => {
window.removeEventListener('resize', updateWidth);
});
const sortedRecentlyPlayed = computed(() => {
return [...songs.value]
.filter(song => song.lastPlayed)
.sort((a, b) => new Date(b.lastPlayed).getTime() - new Date(a.lastPlayed).getTime())
.slice(0, 7);
.slice(0, maxCards.value);
});
async function play(id: string) {
Expand All @@ -67,6 +97,7 @@ function truncate(text: string, length: number = 24) {
}
</script>


<style scoped lang="scss">
@import "~/assets/styles/pages/index.scss";
</style>
Loading

0 comments on commit b2e253a

Please sign in to comment.