Skip to content
Snippets Groups Projects
Commit ceb12723 authored by Eline Evje's avatar Eline Evje
Browse files

chore: ran format

parent 25b3304b
No related branches found
No related tags found
3 merge requests!66Final merge,!47Feat/implement genereated challenges modal,!4Pipeline fix
......@@ -29,9 +29,9 @@ const props = defineProps({
buttonText: String,
type: String,
showModal: Boolean
});
})
const emit = defineEmits(['update:showModal']);
const emit = defineEmits(['update:showModal'])
const router = useRouter()
......@@ -39,12 +39,11 @@ const btnText = ref(props.buttonText)
const routeToGoalOrChallenge = () => {
if (props.type === 'goal') {
router.push('/sparemaal');
router.push('/sparemaal')
} else if (props.type === 'challenge') {
router.push('/spareutfordringer');
router.push('/spareutfordringer')
} else if (props.type === 'generatedChallenge') {
emit('update:showModal', true);
emit('update:showModal', true)
}
};
}
</script>
......@@ -25,9 +25,16 @@
Personlig tilpassede spareutfordringer:
</div>
<div class="grid grid-cols-7 sm:grid-cols-11 gap-2 p-3 pb-1 border-b-2">
<span class="font-bold col-span-2 md:col-span-3 sm:text-lg pt-1 mb-0">Tittel</span>
<span class="font-bold col-span-2 md:col-span-2 sm:text-lg pt-1 mb-0">Målsum</span>
<span class="font-bold col-span-2 md:col-span-1 sm:text-lg pt-1 pr-1 md:pr-3 mb-0">Frist</span>
<span class="font-bold col-span-2 md:col-span-3 sm:text-lg pt-1 mb-0"
>Tittel</span
>
<span class="font-bold col-span-2 md:col-span-2 sm:text-lg pt-1 mb-0"
>Målsum</span
>
<span
class="font-bold col-span-2 md:col-span-1 sm:text-lg pt-1 pr-1 md:pr-3 mb-0"
>Frist</span
>
<span class="col-span-2"></span>
</div>
<div class="space-y-2">
......@@ -37,13 +44,21 @@
:class="{ 'bg-gray-100': index % 2 === 0 }"
class="grid grid-cols-7 md:grid-cols-7 sm:grid-cols-2 lg:grid-cols-7 gap-4 items-center border p-3 rounded mt-[-8px]"
>
<span class="break-words col-span-2 md:col-span-1 lg:col-span-2 text-lg">{{ challenge.title }}</span>
<span class="col-span-2 md:col-span-2 lg:col-span-1 text-lg">{{ challenge.target }}</span>
<span class="col-span-2 md:col-span-1 lg:col-span-2 text-lg">{{ challenge.due }}</span>
<span class="break-words col-span-2 md:col-span-1 lg:col-span-2 text-lg">{{
challenge.title
}}</span>
<span class="col-span-2 md:col-span-2 lg:col-span-1 text-lg">{{
challenge.target
}}</span>
<span class="col-span-2 md:col-span-1 lg:col-span-2 text-lg">{{
challenge.due
}}</span>
<div
class="col-span-7 sm:col-start-3 sm:col-span-2 md:col-span-2 lg:col-span-2 flex items-center justify-end space-x-2"
>
<span v-if="challenge.isAccepted" class="font-bold text-lg">Godtatt!</span>
<span v-if="challenge.isAccepted" class="font-bold text-lg"
>Godtatt!</span
>
<button
@click="acceptChallenge(challenge)"
class="text-white font-bold py-1 px-4 mt-[-14px] sm:mt-0"
......@@ -61,43 +76,46 @@
</div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue'
import authInterceptor from '@/services/authInterceptor'
const showModal = ref(true);
const generatedChallenges = reactive([]);
const showModal = ref(true)
const generatedChallenges = reactive([])
async function fetchGeneratedChallenges() {
try {
const response = await authInterceptor.get('/challenges/generate');
const response = await authInterceptor.get('/challenges/generate')
if (response.status === 200) {
generatedChallenges.splice(0, generatedChallenges.length, ...response.data.map(ch => ({
...ch,
due: new Date(ch.due).toISOString().split('T')[0],
dueFull: ch.due,
accepted: false
})));
console.log('Generated challenges:', generatedChallenges);
generatedChallenges.splice(
0,
generatedChallenges.length,
...response.data.map((ch) => ({
...ch,
due: new Date(ch.due).toISOString().split('T')[0],
dueFull: ch.due,
accepted: false
}))
)
console.log('Generated challenges:', generatedChallenges)
} else {
console.log('No challenges found for the user.');
generatedChallenges.splice(0, generatedChallenges.length);
console.log('No challenges found for the user.')
generatedChallenges.splice(0, generatedChallenges.length)
}
} catch (error) {
console.error('Error fetching challenges:', error);
console.error('Error fetching challenges:', error)
}
}
onMounted(() => {
fetchGeneratedChallenges();
localStorage.setItem('lastModalShow', Date.now().toString());
});
fetchGeneratedChallenges()
localStorage.setItem('lastModalShow', Date.now().toString())
})
function acceptChallenge(challenge) {
if (!challenge) {
console.error('No challenge data provided to acceptChallenge function.');
return;
console.error('No challenge data provided to acceptChallenge function.')
return
}
const postData = {
title: challenge.title,
......@@ -107,18 +125,19 @@ function acceptChallenge(challenge) {
description: challenge.description,
due: challenge.dueFull,
type: challenge.type
};
authInterceptor.post('/challenges', postData)
.then(response => {
console.log('Challenge accepted and saved:', response.data);
challenge.isAccepted = true;
}
authInterceptor
.post('/challenges', postData)
.then((response) => {
console.log('Challenge accepted and saved:', response.data)
challenge.isAccepted = true
})
.catch((error) => {
console.error('Failed to save challenge:', error)
})
.catch(error => {
console.error('Failed to save challenge:', error);
});
}
const closeModal = () => {
showModal.value = false;
showModal.value = false
}
</script>
......@@ -49,18 +49,18 @@ const goals = ref<Goal[]>([])
const goal = ref<Goal | null | undefined>(null)
onMounted(async () => {
await goalStore.getUserGoals();
await challengeStore.getUserChallenges();
challenges.value = challengeStore.challenges;
goals.value = goalStore.goals;
goal.value = goals.value[0];
console.log('Goals:', goals.value);
await goalStore.getUserGoals()
await challengeStore.getUserChallenges()
challenges.value = challengeStore.challenges
goals.value = goalStore.goals
goal.value = goals.value[0]
console.log('Goals:', goals.value)
const lastModalShow = localStorage.getItem('lastModalShow');
const lastModalShow = localStorage.getItem('lastModalShow')
if (!lastModalShow || Date.now() - Number(lastModalShow) >= 24 * 60 * 60 * 1000) {
showModal.value = true;
showModal.value = true
}
});
})
// Define your speech array
const speechArray = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment