Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20f69040e7 |
No files matched your search
@@ -1,2 +1,2 @@
|
|||||||
VUE_APP_SUPABASE_URL=https://ztsuribcieofaqwjeaip.supabase.co
|
VUE_APP_SUPABASE_URL=
|
||||||
VUE_APP_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTY0MDgzMTI1OCwiZXhwIjoxOTU2NDA3MjU4fQ.kDier2hhORx0lzhmTG3Mkkx06bTHoJfwRtVZwImwcAk
|
VUE_APP_SUPABASE_ANON_KEY=
|
||||||
@@ -4,7 +4,6 @@ node_modules
|
|||||||
|
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
.env
|
|
||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
|
|
||||||
|
|||||||
+6
-9
@@ -1,18 +1,15 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="">
|
<html lang="">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
|
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||||
<title>Activity Tracker</title>
|
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
<noscript>
|
||||||
<strong
|
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||||
>We're sorry but activity tracker doesn't work properly without
|
|
||||||
JavaScript enabled. Please enable it to continue.</strong
|
|
||||||
>
|
|
||||||
</noscript>
|
</noscript>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<!-- built files will be auto injected -->
|
<!-- built files will be auto injected -->
|
||||||
|
|||||||
+3
-19
@@ -1,38 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="appReady" class="min-h-full font-Poppins box-border">
|
<div>
|
||||||
<Navigation />
|
|
||||||
<router-view />
|
<router-view />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Navigation from "./components/Navigation.vue";
|
|
||||||
import { ref } from "vue";
|
|
||||||
import { supabase } from "./supabase/init";
|
|
||||||
import store from "./store/index";
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
|
||||||
Navigation,
|
|
||||||
},
|
|
||||||
setup() {
|
setup() {
|
||||||
// Create data / vars
|
// Create data / vars
|
||||||
const appReady = ref(null);
|
|
||||||
|
|
||||||
// Check to see if user is already logged in
|
// Check to see if user is already logged in
|
||||||
const user = supabase.auth.user();
|
|
||||||
|
|
||||||
// If user does not exist, need to make app ready
|
// If user does not exist, need to make app ready
|
||||||
if (!user) {
|
|
||||||
appReady.value = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Runs when there is a auth state change
|
// Runs when there is a auth state change
|
||||||
// if user is logged in, this will fire
|
// if user is logged in, this will fire
|
||||||
supabase.auth.onAuthStateChange((_, session) => {
|
|
||||||
store.methods.setUser(session);
|
return {};
|
||||||
appReady.value = true;
|
|
||||||
});
|
|
||||||
return { appReady };
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,55 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<header class="bg-at-light-green text-white">
|
<header></header>
|
||||||
<nav
|
|
||||||
class="container py-5 px-4 flex flex-col gap-4 items-center sm:flex-row"
|
|
||||||
>
|
|
||||||
<div class="flex items-center gap-x-4">
|
|
||||||
<img class="w-14" src="../assets/images/dumbbell-light.png" alt="" />
|
|
||||||
<h1 class="text-lg">Activity Tracker</h1>
|
|
||||||
</div>
|
|
||||||
<ul class="flex flex-1 justify-end gap-x-10">
|
|
||||||
<router-link class="cursor-pointer" :to="{ name: 'Home' }">
|
|
||||||
Home
|
|
||||||
</router-link>
|
|
||||||
<router-link
|
|
||||||
v-if="user"
|
|
||||||
class="cursor-pointer"
|
|
||||||
:to="{ name: 'Create' }"
|
|
||||||
>
|
|
||||||
Create
|
|
||||||
</router-link>
|
|
||||||
<router-link
|
|
||||||
v-if="!user"
|
|
||||||
class="cursor-pointer"
|
|
||||||
:to="{ name: 'Login' }"
|
|
||||||
>
|
|
||||||
Login
|
|
||||||
</router-link>
|
|
||||||
<li v-if="user" @click="logout" class="cursor-pointer">Logout</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { supabase } from "../supabase/init";
|
|
||||||
import { useRouter } from "vue-router";
|
|
||||||
import store from "../store/index";
|
|
||||||
import { computed } from "vue";
|
|
||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
// Get user from store
|
// Get user from store
|
||||||
const user = computed(() => store.state.user);
|
|
||||||
// Setup ref to router
|
// Setup ref to router
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
// Logout function
|
// Logout function
|
||||||
const logout = async () => {
|
|
||||||
await supabase.auth.signOut();
|
|
||||||
router.replace({ name: "Page" });
|
|
||||||
};
|
|
||||||
|
|
||||||
return { logout, user };
|
return {};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -1,56 +1,11 @@
|
|||||||
import { createRouter, createWebHistory } from "vue-router";
|
import { createRouter, createWebHistory } from "vue-router";
|
||||||
import { supabase } from "../supabase/init";
|
|
||||||
import Home from "../views/Home.vue";
|
import Home from "../views/Home.vue";
|
||||||
import Login from "../views/Login";
|
|
||||||
import Register from "../views/Register";
|
|
||||||
import Create from "../views/Create";
|
|
||||||
import ViewWorkout from "../views/ViewWorkout";
|
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
name: "Home",
|
name: "Home",
|
||||||
component: Home,
|
component: Home,
|
||||||
meta: {
|
|
||||||
title: "Home",
|
|
||||||
auth: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/login",
|
|
||||||
name: "Login",
|
|
||||||
component: Login,
|
|
||||||
meta: {
|
|
||||||
title: "Login",
|
|
||||||
auth: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/register",
|
|
||||||
name: "Register",
|
|
||||||
component: Register,
|
|
||||||
meta: {
|
|
||||||
title: "Register",
|
|
||||||
auth: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/create",
|
|
||||||
name: "Create",
|
|
||||||
component: Create,
|
|
||||||
meta: {
|
|
||||||
title: "Create",
|
|
||||||
auth: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/view-workout/:workoutId",
|
|
||||||
name: "View Workout",
|
|
||||||
component: ViewWorkout,
|
|
||||||
meta: {
|
|
||||||
title: "View Workout",
|
|
||||||
auth: false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -60,23 +15,7 @@ const router = createRouter({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Change document titles
|
// Change document titles
|
||||||
router.beforeEach((to, from, next) => {
|
|
||||||
document.title = `${to.meta.title} | Activity Tracker`;
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Route guard for auth routes
|
// Route guard for auth routes
|
||||||
router.beforeEach((to, from, next) => {
|
|
||||||
const user = supabase.auth.user();
|
|
||||||
if (to.matched.some((res) => res.meta.auth)) {
|
|
||||||
if (user) {
|
|
||||||
next();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
next({ name: "Login" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,16 +1 @@
|
|||||||
import { reactive } from "vue";
|
|
||||||
|
|
||||||
const state = reactive({
|
|
||||||
user: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const methods = {
|
|
||||||
setUser(payload) {
|
|
||||||
state.user = payload ? payload.user : null;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
|
||||||
state,
|
|
||||||
methods,
|
|
||||||
};
|
|
||||||
@@ -1,6 +1 @@
|
|||||||
import { createClient } from "@supabase/supabase-js";
|
|
||||||
|
|
||||||
const supabaseUrl = process.env.VUE_APP_SUPABASE_URL;
|
|
||||||
const supabaseAnonKey = process.env.VUE_APP_SUPABASE_ANON_KEY;
|
|
||||||
|
|
||||||
export const supabase = createClient(supabaseUrl, supabaseAnonKey);
|
|
||||||
+3
-321
@@ -1,340 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="max-w-screen-md mx-auto px-4 py-10">
|
<div></div>
|
||||||
<!-- Status Message -->
|
|
||||||
<div
|
|
||||||
v-if="statusMsg || errorMsg"
|
|
||||||
class="mb-10 p-4 bg-light-grey rounded-md shadow-lg"
|
|
||||||
>
|
|
||||||
<p class="text-at-light-green">{{ statusMsg }}</p>
|
|
||||||
<p class="text-red-500">{{ errorMsg }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Create -->
|
|
||||||
<div class="p-8 flex items-start bg-light-grey rounded-md shadow-lg">
|
|
||||||
<form
|
|
||||||
@submit.prevent="createWorkout"
|
|
||||||
class="flex flex-col gap-y-5 w-full"
|
|
||||||
>
|
|
||||||
<h1 class="text-2xl text-at-light-green">Record Workout</h1>
|
|
||||||
|
|
||||||
<!-- Workout Name -->
|
|
||||||
<div class="flex flex-col">
|
|
||||||
<label for="workout-name" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Workout Name
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
required
|
|
||||||
class="p-2 text-gray-500 focus:outline-none"
|
|
||||||
id="workout-name"
|
|
||||||
v-model="workoutName"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Workout Type -->
|
|
||||||
<div class="flex flex-col">
|
|
||||||
<label for="workout-type" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Workout Type
|
|
||||||
</label>
|
|
||||||
<select
|
|
||||||
required
|
|
||||||
@change="workoutChange"
|
|
||||||
class="p-2 text-gray-500 focus:outline-none"
|
|
||||||
id="workout-name"
|
|
||||||
v-model="workoutType"
|
|
||||||
>
|
|
||||||
<option value="select-workout">Select Workout</option>
|
|
||||||
<option value="strength">Strength Training</option>
|
|
||||||
<option value="cardio">Cardio</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Strength Training Inputs -->
|
|
||||||
<div v-if="workoutType === 'strength'" class="flex flex-col gap-y-4">
|
|
||||||
<div
|
|
||||||
class="flex flex-col gap-x-6 gap-y-2 relative md:flex-row"
|
|
||||||
v-for="(item, index) in exercises"
|
|
||||||
:key="index"
|
|
||||||
>
|
|
||||||
<div class="flex flex-col md:w-1/3">
|
|
||||||
<label
|
|
||||||
for="exercise-name"
|
|
||||||
class="mb-1 text-sm text-at-light-green"
|
|
||||||
>
|
|
||||||
Exercise
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
required
|
|
||||||
type="text"
|
|
||||||
id=""
|
|
||||||
class="p-2 w-full text-grey-500 focus:outline-none"
|
|
||||||
v-model="item.exercise"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col flex-1">
|
|
||||||
<label for="sets" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Sets
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
required
|
|
||||||
type="text"
|
|
||||||
id=""
|
|
||||||
class="p-2 w-full text-grey-500 focus:outline-none"
|
|
||||||
v-model="item.sets"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col flex-1">
|
|
||||||
<label for="reps" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Reps
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
required
|
|
||||||
type="text"
|
|
||||||
id=""
|
|
||||||
class="p-2 w-full text-grey-500 focus:outline-none"
|
|
||||||
v-model="item.reps"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col flex-1">
|
|
||||||
<label for="weight" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Weight (LB's)
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
required
|
|
||||||
type="text"
|
|
||||||
id=""
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
v-model="item.weight"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<img
|
|
||||||
@click="deleteExercise(item.id)"
|
|
||||||
src="@/assets/images/trash-light-green.png"
|
|
||||||
class="h-4 w-auto absolute -left-5 cursor-pointer"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
@click="addExercise"
|
|
||||||
type="button"
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-2
|
|
||||||
px-6
|
|
||||||
rounded-sm
|
|
||||||
self-start
|
|
||||||
text-sm text-white
|
|
||||||
bg-at-light-green
|
|
||||||
duration-200
|
|
||||||
border-solid border-2 border-transparent
|
|
||||||
hover:border-at-light-green
|
|
||||||
hover:bg-white
|
|
||||||
hover:text-at-light-green
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Add Exercises
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Cardio Inputs -->
|
|
||||||
<div v-if="workoutType === 'cardio'" class="flex flex-col gap-y-4">
|
|
||||||
<div
|
|
||||||
class="flex flex-col gap-x-6 gap-y-2 relative md:flex-row"
|
|
||||||
v-for="(item, index) in exercises"
|
|
||||||
:key="index"
|
|
||||||
>
|
|
||||||
<div class="flex flex-col md:w-1/3">
|
|
||||||
<label for="cardio-type" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Type
|
|
||||||
</label>
|
|
||||||
<select
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
id="cardio-type"
|
|
||||||
v-model="item.cardioType"
|
|
||||||
>
|
|
||||||
<option value="#">Select Type</option>
|
|
||||||
<option value="run">Run</option>
|
|
||||||
<option value="walk">Walk</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col flex-1">
|
|
||||||
<label for="distance" class="mb-1 text-sm text-at-light-green">
|
|
||||||
distance
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
required
|
|
||||||
type="text"
|
|
||||||
id=""
|
|
||||||
class="p-2 w-full text-grey-500 focus:outline-none"
|
|
||||||
v-model="item.distance"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col flex-1">
|
|
||||||
<label for="duration" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Duration
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
required
|
|
||||||
type="text"
|
|
||||||
id=""
|
|
||||||
class="p-2 w-full text-grey-500 focus:outline-none"
|
|
||||||
v-model="item.duration"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col flex-1">
|
|
||||||
<label for="pace" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Pace
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
required
|
|
||||||
type="text"
|
|
||||||
id=""
|
|
||||||
class="p-2 w-full text-grey-500 focus:outline-none"
|
|
||||||
v-model="item.pace"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<img
|
|
||||||
@click="deleteExercise(item.id)"
|
|
||||||
src="@/assets/images/trash-light-green.png"
|
|
||||||
class="h-4 w-auto absolute -left-5 cursor-pointer"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
@click="addExercise"
|
|
||||||
type="button"
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-2
|
|
||||||
px-6
|
|
||||||
rounded-sm
|
|
||||||
self-start
|
|
||||||
text-sm text-white
|
|
||||||
bg-at-light-green
|
|
||||||
duration-200
|
|
||||||
border-solid border-2 border-transparent
|
|
||||||
hover:border-at-light-green
|
|
||||||
hover:bg-white
|
|
||||||
hover:text-at-light-green
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Add Exercises
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-2
|
|
||||||
px-6
|
|
||||||
rounded-sm
|
|
||||||
self-start
|
|
||||||
text-sm text-white
|
|
||||||
bg-at-light-green
|
|
||||||
duration-200
|
|
||||||
border-solid border-2 border-transparent
|
|
||||||
hover:border-at-light-green hover:bg-white hover:text-at-light-green
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Record Workout
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref } from "vue";
|
|
||||||
import { uid } from "uid";
|
|
||||||
import { supabase } from "../supabase/init";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "create",
|
name: "create",
|
||||||
setup() {
|
setup() {
|
||||||
// Create data
|
// Create data
|
||||||
const workoutName = ref("");
|
|
||||||
const workoutType = ref("select-workout");
|
|
||||||
const exercises = ref([]);
|
|
||||||
const statusMsg = ref(null);
|
|
||||||
const errorMsg = ref(null);
|
|
||||||
// Add exercise
|
// Add exercise
|
||||||
const addExercise = () => {
|
|
||||||
if (workoutType.value === "strength") {
|
|
||||||
exercises.value.push({
|
|
||||||
id: uid(),
|
|
||||||
exercise: "",
|
|
||||||
sets: "",
|
|
||||||
reps: "",
|
|
||||||
weight: "",
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
exercises.value.push({
|
|
||||||
id: uid(),
|
|
||||||
cardioType: "",
|
|
||||||
distance: "",
|
|
||||||
duration: "",
|
|
||||||
pace: "",
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Delete exercise
|
// Delete exercise
|
||||||
const deleteExercise = (id) => {
|
|
||||||
if (exercises.value.length > 1) {
|
|
||||||
exercises.value = exercises.value.filter(
|
|
||||||
(exercise) => exercise.id !== id
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
errorMsg.value =
|
|
||||||
"Error: Cannot remove, need to have at least one exercise";
|
|
||||||
setTimeout(() => {
|
|
||||||
errorMsg.value = false;
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Listens for chaging of workout type input
|
// Listens for chaging of workout type input
|
||||||
const workoutChange = () => {
|
|
||||||
exercises.value = [];
|
|
||||||
addExercise();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create workout
|
// Create workout
|
||||||
const createWorkout = async () => {
|
|
||||||
try {
|
|
||||||
const { error } = await supabase.from("workouts").insert([
|
|
||||||
{
|
|
||||||
workoutName: workoutName.value,
|
|
||||||
workoutType: workoutType.value,
|
|
||||||
exercises: exercises.value,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
if (error) throw error;
|
|
||||||
statusMsg.value = "Success: Workout Created!";
|
|
||||||
workoutName.value = null;
|
|
||||||
workoutType.value = "select-workout";
|
|
||||||
exercises.value = [];
|
|
||||||
setTimeout(() => {
|
|
||||||
statusMsg.value = false;
|
|
||||||
}, 5000);
|
|
||||||
} catch (error) {
|
|
||||||
errorMsg.value = `Error: ${error.message};`;
|
|
||||||
setTimeout(() => {
|
|
||||||
errorMsg.value = false;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {};
|
||||||
workoutName,
|
|
||||||
workoutType,
|
|
||||||
exercises,
|
|
||||||
statusMsg,
|
|
||||||
errorMsg,
|
|
||||||
addExercise,
|
|
||||||
workoutChange,
|
|
||||||
deleteExercise,
|
|
||||||
createWorkout,
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
+3
-97
@@ -1,113 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="dataLoaded" class="container mt-10 px-4">
|
<div></div>
|
||||||
<!-- No Data -->
|
|
||||||
<div v-if="data.length === 0" class="w-full flex flex-col items-center">
|
|
||||||
<h1 class="text-2xl">Looks empty here...</h1>
|
|
||||||
<router-link
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-2
|
|
||||||
px-6
|
|
||||||
rounded-sm
|
|
||||||
text-sm text-white
|
|
||||||
bg-at-light-green
|
|
||||||
duration-200
|
|
||||||
border-solid border-2 border-transparent
|
|
||||||
hover:border-at-light-green hover:bg-white hover:text-at-light-green
|
|
||||||
"
|
|
||||||
:to="{ name: 'Create' }"
|
|
||||||
>Create Workout</router-link
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<!-- Data -->
|
|
||||||
<div
|
|
||||||
v-else
|
|
||||||
class="
|
|
||||||
grid grid-cols-1
|
|
||||||
sm:grid-cols-2
|
|
||||||
md:grid-cols-3
|
|
||||||
lg:grid-cols-4
|
|
||||||
gap-6
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<router-link
|
|
||||||
class="
|
|
||||||
flex flex-col
|
|
||||||
items-center
|
|
||||||
bg-light-grey
|
|
||||||
p-8
|
|
||||||
shadow-md
|
|
||||||
cursor-pointer
|
|
||||||
"
|
|
||||||
:to="{ name: 'View Workout', params: { workoutId: workout.id } }"
|
|
||||||
v-for="(workout, index) in data"
|
|
||||||
:key="index"
|
|
||||||
>
|
|
||||||
<!-- Cardio Img -->
|
|
||||||
<img
|
|
||||||
v-if="workout.workoutType === 'cardio'"
|
|
||||||
src="@/assets/images/running-light-green.png"
|
|
||||||
class="h-24 w-auto"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- Strength Training -->
|
|
||||||
<img
|
|
||||||
v-else
|
|
||||||
src="@/assets/images/dumbbell-light-green.png"
|
|
||||||
class="h-24 w-auto"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<p
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-1
|
|
||||||
px-3
|
|
||||||
text-xs text-white
|
|
||||||
bg-at-light-green
|
|
||||||
shadow-md
|
|
||||||
rounded-lg
|
|
||||||
"
|
|
||||||
>
|
|
||||||
{{ workout.workoutType }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h1 class="mt-8 mb-2 text-center text-xl text-at-light-green">
|
|
||||||
{{ workout.workoutName }}
|
|
||||||
</h1>
|
|
||||||
</router-link>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { supabase } from "../supabase/init";
|
|
||||||
import { ref } from "vue";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Home",
|
name: "Home",
|
||||||
components: {},
|
components: {},
|
||||||
setup() {
|
setup() {
|
||||||
// Create data / vars
|
// Create data / vars
|
||||||
const data = ref([]);
|
|
||||||
const dataLoaded = ref(null);
|
|
||||||
|
|
||||||
// Get data
|
// Get data
|
||||||
const getData = async () => {
|
|
||||||
try {
|
|
||||||
const { data: workouts, error } = await supabase
|
|
||||||
.from("workouts")
|
|
||||||
.select("*");
|
|
||||||
if (error) throw error;
|
|
||||||
data.value = workouts;
|
|
||||||
dataLoaded.value = true;
|
|
||||||
} catch (error) {
|
|
||||||
console.warn(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Run data function
|
// Run data function
|
||||||
getData();
|
|
||||||
return { data, dataLoaded };
|
return {};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
+2
-85
@@ -1,99 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="max-w-screen-sm mx-auto px-4 py-10">
|
<div></div>
|
||||||
<!-- Error Handling -->
|
|
||||||
<div v-if="errorMsg" class="mb-10 p-4 rounded-md bg-light-grey shadow-lg">
|
|
||||||
<p class="text-red-500">{{ errorMsg }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Login -->
|
|
||||||
<form
|
|
||||||
@submit.prevent="login"
|
|
||||||
action=""
|
|
||||||
class="p-8 flex flex-col bg-light-grey rounded-md shadow-lg"
|
|
||||||
>
|
|
||||||
<h1 class="text-3xl text-at-light-green mb-4">Login</h1>
|
|
||||||
<div class="flex flex-col mb-2">
|
|
||||||
<label for="email" class="mb-1 text-sm text-at-light-green"
|
|
||||||
>Email</label
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="email"
|
|
||||||
class="p-2 text-gray-500 focus:outline-none"
|
|
||||||
id="email"
|
|
||||||
v-model="email"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col mb-2">
|
|
||||||
<label for="password" class="mb-1 text-sm text-at-light-green"
|
|
||||||
>Password</label
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
class="p-2 text-gray-500 focus:outline-none"
|
|
||||||
id="password"
|
|
||||||
v-model="password"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-2
|
|
||||||
px-6
|
|
||||||
rounded-sm
|
|
||||||
self-start
|
|
||||||
text-sm text-white
|
|
||||||
bg-at-light-green
|
|
||||||
duration-200
|
|
||||||
border-solid border-2 border-transparent
|
|
||||||
hover:border-at-light-green hover:bg-white hover:text-at-light-green
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Login
|
|
||||||
</button>
|
|
||||||
<p class="text-sm mt-6 text-center">
|
|
||||||
Don't have an account?
|
|
||||||
<router-link :to="{ name: 'Register' }">
|
|
||||||
<span class="text-at-light-green">Register</span>
|
|
||||||
</router-link>
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref } from "vue";
|
|
||||||
import { supabase } from "../supabase/init";
|
|
||||||
import { useRouter } from "vue-router";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "login",
|
name: "login",
|
||||||
setup() {
|
setup() {
|
||||||
// Create data / vars
|
// Create data / vars
|
||||||
const email = ref(null);
|
|
||||||
const password = ref(null);
|
|
||||||
const errorMsg = ref(null);
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
// Login function
|
// Login function
|
||||||
const login = async () => {
|
|
||||||
try {
|
|
||||||
const { error } = await supabase.auth.signIn({
|
|
||||||
email: email.value,
|
|
||||||
password: password.value,
|
|
||||||
});
|
|
||||||
if (error) throw error;
|
|
||||||
router.replace({ name: "Home" });
|
|
||||||
} catch (error) {
|
|
||||||
errorMsg.value = `Error: ${error.message}`;
|
|
||||||
setTimeout(() => {
|
|
||||||
errorMsg.value = null;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return { email, password, errorMsg, login };
|
return {};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
+2
-104
@@ -1,118 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="max-w-screen-sm mx-auto px-4 py-10">
|
<div></div>
|
||||||
<!-- Error Handling -->
|
|
||||||
<div v-if="errorMsg" class="mb-10 p-4 rounded-md bg-light-grey shadow-lg">
|
|
||||||
<p class="text-red-500">{{ errorMsg }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Register -->
|
|
||||||
<form
|
|
||||||
@submit.prevent="register"
|
|
||||||
action=""
|
|
||||||
class="p-8 flex flex-col bg-light-grey rounded-md shadow-lg"
|
|
||||||
>
|
|
||||||
<h1 class="text-3xl text-at-light-green mb-4">Register</h1>
|
|
||||||
<div class="flex flex-col mb-2">
|
|
||||||
<label for="email" class="mb-1 text-sm text-at-light-green"
|
|
||||||
>Email</label
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="email"
|
|
||||||
class="p-2 text-gray-500 focus:outline-none"
|
|
||||||
id="email"
|
|
||||||
v-model="email"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col mb-2">
|
|
||||||
<label for="password" class="mb-1 text-sm text-at-light-green"
|
|
||||||
>Password</label
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
class="p-2 text-gray-500 focus:outline-none"
|
|
||||||
id="password"
|
|
||||||
v-model="password"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col mb-2">
|
|
||||||
<label for="confirmPassword" class="mb-1 text-sm text-at-light-green"
|
|
||||||
>Confirm Password</label
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
class="p-2 text-gray-500 focus:outline-none"
|
|
||||||
id="confirmPassword"
|
|
||||||
v-model="confirmPassword"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-2
|
|
||||||
px-6
|
|
||||||
rounded-sm
|
|
||||||
self-start
|
|
||||||
text-sm text-white
|
|
||||||
bg-at-light-green
|
|
||||||
duration-200
|
|
||||||
border-solid border-2 border-transparent
|
|
||||||
hover:border-at-light-green hover:bg-white hover:text-at-light-green
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Register
|
|
||||||
</button>
|
|
||||||
<p class="text-sm mt-6 text-center">
|
|
||||||
Already have an account?
|
|
||||||
<router-link :to="{ name: 'Login' }">
|
|
||||||
<span class="text-at-light-green">Login</span>
|
|
||||||
</router-link>
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref } from "vue";
|
|
||||||
import { supabase } from "../supabase/init";
|
|
||||||
import { useRouter } from "vue-router";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "register",
|
name: "register",
|
||||||
setup() {
|
setup() {
|
||||||
// Create data / vars
|
// Create data / vars
|
||||||
const email = ref(null);
|
|
||||||
const password = ref(null);
|
|
||||||
const confirmPassword = ref(null);
|
|
||||||
const errorMsg = ref(null);
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
// Register function
|
// Register function
|
||||||
const register = async () => {
|
|
||||||
if (password.value === confirmPassword.value) {
|
|
||||||
try {
|
|
||||||
const { error } = await supabase.auth.signUp({
|
|
||||||
email: email.value,
|
|
||||||
password: password.value,
|
|
||||||
});
|
|
||||||
if (error) throw error;
|
|
||||||
router.replace({ name: "Login" });
|
|
||||||
} catch (error) {
|
|
||||||
errorMsg.value = error.message;
|
|
||||||
setTimeout(() => {
|
|
||||||
errorMsg.value = null;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
errorMsg.value = "Error: passwords do not match";
|
|
||||||
setTimeout(() => {
|
|
||||||
errorMsg.value = null;
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
return { email, password, confirmPassword, errorMsg, register };
|
return {};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
+2
-444
@@ -1,470 +1,28 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="max-w-screen-sm mx-auto px-4 py-10">
|
<div></div>
|
||||||
<!-- App Message -->
|
|
||||||
<div
|
|
||||||
v-if="statusMsg || errorMsg"
|
|
||||||
class="mb-10 p-4 rounded-md shadow-md bg-light-grey"
|
|
||||||
>
|
|
||||||
<p class="text-at-light-green">{{ statusMsg }}</p>
|
|
||||||
<p class="text-red-500">{{ errorMsg }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="dataLoaded">
|
|
||||||
<!-- General Workout Info -->
|
|
||||||
<div
|
|
||||||
class="
|
|
||||||
flex flex-col
|
|
||||||
items-center
|
|
||||||
p-8
|
|
||||||
rounded-md
|
|
||||||
shadow-md
|
|
||||||
bg-light-grey
|
|
||||||
relative
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<div v-if="user" class="flex absolute left-2 top-2 gap-x-2">
|
|
||||||
<!-- Edit Mode -->
|
|
||||||
<div
|
|
||||||
class="
|
|
||||||
h-7
|
|
||||||
w-7
|
|
||||||
rounded-full
|
|
||||||
flex
|
|
||||||
justify-center
|
|
||||||
items-center
|
|
||||||
cursor-pointer
|
|
||||||
bg-at-light-green
|
|
||||||
shadow-lg
|
|
||||||
"
|
|
||||||
@click="editMode"
|
|
||||||
>
|
|
||||||
<img src="@/assets/images/pencil-light.png" class="h-3.5 w-auto" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Delete Mode -->
|
|
||||||
<div
|
|
||||||
class="
|
|
||||||
h-7
|
|
||||||
w-7
|
|
||||||
rounded-full
|
|
||||||
flex
|
|
||||||
justify-center
|
|
||||||
items-center
|
|
||||||
cursor-pointer
|
|
||||||
bg-at-light-green
|
|
||||||
shadow-lg
|
|
||||||
"
|
|
||||||
@click="deleteWorkout"
|
|
||||||
>
|
|
||||||
<img src="@/assets/images/trash-light.png" class="h-3.5 w-auto" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<img
|
|
||||||
v-if="data.workoutType === 'cardio'"
|
|
||||||
class="h-24 w-auto"
|
|
||||||
src="@/assets/images/running-light-green.png"
|
|
||||||
alt=""
|
|
||||||
/>
|
|
||||||
<img
|
|
||||||
v-else
|
|
||||||
class="h-24 w-auto"
|
|
||||||
src="@/assets/images/dumbbell-light-green.png"
|
|
||||||
alt=""
|
|
||||||
/>
|
|
||||||
|
|
||||||
<span
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-1.5
|
|
||||||
px-5
|
|
||||||
text-xs text-white
|
|
||||||
bg-at-light-green
|
|
||||||
rounded-lg
|
|
||||||
shadow-md
|
|
||||||
"
|
|
||||||
>
|
|
||||||
{{ data.workoutType }}
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<div class="w-full mt-6">
|
|
||||||
<input
|
|
||||||
v-if="edit"
|
|
||||||
type="text"
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
v-model="data.workoutName"
|
|
||||||
/>
|
|
||||||
<h1 v-else class="text-at-light-green text-2xl text-center">
|
|
||||||
{{ data.workoutName }}
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Exercises -->
|
|
||||||
<div
|
|
||||||
class="
|
|
||||||
mt-10
|
|
||||||
p-8
|
|
||||||
rounded-md
|
|
||||||
flex flex-col
|
|
||||||
items-center
|
|
||||||
bg-light-grey
|
|
||||||
shadow-md
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<!-- Strength Training -->
|
|
||||||
<div
|
|
||||||
v-if="data.workoutType === 'strength'"
|
|
||||||
class="flex flex-col gap-y-4 w-full"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="flex flex-col gap-x-6 gap-y-2 relative sm:flex-row"
|
|
||||||
v-for="(item, index) in data.exercises"
|
|
||||||
:key="index"
|
|
||||||
>
|
|
||||||
<div class="flex flex-2 flex-col md:w-1/3">
|
|
||||||
<label
|
|
||||||
for="exercise-name"
|
|
||||||
class="mb-1 text-sm text-at-light-green"
|
|
||||||
>
|
|
||||||
Exercise
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
v-if="edit"
|
|
||||||
id="exercise-name"
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
type="text"
|
|
||||||
v-model="item.exercise"
|
|
||||||
/>
|
|
||||||
<p v-else>{{ item.exercise }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-1 flex-col">
|
|
||||||
<label for="sets" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Sets
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
v-if="edit"
|
|
||||||
id="sets"
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
type="text"
|
|
||||||
v-model="item.sets"
|
|
||||||
/>
|
|
||||||
<p v-else>{{ item.sets }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-1 flex-col">
|
|
||||||
<label for="reps" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Reps
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
v-if="edit"
|
|
||||||
id="reps"
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
type="text"
|
|
||||||
v-model="item.reps"
|
|
||||||
/>
|
|
||||||
<p v-else>{{ item.reps }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-1 flex-col">
|
|
||||||
<label for="weight" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Weight (LB's)
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
v-if="edit"
|
|
||||||
id="weight"
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
type="text"
|
|
||||||
v-model="item.weight"
|
|
||||||
/>
|
|
||||||
<p v-else>{{ item.weight }}</p>
|
|
||||||
</div>
|
|
||||||
<img
|
|
||||||
v-if="edit"
|
|
||||||
@click="deleteExercise(item.id)"
|
|
||||||
src="@/assets/images/trash-light-green.png"
|
|
||||||
class="absolute h-4 w-auto -left-5 cursor-pointer"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
v-if="edit"
|
|
||||||
@click="addExercise"
|
|
||||||
type="button"
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-2
|
|
||||||
px-6
|
|
||||||
rounded-sm
|
|
||||||
self-start
|
|
||||||
text-sm text-white
|
|
||||||
bg-at-light-green
|
|
||||||
duration-200
|
|
||||||
border-solid border-2 border-transparent
|
|
||||||
hover:border-at-light-green
|
|
||||||
hover:bg-white
|
|
||||||
hover:text-at-light-green
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Add Exercise
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Cardio Training -->
|
|
||||||
<div v-else class="flex flex-col gap-y-4 w-full">
|
|
||||||
<div
|
|
||||||
class="flex flex-col gap-x-6 gap-y-2 relative sm:flex-row"
|
|
||||||
v-for="(item, index) in data.exercises"
|
|
||||||
:key="index"
|
|
||||||
>
|
|
||||||
<div class="flex flex-2 flex-col md:w-1/3">
|
|
||||||
<label for="cardio-type" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Type
|
|
||||||
</label>
|
|
||||||
<select
|
|
||||||
v-if="edit"
|
|
||||||
id="cardio-type"
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
type="text"
|
|
||||||
v-model="item.cardioType"
|
|
||||||
>
|
|
||||||
<option value="#">Select Type</option>
|
|
||||||
<option value="run">Run</option>
|
|
||||||
<option value="walk">Walk</option>
|
|
||||||
</select>
|
|
||||||
<p v-else>{{ item.cardioType }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-1 flex-col">
|
|
||||||
<label for="distance" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Distance
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
v-if="edit"
|
|
||||||
id="distance"
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
type="text"
|
|
||||||
v-model="item.distance"
|
|
||||||
/>
|
|
||||||
<p v-else>{{ item.distance }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-1 flex-col">
|
|
||||||
<label for="duration" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Duration
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
v-if="edit"
|
|
||||||
id="duration"
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
type="text"
|
|
||||||
v-model="item.duration"
|
|
||||||
/>
|
|
||||||
<p v-else>{{ item.duration }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-1 flex-col">
|
|
||||||
<label for="pace" class="mb-1 text-sm text-at-light-green">
|
|
||||||
Pace
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
v-if="edit"
|
|
||||||
id="pace"
|
|
||||||
class="p-2 w-full text-gray-500 focus:outline-none"
|
|
||||||
type="text"
|
|
||||||
v-model="item.pace"
|
|
||||||
/>
|
|
||||||
<p v-else>{{ item.pace }}</p>
|
|
||||||
</div>
|
|
||||||
<img
|
|
||||||
v-if="edit"
|
|
||||||
@click="deleteExercise(item.id)"
|
|
||||||
src="@/assets/images/trash-light-green.png"
|
|
||||||
class="absolute h-4 w-auto -left-5 cursor-pointer"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
v-if="edit"
|
|
||||||
@click="addExercise"
|
|
||||||
type="button"
|
|
||||||
class="
|
|
||||||
mt-6
|
|
||||||
py-2
|
|
||||||
px-6
|
|
||||||
rounded-sm
|
|
||||||
self-start
|
|
||||||
text-sm text-white
|
|
||||||
bg-at-light-green
|
|
||||||
duration-200
|
|
||||||
border-solid border-2 border-transparent
|
|
||||||
hover:border-at-light-green
|
|
||||||
hover:bg-white
|
|
||||||
hover:text-at-light-green
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Add Exercise
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Update -->
|
|
||||||
<button
|
|
||||||
v-if="edit"
|
|
||||||
@click="update"
|
|
||||||
type="button"
|
|
||||||
class="
|
|
||||||
mt-10
|
|
||||||
py-2
|
|
||||||
px-6
|
|
||||||
rounded-sm
|
|
||||||
self-start
|
|
||||||
text-sm text-white
|
|
||||||
bg-at-light-green
|
|
||||||
duration-200
|
|
||||||
border-solid border-2 border-transparent
|
|
||||||
hover:border-at-light-green hover:bg-white hover:text-at-light-green
|
|
||||||
"
|
|
||||||
>
|
|
||||||
Update Workout
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, computed } from "vue";
|
|
||||||
import { supabase } from "../supabase/init";
|
|
||||||
import { useRoute, useRouter } from "vue-router";
|
|
||||||
import store from "../store/index";
|
|
||||||
import { uid } from "uid";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "view-workout",
|
name: "view-workout",
|
||||||
setup() {
|
setup() {
|
||||||
// Create data / vars
|
// Create data / vars
|
||||||
const data = ref(null);
|
|
||||||
const dataLoaded = ref(null);
|
|
||||||
const errorMsg = ref(null);
|
|
||||||
const statusMsg = ref(null);
|
|
||||||
const route = useRoute();
|
|
||||||
const user = computed(() => store.state.user);
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
// Get current Id of route
|
// Get current Id of route
|
||||||
const currentId = route.params.workoutId;
|
|
||||||
|
|
||||||
// Get workout data
|
// Get workout data
|
||||||
const getData = async () => {
|
|
||||||
try {
|
|
||||||
const { data: workouts, error } = await supabase
|
|
||||||
.from("workouts")
|
|
||||||
.select("*")
|
|
||||||
.eq("id", currentId);
|
|
||||||
if (error) throw error;
|
|
||||||
data.value = workouts[0];
|
|
||||||
dataLoaded.value = true;
|
|
||||||
} catch (error) {
|
|
||||||
errorMsg.value = error.message;
|
|
||||||
setTimeout(() => {
|
|
||||||
errorMsg.value = false;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
getData();
|
|
||||||
|
|
||||||
// Delete workout
|
// Delete workout
|
||||||
|
|
||||||
const deleteWorkout = async () => {
|
|
||||||
try {
|
|
||||||
const { error } = await supabase
|
|
||||||
.from("workout")
|
|
||||||
.delete()
|
|
||||||
.eq("id", currentId);
|
|
||||||
if (error) throw error;
|
|
||||||
router.replace({ name: "Home" });
|
|
||||||
} catch (error) {
|
|
||||||
errorMsg.value = `Error: ${error.message}`;
|
|
||||||
setTimeout(() => {
|
|
||||||
errorMsg.value = false;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Edit mode
|
// Edit mode
|
||||||
const edit = ref(null);
|
|
||||||
|
|
||||||
const editMode = () => {
|
|
||||||
edit.value = !edit.value;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add exercise
|
// Add exercise
|
||||||
const addExercise = () => {
|
|
||||||
if (data.value.workoutType === "strength") {
|
|
||||||
data.value.exercise.push({
|
|
||||||
id: uid(),
|
|
||||||
exercise: "",
|
|
||||||
sets: "",
|
|
||||||
reps: "",
|
|
||||||
weight: "",
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
data.value.exercises.push({
|
|
||||||
id: uid(),
|
|
||||||
cardioType: "",
|
|
||||||
distance: "",
|
|
||||||
duration: "",
|
|
||||||
pace: "",
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Delete exercise
|
// Delete exercise
|
||||||
const deleteExercise = (id) => {
|
|
||||||
if (data.value.exercises.length > 1) {
|
|
||||||
data.value.exercises = data.value.exercises.filter(
|
|
||||||
(exercise) => exercise.id !== id
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
errorMsg.value =
|
|
||||||
"Error: Cannot remove, need to have at least one exercise";
|
|
||||||
setTimeout(() => {
|
|
||||||
errorMsg.value = false;
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Update Workout
|
// Update Workout
|
||||||
const update = async () => {
|
|
||||||
try {
|
|
||||||
const { error } = await supabase
|
|
||||||
.from("workouts")
|
|
||||||
.update({
|
|
||||||
workoutName: data.value.workoutName,
|
|
||||||
exercises: data.value.exercises,
|
|
||||||
})
|
|
||||||
.eq("id", currentId);
|
|
||||||
if (error) throw error;
|
|
||||||
edit.value = false;
|
|
||||||
statusMsg.value = "Success: Workout Updated!";
|
|
||||||
setTimeout(() => {
|
|
||||||
statusMsg.value = false;
|
|
||||||
}, 5000);
|
|
||||||
} catch (error) {
|
|
||||||
errorMsg.value = `Error: ${error.message}`;
|
|
||||||
setTimeout(() => {
|
|
||||||
errorMsg.value = false;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {};
|
||||||
statusMsg,
|
|
||||||
data,
|
|
||||||
dataLoaded,
|
|
||||||
errorMsg,
|
|
||||||
edit,
|
|
||||||
editMode,
|
|
||||||
user,
|
|
||||||
deleteWorkout,
|
|
||||||
addExercise,
|
|
||||||
deleteExercise,
|
|
||||||
update,
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
Reference in new issue
Block a user