Skip to content

Commit

Permalink
feat: tack unfinished session and reflect on sessions list page (#108)
Browse files Browse the repository at this point in the history
feat: tack unfinish session and reflect on sessions list page
  • Loading branch information
wajeht authored Jul 22, 2022
1 parent de9fa6a commit 31c84bd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/apps/api/v1/sessions/sessions.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ export async function postCreateSession(req, res) {
export async function patchSession(req, res) {
const body = req.body;
const sid = req.params.sid;
const uid = req.body.user_id;

const fields = ['id', 'user_id'];
const b = omit(body, ...fields);

const updated = await SessionQueries.updateSession(sid, req.body.user_id, b);
const updated = await SessionQueries.updateSession(sid, uid, b);

logger.info(`User id ${req.body.user_id} has updated session details to ${JSON.stringify(b)}!`);

Expand Down
1 change: 1 addition & 0 deletions src/apps/api/v1/sessions/sessions.queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function getSessionBySessionId(sid) {
s.session_id,
e.id,
gm.id
order by e.id desc
`,
[sid, sid],
);
Expand Down
11 changes: 11 additions & 0 deletions src/apps/api/v1/sessions/sessions.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ export const patchSession = [
.trim()
.isFloat()
.withMessage('caffeine_intake must be an integer format!'),
body('json')
.optional()
.trim()
.custom((json) => {
try {
JSON.stringify(json);
return true;
} catch (e) {
throw new Error('json must be json format');
}
}),
body('notes')
.optional()
.trim()
Expand Down
23 changes: 19 additions & 4 deletions src/apps/ui/components/dashboard/SessionDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,13 @@ async function handleAddASet() {
}
}
currentSessionDetails.logs[addASetExerciseIndex.value].sets.push(setData);
// if .logs not available, we push to .json
if (currentSessionDetails.logs?.length === 0) {
currentSessionDetails.json[addASetExerciseIndex.value].sets.push(setData);
} else {
currentSessionDetails.logs[addASetExerciseIndex.value].sets.push(setData);
}
addASetLoading.value = false;
clearDataAndDismissAddASetModal();
Expand Down Expand Up @@ -324,6 +330,7 @@ async function handleCompleteCurrentSession() {
const body = {
end_date: gainsCurrentDateTime(),
user_id: userStore.user.id,
json: JSON.stringify(currentSessionDetails.logs),
};
loading.value = true;
Expand Down Expand Up @@ -542,7 +549,12 @@ async function handleDeleteSession() {
</div>
<!-- exercise logs -->
<div v-for="(log, index) in currentSessionDetails.logs" class="card p-0">
<div
v-for="(log, index) in currentSessionDetails.logs?.length != 0
? currentSessionDetails.logs
: currentSessionDetails.json"
class="card p-0"
>
<!-- individual exercises log -->
<div class="card-body">
<!-- header -->
Expand Down Expand Up @@ -613,7 +625,7 @@ async function handleDeleteSession() {
</thead>
<tbody>
<tr v-for="(s, idx) in log.sets">
<th class="text-center">{{ idx + 1 }}</th>
<td class="text-center">{{ idx + 1 }}</td>
<td class="text-center">x</td>
<td class="text-center">{{ s.reps }}</td>
<td class="text-center">x</td>
Expand Down Expand Up @@ -642,6 +654,7 @@ async function handleDeleteSession() {
<!-- left -->
<span class="d-flex justify-content-between gap-2">
<!-- add a set model button -->
<span>
<button
@click="(addASetExerciseId = log.exercise_id), (addASetExerciseIndex = index)"
Expand Down Expand Up @@ -809,7 +822,9 @@ async function handleDeleteSession() {
@click="handleCompleteCurrentSession()"
type="button"
class="btn btn-success"
:disabled="loading || !currentSessionDetails.logs?.length"
:disabled="
loading || (!currentSessionDetails.logs?.length && addASetExerciseId == null)
"
>
<div v-if="loading" class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">Loading...</span>
Expand Down
12 changes: 6 additions & 6 deletions src/apps/ui/pages/dashboard/sessions/Sessions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ function logDetails(sid) {
<!-- middle -->
<div class="flex-grow-1">
<h5 class="card-title">{{ session.name }}</h5>

<div class="card-text">
<ul class="list-unstyled mb-0 pb-0">
<li>close grip bench press</li>
<li>conventional deadlift</li>
<li>high bar squat</li>
<li>overhead shoulder press</li>
</ul>
<small>
<ul class="list-unstyled mb-0 pb-0 list-group-numbered">
<li v-for="log in session.json">{{ log.name }}</li>
</ul>
</small>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/database/migrations/20220718015611_sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function up(knex) {
caffeine_intake INT DEFAULT NULL,
calories_prior_session INT DEFAULT NULL,
session_rpe INT DEFAULT NULL,
json jsonb,
json jsonb DEFAULT NULL,
deleted BOOLEAN DEFAULT FALSE,
notes VARCHAR(1000) DEFAULT NULL,
user_id INT REFERENCES users on DELETE CASCADE NOT NULL,
Expand Down

0 comments on commit 31c84bd

Please sign in to comment.