Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sparesti-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_2024_01
sparesti-frontend
Merge requests
!10
refactor: updated days left in challenge component
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
refactor: updated days left in challenge component
current-saving-challenge-component
into
development
Overview
0
Commits
1
Pipelines
1
Changes
2
Merged
Maria Elizabeth Pauna Lane
requested to merge
current-saving-challenge-component
into
development
1 year ago
Overview
0
Commits
1
Pipelines
1
Changes
2
Expand
Added days and hours, and fixed time zome issue
0
0
Merge request reports
Compare
development
development (base)
and
latest version
latest version
4e6cde8b
1 commit,
1 year ago
2 files
+
34
−
20
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/components/CurrentSavingChallenge.vue
+
34
−
19
Options
<
script
setup
>
<
script
setup
>
import
{
ref
}
from
'
vue
'
import
{
onBeforeMount
,
ref
}
from
'
vue
'
import
{
Card
}
from
"
@/components/ui/card/index.js
"
;
import
{
Card
}
from
"
@/components/ui/card/index.js
"
;
/**
/**
* The category of the saving challenge
* The category of the saving challenge
* @type {Ref<UnwrapRef<string>>}
*/
*/
const
category
=
ref
(
'
Kaffe
'
)
const
category
=
ref
(
'
Kaffe
'
)
/**
/**
* The amount of money the user wants to spend
* The amount of money the user wants to spend
* @type {Ref<UnwrapRef<number>>}
*/
*/
const
amount
=
ref
(
200
)
const
amount
=
ref
(
200
)
/**
/**
* The goal amount the user wants to spend
* The goal amount the user wants to spend
* @type {Ref<UnwrapRef<number>>}
*/
*/
const
goal
=
ref
(
400
)
const
goal
=
ref
(
400
)
/**
/**
* The deadline for the saving challenge
* The deadline for the saving challenge
* @type {Ref<UnwrapRef<string>>}
*/
*/
const
deadline
=
ref
(
'
2024-04-30
'
)
const
deadline
=
ref
(
'
2024-05-29
'
)
/**
* The days left for the saving challenge
*/
const
daysLeft
=
ref
(
0
)
/**
/**
* The number of days left until the deadline
* The hours left for the saving challenge
* @type {Ref<UnwrapRef<number>>}
*/
*/
const
day
sLeft
=
updateDaysLeft
(
)
const
hour
sLeft
=
ref
(
0
)
/**
/**
* Updates the days left until the given deadline
* Set the time remaining for the saving challenge
* @returns {number} The number of days left
*/
*/
function
updateDaysLeft
()
{
function
setTimeRemaining
(){
//TODO: Feilhåndtering ugyldig dato?
const
endDate
=
new
Date
(
deadline
.
value
);
const
today
=
new
Date
()
const
offset
=
endDate
.
getTimezoneOffset
();
const
deadlineDate
=
new
Date
(
deadline
.
value
)
const
now
=
new
Date
();
const
diffTime
=
deadlineDate
-
today
now
.
setMinutes
(
now
.
getMinutes
()
-
offset
);
const
diffDays
=
Math
.
ceil
(
diffTime
/
(
1000
*
60
*
60
*
24
))
const
total
=
endDate
-
now
;
return
diffDays
if
(
total
<
0
)
{
daysLeft
.
value
=
0
;
hoursLeft
.
value
=
0
;
return
;
}
const
hours
=
Math
.
floor
(
(
total
/
(
1000
*
60
*
60
))
%
24
);
const
days
=
Math
.
floor
(
total
/
(
1000
*
60
*
60
*
24
)
);
hoursLeft
.
value
=
hours
;
daysLeft
.
value
=
days
;
}
}
/**
* Set the time remaining when the component is mounted
*/
onBeforeMount
(()
=>
{
setTimeRemaining
()
})
</
script
>
</
script
>
@@ -48,7 +63,7 @@ function updateDaysLeft() {
@@ -48,7 +63,7 @@ function updateDaysLeft() {
<card>
<card>
<div
class=
"flex justify-between px-2.5"
>
<div
class=
"flex justify-between px-2.5"
>
<p
class=
"text-left"
>
{{
category
}}
</p>
<p
class=
"text-left"
>
{{
category
}}
</p>
<p
class=
"text-right"
@
reset=
"
updateDaysLeft
"
>
Innen
{{
daysLeft
}}
dager
</p>
<p
class=
"text-right"
@
reset=
"
setTimeRemaining
"
>
Innen
{{
daysLeft
}}
d
{{
hoursLeft
}}
t
</p>
</div>
</div>
<div
class=
"flex justify-center"
>
<div
class=
"flex justify-center"
>
<p
class=
""
>
Bruke mindre enn:
</p>
<p
class=
""
>
Bruke mindre enn:
</p>
Loading