Skip to content

Commit

Permalink
refactor: converted the remaining components to typescript (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed May 1, 2024
1 parent 855f06e commit 3ae4060
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/components/CategoryEditModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ b-modal(id="edit" ref="edit" title="Edit category" @show="resetModal" @hidden="h
| Inherit parent color
div.mt-1(v-show="!editing.inherit_color")
color-picker(v-model="editing.color")

hr
div.my-1
b Productivity score
Expand All @@ -50,9 +50,9 @@ b-modal(id="edit" ref="edit" title="Edit category" @show="resetModal" @hidden="h
| Remove category
</template>

<script>
<script lang="ts">
import _ from 'lodash';
import ColorPicker from '~/components/ColorPicker';
import ColorPicker from '~/components/ColorPicker.vue';
import { useCategoryStore } from '~/stores/categories';
import { mapState } from 'pinia';
import { validateRegex, isRegexBroad } from '~/util/validate';
Expand Down
2 changes: 1 addition & 1 deletion src/components/CategoryEditTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ div
CategoryEditModal(:categoryId='editingId', @hidden="hideEditModal()")
</template>

<script>
<script lang="ts">
import 'vue-awesome/icons/regular/plus-square';
import 'vue-awesome/icons/regular/minus-square';
import 'vue-awesome/icons/circle';
Expand Down
2 changes: 1 addition & 1 deletion src/components/ColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ div
}
</style>

<script>
<script lang="ts">
// Based on https://codepen.io/Brownsugar/pen/NaGPKy
import 'vue-awesome/icons/sync';
Expand Down
2 changes: 1 addition & 1 deletion src/components/DevOnly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ div(v-if="show", style="border: 1px solid #aaa; border-radius: 5px")
slot
</template>

<script>
<script lang="ts">
export default {
props: {
note: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ErrorBoundary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ div
slot
</template>

<script>
<script lang="ts">
// Based on: https://medium.com/@dillonchanis/handling-errors-in-vue-with-error-boundaries-91f6ead0093b
export default {
name: 'ErrorBoundary',
Expand Down
2 changes: 1 addition & 1 deletion src/components/EventEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ b-modal(v-if="event && event.id", :id="'edit-modal-' + event.id", ref="eventEdit

<style lang="scss"></style>

<script>
<script lang="ts">
// This EventEditor can be used to edit events in a specific bucket.
//
// It is used in:
Expand Down
2 changes: 1 addition & 1 deletion src/components/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ div.container(style="color: #555; font-size: 0.9em")
| Donate
</template>

<script>
<script lang="ts">
// only import the icons you use to reduce bundle size
import 'vue-awesome/icons/brands/twitter';
import 'vue-awesome/icons/brands/github';
Expand Down
15 changes: 8 additions & 7 deletions src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ div(:class="{'fixed-top-padding': fixedTopMenu}")
}
</style>

<script>
<script lang="ts">
// only import the icons you use to reduce bundle size
import 'vue-awesome/icons/calendar-day';
import 'vue-awesome/icons/calendar-week';
Expand Down Expand Up @@ -125,6 +125,7 @@ import _ from 'lodash';
import { mapState } from 'pinia';
import { useSettingsStore } from '~/stores/settings';
import { useBucketsStore } from '~/stores/buckets';
import { IBucket } from '~/util/interfaces';
export default {
name: 'Header',
Expand All @@ -141,18 +142,18 @@ export default {
mounted: async function () {
const bucketStore = useBucketsStore();
await bucketStore.ensureLoaded();
const buckets = bucketStore.buckets;
const buckets: IBucket[] = bucketStore.buckets;
const types_by_host = {};
const activityViews = [];
// TODO: Change to use same bucket detection logic as get_buckets/set_available in store/modules/activity.ts
_.each(buckets, v => {
types_by_host[v.hostname] = types_by_host[v.hostname] || {};
// The '&& true;' is just to typecoerce into booleans
types_by_host[v.hostname].afk |= v.type == 'afkstatus';
types_by_host[v.hostname].window |= v.type == 'currentwindow';
types_by_host[v.hostname].android |= v.type == 'currentwindow' && v.id.includes('android'); // Use other bucket type ID in the future
types_by_host[v.hostname].afk ||= v.type == 'afkstatus';
types_by_host[v.hostname].window ||= v.type == 'currentwindow';
// TODO: Use other bucket type ID in the future
types_by_host[v.hostname].android ||= v.type == 'currentwindow' && v.id.includes('android');
});
//console.log(types_by_host);
Expand All @@ -166,7 +167,7 @@ export default {
icon: 'desktop',
});
}
if (types.android) {
if (types['android']) {
activityViews.push({
name: `${hostname} (Android)`,
hostname: hostname,
Expand Down
2 changes: 1 addition & 1 deletion src/components/InputTimeInterval.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ div

<style scoped lang="scss"></style>

<script>
<script lang="ts">
import moment from 'moment';
import 'vue-awesome/icons/sync';
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/components/NewReleaseNotification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
button(type="button", class="close", @click="isFollowUpVisible=false") &times;
</template>

<script>
<script lang="ts">
import axios from 'axios';
import moment from 'moment';
import semver from 'semver';
Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectableEventView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ div
pre {{ events }}
</template>

<script>
<script lang="ts">
export default {
name: 'aw-selectable-eventview',
props: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectableVisualization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ div
}
</style>

<script>
<script lang="ts">
import _ from 'lodash';
import 'vue-awesome/icons/cog';
import 'vue-awesome/icons/times';
Expand Down
4 changes: 2 additions & 2 deletions src/components/StopwatchEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ div
}
</style>

<script>
<script lang="ts">
import moment from 'moment';
import 'vue-awesome/icons/edit';
import 'vue-awesome/icons/stop';
Expand All @@ -54,7 +54,7 @@ export default {
stop: async function () {
const new_event = JSON.parse(JSON.stringify(this.event));
new_event.data.running = false;
new_event.duration = (moment() - moment(new_event.timestamp)) / 1000;
new_event.duration = moment().diff(moment(new_event.timestamp)) / 1000;
await this.$aw.replaceEvent(this.bucket_id, new_event);
this.$emit('update', new_event);
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/UncategorizedNotification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ div
| You can address this by using the #[router-link(:to="{ path: '/settings/category-builder' }") Category Builder].
</template>

<script>
<script lang="ts">
import { mapState } from 'pinia';
import { useActivityStore } from '~/stores/activity';
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserSatisfactionPoll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ul {
}
</style>

<script>
<script lang="ts">
import { range } from 'lodash/fp';
import moment from 'moment';
Expand Down
2 changes: 1 addition & 1 deletion src/visualizations/CategoryTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ div(style="font-size: 0.9em")
}
</style>

<script>
<script lang="ts">
import 'vue-awesome/icons/circle';
import 'vue-awesome/icons/regular/plus-square';
import 'vue-awesome/icons/regular/minus-square';
Expand Down
2 changes: 1 addition & 1 deletion src/visualizations/EventList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ $border-color: #ddd;
}
</style>

<script>
<script lang="ts">
import 'vue-awesome/icons/edit';
import 'vue-awesome/icons/tags';
import 'vue-awesome/icons/clock';
Expand Down
2 changes: 1 addition & 1 deletion src/visualizations/PeriodUsage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ svg {
}
</style>

<script>
<script lang="ts">
// NOTE: This is just a Vue.js component wrapper for periodusage.js
// Code should generally go in the framework-independent file.
Expand Down
9 changes: 5 additions & 4 deletions src/visualizations/Score.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,30 @@ div
| {{ (Math.round(cat.data.$total_score * 10) / 10).toFixed(1) }}
</template>

<script>
<script lang="ts">
import _ from 'lodash';
import { useActivityStore } from '~/stores/activity';
import { IEvent } from '~/util/interfaces';
// TODO: Maybe add a "Category Tree"-style visualization?
export default {
name: 'aw-score',
computed: {
categories_with_score: function () {
categories_with_score: function (): IEvent[] {
// FIXME: Does this get all category time? Or just top ones?
const top_categories = useActivityStore().category.top;
return _.map(top_categories, cat => {
cat.data.$total_score = (cat.duration / (60 * 60)) * cat.data.$score;
return cat;
});
},
score: function () {
score: function (): number {
return _.sum(_.map(this.categories_with_score, cat => cat.data.$total_score));
},
score_productive_percent() {
// Compute the percentage of time spent on productive activities (score > 0)
const total_time = _.sumBy(this.categories_with_score, cat => cat.duration);
const total_time = _.sumBy(this.categories_with_score as IEvent[], cat => cat.duration);
const productive_time = _.sumBy(
_.filter(this.categories_with_score, cat => cat.data.$total_score > 0),
cat => cat.duration
Expand Down
2 changes: 1 addition & 1 deletion src/visualizations/Summary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ div
}
</style>

<script>
<script lang="ts">
// NOTE: This is just a Vue.js component wrapper for summary.ts
// Code should generally go in the framework-independent file.
Expand Down
2 changes: 1 addition & 1 deletion src/visualizations/SunburstCategories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sunburst(:data="data", :colorScale="colorfunc", :getCategoryForColor="categoryFo
//breadcrumbTrail(slot="legend" slot-scope="{ nodes, colorGetter, width }" :current="nodes.mouseOver" :root="nodes.root" :colorGetter="colorGetter" :from="nodes.clicked" :width="width" :item-width="100" :order="0")
</template>

<script>
<script lang="ts">
import {
breadcrumbTrail,
highlightOnHover,
Expand Down
2 changes: 1 addition & 1 deletion src/visualizations/TimelineInspect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ svg {
}
</style>

<script>
<script lang="ts">
// NOTE: This is just a Vue.js component wrapper for timeline.js
// Code should generally go in the framework-independent file.
Expand Down
2 changes: 1 addition & 1 deletion src/visualizations/TimelineSimple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ svg {
}
</style>

<script>
<script lang="ts">
// NOTE: This is just a Vue.js component wrapper for timeline-simple.js
// Code should generally go in the framework-independent file.
Expand Down

1 comment on commit 3ae4060

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are screenshots of this commit:

Screenshots using aw-server v0.12.3b11 (click to expand)

Screenshots using aw-server-rust master (click to expand)

Screenshots using aw-server-rust v0.12.3b11 (click to expand)

Please sign in to comment.