Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IDATT2106 Scrum Team 02
Frontend
Commits
7336bdaf
Commit
7336bdaf
authored
2 years ago
by
Ingrid Martinsheimen Egge
Browse files
Options
Downloads
Patches
Plain Diff
fjernet fridge som eget store. oppdaterte metoder
parent
3ead56bb
Branches
ResetPassword
Branches containing commit
No related tags found
1 merge request
!20
Fridge updates
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/stores/authStore.js
+8
-1
8 additions, 1 deletion
src/stores/authStore.js
src/util/API.js
+5
-16
5 additions, 16 deletions
src/util/API.js
src/views/FridgeView.vue
+4
-5
4 additions, 5 deletions
src/views/FridgeView.vue
with
17 additions
and
22 deletions
src/stores/authStore.js
+
8
−
1
View file @
7336bdaf
...
...
@@ -6,7 +6,8 @@ export const useAuthStore = defineStore("auth", {
account
:
{},
profile
:
{},
profiles
:
[],
items
:
{
ingredientList
:
[],
suggestionList
:
[]}
items
:
{
ingredientList
:
[],
suggestionList
:
[]},
fridgeItems
:
[],
};
},
persist
:
{
...
...
@@ -38,6 +39,12 @@ export const useAuthStore = defineStore("auth", {
},
setItem
(
item
)
{
this
.
items
.
push
(
item
);
},
setFridge
(
fridgeItems
){
this
.
fridgeItems
=
fridgeItems
;
},
addItemToFridge
(
fridgeItem
){
this
.
fridgeItems
.
push
(
fridgeItem
);
}
}
});
This diff is collapsed.
Click to expand it.
src/util/API.js
+
5
−
16
View file @
7336bdaf
...
...
@@ -183,6 +183,7 @@ export const API = {
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
})
.
then
((
response
)
=>
{
authStore
.
setFridge
(
response
.
data
)
return
response
.
data
;
}).
catch
(()
=>
{
throw
new
Error
(
"
Could not fetch fridge items
"
);
...
...
@@ -233,6 +234,7 @@ export const API = {
axios
.
put
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge/ingredientsAmount`
,
request
,{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
}).
then
((
response
)
=>
{
authStore
.
setFridge
(
response
.
data
);
return
response
.
data
;
}).
catch
(()
=>
{
throw
new
Error
(
"
Could modify ingredient.
"
);
...
...
@@ -256,22 +258,6 @@ export const API = {
})
},
//returns fridgeItem of specific id
getFridgeItem
:
async
(
id
)
=>
{
const
authStore
=
useAuthStore
();
axios
.
get
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge/
${
id
}
`
,
{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
})
.
then
((
response
)
=>
{
return
response
.
data
;
})
.
catch
(()
=>
{
throw
new
Error
(
"
Could not fetch fridge item
"
);
});
},
/**
* Getter for the shopping list of a logged in account
* @returns a promise that resolves to an array of Ingredient objects representing the shopping list, or an error if it fails
...
...
@@ -402,6 +388,9 @@ export const API = {
},
/**
...
...
This diff is collapsed.
Click to expand it.
src/views/FridgeView.vue
+
4
−
5
View file @
7336bdaf
...
...
@@ -31,14 +31,13 @@ export default {
name
:
"
FridgeView
"
,
components
:
{
ItemSearch
,
EatFridgeItemModal
,
FridgeItem
},
computed
:{
...
mapState
(
useAuthStore
,
[
'
account
'
]),
...
mapStores
(
useFridgeStore
),
...
mapState
(
useAuthStore
,
[
'
account
'
,
'
fridgeItems
'
]),
},
data
()
{
return
{
visible
:
false
,
//is the useitemModal visible
selectedItem
:
null
,
fridgeItems
:
[],
//
fridgeItems: [],
searchVisible
:
false
,
fridgeMsg
:
""
}
...
...
@@ -63,14 +62,14 @@ export default {
},
async
updateFridge
(
addedItem
)
{
this
.
fridgeItems
=
await
API
.
getFridgeItems
();
this
.
fridgeItems
=
await
API
.
getFridgeItems
();
this
.
hideItemSearch
();
this
.
updateFridgeMessage
(
addedItem
.
name
+
"
ble lagt i kjøleskapet.
"
)
},
},
async
mounted
()
{
this
.
fridgeItems
=
await
API
.
getFridgeItems
()
;
await
API
.
getFridgeItems
()
if
(
this
.
fridgeItems
.
length
===
0
){
this
.
fridgeMsg
=
"
Kjøleskapet ditt er tomt.
"
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment