Skip to content

Commit

Permalink
feat: price outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Mar 5, 2024
1 parent 31d6dbf commit 38fe019
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion components/City.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import CreateLog from './CreateLog.vue';
const props = defineProps<{ city: CityInfo }>();
const timestamp = useTimestamp({ interval: 10 * 1000 });
const store = useLatestLogs();
</script>

Expand All @@ -45,7 +47,10 @@ const store = useLatestLogs();
<TableRow v-for="product in city.products" :key="product.name">
<TableCell>{{ product.name }}</TableCell>
<TableCell v-for="target in cities" :key="target.name"
><Price :log="store.getLatestLog(city.name, product.name, target.name)"></Price
><Price
:timestamp="timestamp"
:log="store.getLatestLog(city.name, product.name, target.name)"
></Price
></TableCell>
<TableCell><CreateLog :city="city" :product="product"></CreateLog></TableCell>
</TableRow>
Expand Down
10 changes: 8 additions & 2 deletions components/Price.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<script setup lang="ts">
import type { Log } from '~/drizzle/schema';
defineProps<{ log: Log | undefined }>();
const props = defineProps<{ timestamp: number; log: Log | undefined }>();
const isOutdated = computed(() => {
if (!props.log) return true;
const uploadedAt = props.log.uploadedAt.getTime();
return props.timestamp - uploadedAt > 3600 * 1000;
});
</script>

<template>
<div v-if="log">
<div v-if="log" :class="{ 'line-through': isOutdated, 'op-50': isOutdated }">
<div>
<span>{{ log.price }}</span>
</div>
Expand Down

0 comments on commit 38fe019

Please sign in to comment.