Files
stpweb/vue/src/views/home/Steam.vue
T
adamfandClaude Opus 5.5 76735f0552 Improve /stp layout on small screens
- Listening and Steam: fit the artwork to the cell instead of scrolling.
  The image is now a flexible item that takes the height left over after
  the text, so a wide/short cell or a wrapped title can no longer overflow.
- Below 1360px the two sidebars collapse into one tabbed panel (Chat,
  Bookmarks, Commits, Steam) under the sheet instead of a long stack of
  individually scrolling boxes. CSS-only: widgets stay mounted once.
- Phone: clamp song/artist to one line and give the grid a minimum
  height so album art stays visible on short screens.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-01 15:15:10 +01:00

119 lines
3.0 KiB
Vue

<script setup>
/**
* Steam widget on /stp: online status plus a rotation through recent games
* (5s rotation, 5-minute re-poll, both from useRotation()). `loaded` comes from
* homeData so the widget can tell "not fetched yet" from "fetched, nothing to
* show".
*/
import { computed } from "vue";
import { storeToRefs } from "pinia";
import { useSteamStore } from "@/stores/steam";
import { useHomeDataStore } from "@/stores/homeData";
import Header from "@/components/text/Header.vue";
import { useRotation } from "@/js/useRotation";
const ROTATE_MS = 5000;
const REFRESH_MS = 5 * 60 * 1000;
const steamStore = useSteamStore();
const { steamStatus } = storeToRefs(steamStore);
const homeData = useHomeDataStore();
const { loaded } = storeToRefs(homeData);
const { idx, next: nextGame } = useRotation(
() => steamStatus.value.recentGames,
ROTATE_MS,
{ refresh: () => steamStore.fetchSteam(), refreshMs: REFRESH_MS },
);
const game = computed(() => steamStatus.value.recentGames[idx.value]);
function formatHours(minutes) {
const hrs = (minutes / 60).toFixed(1);
return `${hrs}h`;
}
</script>
<template>
<div class="steam-wrapper">
<Header class="text-left">
<span class="flex items-center gap-2">
Steam
<span
class="inline-block w-2 h-2 rounded-full"
:class="steamStatus.online ? 'bg-green-500' : 'bg-gray-400'"
:title="steamStatus.online ? 'Online' : 'Offline'"
/>
</span>
</Header>
<div v-if="!loaded" class="p-2 text-sm">Loading...</div>
<div v-else-if="game" class="game-container">
<Transition name="fade">
<div
@click="nextGame"
:key="game.appId"
class="game flex flex-col items-center pt-2"
>
<img
:src="game.headerImageUrl"
:alt="game.name"
width="145"
height="68"
class="game-img"
/>
<p class="text-center">
<strong>{{ game.name }}</strong>
</p>
<p class="text-center text-tertiary text-xs">
{{ formatHours(game.playtime2Weeks) }} last 2 weeks
</p>
</div>
</Transition>
</div>
<div v-else class="p-2 text-sm">No recent games.</div>
</div>
</template>
<style scoped>
.steam-wrapper {
position: relative;
height: 54mm;
display: flex;
flex-direction: column;
}
.game-container {
position: relative;
flex: 1;
min-height: 0;
overflow: hidden;
}
/* Fit, don't scroll: the text keeps its natural height and the header image
shrinks into whatever is left of the widget's fixed height. It shrinks but
never grows (flex: 0 1 auto), so in the tall small-screen tab panel it stays
at its natural size next to the title instead of floating mid-box. */
.game {
height: 100%;
box-sizing: border-box;
}
.game-img {
flex: 0 1 auto;
min-height: 0;
width: 90%;
max-width: 460px; /* Steam header images are 460x215 */
height: auto;
object-fit: contain;
}
p {
flex-shrink: 0;
width: 100%;
margin: 0 auto;
}
</style>