point history
This commit is contained in:
parent
441f8f6a09
commit
22224c8003
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
<!-- Form -->
|
<!-- Form -->
|
||||||
<div class="w-full">
|
<div class="w-full">
|
||||||
|
<form @submit.prevent="login">
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<input
|
<input
|
||||||
v-model="username"
|
v-model="username"
|
||||||
@ -58,6 +59,7 @@
|
|||||||
REGISTER
|
REGISTER
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
<div class="p-4 flex justify-center">
|
<div class="p-4 flex justify-center">
|
||||||
<div class="bg-gradient-to-b from-gray-400 to-slate-500 rounded-2xl p-6 text-center w-full max-w-sm shadow-lg backdrop-blur-md animate-[pulse_3s_infinite]">
|
<div class="bg-gradient-to-b from-gray-400 to-slate-500 rounded-2xl p-6 text-center w-full max-w-sm shadow-lg backdrop-blur-md animate-[pulse_3s_infinite]">
|
||||||
<p class="text-md text-black font-bold">Total Poin </p>
|
<p class="text-md text-black font-bold">Total Poin </p>
|
||||||
<h2 class="text-4xl font-bold text-yellow-300">{{ totalPoints }}</h2>
|
<h2 class="text-4xl font-bold text-yellow-300">{{ myTotalPoint }}</h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -56,15 +56,15 @@
|
|||||||
class="flex justify-between items-center bg-white bg-opacity-15 backdrop-blur-md rounded-xl p-4 shadow hover:bg-opacity-25 transition-all"
|
class="flex justify-between items-center bg-white bg-opacity-15 backdrop-blur-md rounded-xl p-4 shadow hover:bg-opacity-25 transition-all"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<h3 class="font-semibold text-black">{{ entry.activity }} {{ index }}</h3>
|
<h3 class="font-semibold text-black">{{ entry.mission?.name || 'Unknown Mission'}} {{ index }}</h3>
|
||||||
<p class="text-sm text-black">{{ entry.source }}</p>
|
<p class="text-sm text-black">{{ entry.mission?.category }}</p>
|
||||||
<p class="text-xs text-black">{{ entry.date }}</p>
|
<p class="text-xs text-black">{{ entry.completed_at }}</p>
|
||||||
</div>
|
</div>
|
||||||
<span
|
<span
|
||||||
class="font-bold text-lg"
|
class="font-bold text-lg"
|
||||||
:class="entry.points > 0 ? 'text-orange-300' : 'text-red-300'"
|
:class="entry.points > 0 ? 'text-orange-300' : 'text-red-300'"
|
||||||
>
|
>
|
||||||
{{ entry.points > 0 ? '+' : '' }}{{ entry.points }}
|
{{ entry.points > 0 ? '+' : '' }}{{ entry.point }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</transition-group>
|
</transition-group>
|
||||||
@ -87,7 +87,10 @@ export default{
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from "vue";
|
import { ref, computed, onMounted } from "vue";
|
||||||
|
import { getUserPoint } from "@/services/missions";
|
||||||
|
|
||||||
|
const myTotalPoint = ref(0);
|
||||||
|
|
||||||
// Data contoh (bisa diganti dari backend)
|
// Data contoh (bisa diganti dari backend)
|
||||||
const pointHistory = ref([
|
const pointHistory = ref([
|
||||||
@ -103,17 +106,35 @@ const categories = ["Semua", "Game", "Content", "Manga", "Quiz", "Penalty"];
|
|||||||
const selectedCategory = ref("Semua");
|
const selectedCategory = ref("Semua");
|
||||||
|
|
||||||
// Hitung total poin
|
// Hitung total poin
|
||||||
const totalPoints = computed(() =>
|
// const totalPoints = computed(() =>
|
||||||
pointHistory.value.reduce((sum, e) => sum + e.points, 0)
|
// pointHistory.value.reduce((sum, e) => sum + e.points, 0)
|
||||||
);
|
// );
|
||||||
|
|
||||||
// Filter sesuai kategori
|
// Filter sesuai kategori
|
||||||
const filteredHistory = computed(() => {
|
const filteredHistory = computed(() => {
|
||||||
if (selectedCategory.value === "Semua") return pointHistory.value;
|
if (selectedCategory.value === "Semua") return pointHistory.value;
|
||||||
return pointHistory.value.filter(
|
return pointHistory.value.filter(
|
||||||
e => e.source.toLowerCase() === selectedCategory.value.toLowerCase()
|
e => e.category.toLowerCase() === selectedCategory.value.toLowerCase()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const totalPoints = computed(() =>
|
||||||
|
pointHistory.value.reduce((sum, e) => sum + e.point, 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
async function getHistory(){
|
||||||
|
const histories = await getUserPoint();
|
||||||
|
const myPointHistory = histories.myTask;
|
||||||
|
myTotalPoint.value =totalPoints //histories.myTaskCount
|
||||||
|
pointHistory.value = myPointHistory
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getHistory();
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@ -17,6 +17,7 @@ export const getMissions = async () => {
|
|||||||
...data,
|
...data,
|
||||||
count: activeMissions.length,
|
count: activeMissions.length,
|
||||||
results: activeMissions,
|
results: activeMissions,
|
||||||
|
allMissions: missions
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -45,22 +46,33 @@ export const updateMissionLog = async(missionId ,data = {}) =>{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const getUserPoint = async() =>{
|
export const getUserPoint = async() =>{
|
||||||
const auth = useAuthStore();
|
const auth = useAuthStore();
|
||||||
const user = auth.user
|
const user = auth.user
|
||||||
console.log(`User Data: ${JSON.stringify(user)}`)
|
const [missions, missionLogs] = await Promise.all([getMissions(), getMissionLogs()]);
|
||||||
|
const userLogs = missionLogs.results.filter((mlog) => mlog.user_id === user.id);
|
||||||
|
|
||||||
// getting points
|
const combine = userLogs.map(
|
||||||
const resPoint = await getMissionLogs();
|
log => {
|
||||||
console.log(`Missions Logs: ${JSON.stringify(resPoint)}`)
|
const missionDetail = missions.allMissions.find((mission) => mission.id === log.mission);
|
||||||
const userLogs = resPoint.results.filter((log) => log.user_id === user.id);
|
|
||||||
const myPoints = userLogs.reduce((total, log) => total + log.point, 0);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
task: resPoint,
|
...log,
|
||||||
taskCount: resPoint.count,
|
mission: missionDetail || null
|
||||||
myTask: userLogs,
|
}
|
||||||
myTaskCount: userLogs.length,
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const myPoints = combine.reduce((total, log) => total + log.point, 0);
|
||||||
|
const activeMissions = missions.activeMissions || [];
|
||||||
|
const taskCount = activeMissions.length;
|
||||||
|
|
||||||
|
return {
|
||||||
|
task: activeMissions,
|
||||||
|
taskCount: taskCount,
|
||||||
|
myTask: combine,
|
||||||
|
myTaskCount: combine.length,
|
||||||
myPoints,
|
myPoints,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user