Skip to content

Commit

Permalink
[#1936] Migrate c-segment.vue to typescript (#2035)
Browse files Browse the repository at this point in the history
Currently, there is still some JavaScript code which remains 
unmigrated. This allows for type unsafe code to be written, 
potentially resulting in unintended behavior.

Let's migrate the rest of the JavaScript code to TypeScript 
code to facilitate future changes to the code.
  • Loading branch information
jq1836 committed Sep 30, 2023
1 parent 0c80ee6 commit 46409aa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions frontend/src/components/c-segment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
)
</template>

<script>
<script lang='ts'>
import { defineComponent } from 'vue';
import { mapState } from 'vuex';
import Segment from '../utils/segment';
import { StoreState } from '../types/vuex.d';
export default {
export default defineComponent({
name: 'c-segment',
props: {
segment: {
Expand All @@ -49,22 +51,22 @@ export default {
},
data() {
return {
isOpen: this.segment.knownAuthor || this.segment.lines.length < 5,
canOpen: !this.segment.knownAuthor && this.segment.lines.length > 4,
transparencyValue: '30',
isOpen: (this.segment.knownAuthor !== null) || this.segment.lines.length < 5 as boolean,
canOpen: (this.segment.knownAuthor === null) && this.segment.lines.length > 4 as boolean,
transparencyValue: '30' as string,
};
},
computed: {
...mapState({
authorColors: ['tabAuthorColors'],
authorColors: (state: unknown) => (state as StoreState).tabAuthorColors,
}),
},
methods: {
toggleCode() {
this.isOpen = !this.isOpen;
},
},
};
});
</script>

<style lang="css">
Expand Down

0 comments on commit 46409aa

Please sign in to comment.