Plan stuff. Log stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

4 years ago
  1. <script>
  2. import pluralize from "pluralize";
  3. import ModalFrame from "../components/ModalFrame";
  4. import SubGoalInput from "../components/SubGoalInput";
  5. import modal from "../stores/modal";
  6. import stufflog from "../stores/stufflog";
  7. export let period = {};
  8. let error = null;
  9. let activityId = "";
  10. let pointCount = "1000";
  11. function addPeriodGoal() {
  12. error = null;
  13. const parsedPointCount = parseInt(pointCount)
  14. if (Number.isNaN(parsedPointCount)) {
  15. error = "Point count must be a number.";
  16. return
  17. }
  18. if (parsedPointCount <= 0 || (parsedPointCount % 1000) !== 0) {
  19. error = "Point must be a positive non-zero multiple of 1000.";
  20. return
  21. }
  22. const addGoal = {
  23. activityId: activityId,
  24. pointCount: parsedPointCount,
  25. }
  26. stufflog.updatePeriod(period.id, {addGoal}).then(() => {
  27. modal.close();
  28. }).catch(err => {
  29. error = err.message || err;
  30. console.warn(err);
  31. });
  32. }
  33. $: if (activityId === "" && $stufflog.activities.length > 0) {
  34. activityId = $stufflog.activities[0].id;
  35. }
  36. </script>
  37. <ModalFrame title={`Add ${period.name} Goal`} error={error} closable on:close={() => modal.close()}>
  38. <form on:submit|preventDefault={() => addPeriodGoal()}>
  39. <label>Activity</label>
  40. <select bind:value={activityId}>
  41. {#each $stufflog.activities as activity (activity.id)}
  42. <option value={activity.id}>{activity.name}</option>
  43. {/each}
  44. </select>
  45. <label>Points</label>
  46. <input class="nolast" type="string" bind:value={pointCount} />
  47. <p>
  48. The amount of points must be in an increment of 1000, which should be
  49. equivalent to about an hour of baseline activity. Subgoal values are
  50. multipliers. 1.05 means that the 5% more points are added. 0.5 means
  51. the points are halved.
  52. </p>
  53. <hr />
  54. <button type="submit">Add Goal</button>
  55. </form>
  56. </ModalFrame>
  57. <style>
  58. p {
  59. margin-top: 1em;
  60. }
  61. </style>