Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simple list of last added prices #26

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/components/PriceCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<v-card>
<v-card-item>
<template v-slot:prepend>
<v-avatar v-if="price.product" :image="price.product.image_url || defaultAvatar"></v-avatar>
raphodn marked this conversation as resolved.
Show resolved Hide resolved
<v-avatar v-if="!price.product" :image="defaultAvatar"></v-avatar>
</template>

<v-card-title v-if="price.product">{{ price.product.product_name }}</v-card-title>
<v-card-title v-if="!price.product">{{ price.product_code }}</v-card-title>

<v-card-subtitle v-if="price.product">{{ price.product.product_quantity }} · {{ price.product.brands }}</v-card-subtitle>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the field product.brands is currently being added in the backend : openfoodfacts/open-prices#93

<v-card-subtitle v-if="!price.product"></v-card-subtitle>
</v-card-item>

<v-card-text>
<span>{{ price.price }} {{ price.currency }}</span>
<span> · </span>
<span v-if="price.location">{{ price.location.osm_name }}, {{ price.location.osm_address_city }}</span>
<span v-if="!price.location">{{ price.location_id }}</span>
<span> · </span>
<span>{{ price.date }}</span>
</v-card-text>
</v-card>
</template>

<script>
export default {
props: ['price'],
data() {
return {
defaultAvatar: 'https://world.openfoodfacts.org/images/icons/dist/packaging.svg'
}
}
}
</script>
2 changes: 2 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Home from './views/Home.vue'
import SignIn from './views/SignIn.vue'
import AddPriceHome from './views/AddPriceHome.vue'
import AddPriceSingle from './views/AddPriceSingle.vue'
import PriceList from './views/PriceList.vue'
import NotFound from './views/NotFound.vue'

/** @type {import('vue-router').RouterOptions['routes']} */
Expand All @@ -10,5 +11,6 @@ export let routes = [
{ path: '/sign-in', name: 'sign-in', component: SignIn, meta: { title: 'Sign in', icon: 'mdi-login', drawerMenu: true, requiresAuth: false } },
{ path: '/add', name: 'add-price', component: AddPriceHome, meta: { title: 'Add a price', icon: 'mdi-plus', drawerMenu: true, requiresAuth: true }},
{ path: '/add/single', name: 'add-price-single', component: AddPriceSingle, meta: { title: 'Add a single price', requiresAuth: true }},
{ path: '/prices', name: 'prices', component: PriceList, meta: { title: 'Last prices', icon: 'mdi-tag-multiple-outline', drawerMenu: true }},
{ path: '/:path(.*)', component: NotFound },
]
12 changes: 12 additions & 0 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ export default {
.then((response) => response.json())
},

getPrices(params = {}) {
const url = `${import.meta.env.VITE_OPEN_PRICES_API_URL}/prices?${new URLSearchParams(params)}`
return fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.getToken()}`
},
})
.then((response) => response.json())
},

openstreetmapNominatimSearch(q) {
return fetch(`https://nominatim.openstreetmap.org/search?q=${q}&format=json&limit=5`, {
method: 'GET',
Expand Down
36 changes: 36 additions & 0 deletions src/views/PriceList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<h1 class="mb-1">Last prices</h1>

<v-row>
<v-col cols="12" sm="6" md="4" v-for="price in prices" :key="price">
<PriceCard :price="price" elevation="1" height="100%"></PriceCard>
</v-col>
</v-row>
</template>

<script>
import api from '../services/api'
import PriceCard from '../components/PriceCard.vue'

export default {
components: {
PriceCard,
},
data() {
return {
prices: [],
}
},
mounted() {
this.getPrices()
},
methods: {
getPrices() {
return api.getPrices({ order_by: '-date' })
.then((data) => {
this.prices = data.items
})
}
}
}
</script>