Skip to content

Commit

Permalink
refactor: prefer 'useTemplateRef' over generic 'ref' (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasan1999 authored Sep 14, 2024
1 parent 2d5cdaf commit 45d8e4c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions client/src/components/main/Main.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import Navbar from '@/components/main/navbar/Navbar.vue';
import mainSections from '@/components/main/mainSections';
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { computed, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue';
import router from '@/router';
import AboutMyself from '@/components/main/about-myself/AboutMyself.vue';
import Projects from '@/components/main/projects/Projects.vue';
Expand Down Expand Up @@ -49,7 +49,7 @@
const navigatingTo = ref<string | undefined>();
const root = ref<HTMLDivElement | null>(null);
const root = useTemplateRef('root');
const sectionElements = ref<Record<string, HTMLDivElement>>({});
Expand Down
5 changes: 1 addition & 4 deletions client/src/components/main/MainSection.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { computed } from 'vue';
import mainSections from '@/components/main/mainSections';
import { MainSectionProps } from '@/components/main/types';
const props = withDefaults(defineProps<MainSectionProps>(), { heading: false });
const root = ref<HTMLDivElement | null>(null);
const activeSection = computed(() => mainSections[props.name]);
const id = computed(() => activeSection.value.id);
Expand All @@ -18,7 +16,6 @@
<section
class="main-section"
:id="id"
ref="root"
>
<div class="text-content">
<h2
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/main/contact/form/ContactForm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { computed, useTemplateRef } from 'vue';
import useStore from '@/store';
import ContactFormField from '@/components/main/contact/form/ContactFormField.vue';
import contactFormFields from '@/components/main/contact/form/contactFormFields';
Expand Down Expand Up @@ -53,7 +53,7 @@
const fields = contactFormFields;
const root = ref<HTMLFormElement>();
const root = useTemplateRef('root');
const submitDisabled = computed(() => touched.value && !valid.value);
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/main/navbar/Navbar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import NavbarLink from '@/components/main/navbar/NavbarLink.vue';
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
import { computed, onBeforeUnmount, onMounted, ref, useTemplateRef } from 'vue';
import useStore from '@/store';
import NavbarSocialNetwork from '@/components/main/navbar/NavbarSocialNetwork.vue';
import NavbarIcon from '@/components/main/navbar/NavbarIcon.vue';
Expand Down Expand Up @@ -31,7 +31,7 @@
const opened = ref(false);
const root = ref<HTMLDivElement | null>(null);
const root = useTemplateRef('root');
const socialNetworks: NavbarSocialNetworkProps[] = [
{
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/main/projects/Project.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { computed, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue';
import useStore from '@/store';
import { kebabCase } from 'lodash';
import ExternalLink from '@/components/ExternalLink.vue';
Expand All @@ -19,7 +19,7 @@
const textHoverHeight = ref(0);
const textContent = ref<HTMLDivElement | null>(null);
const textContent = useTemplateRef('textContent');
const backgroundImage = computed(() => `url(/images/${kebabCase(props.name)}.${store.imageFormat})`);
Expand Down

0 comments on commit 45d8e4c

Please sign in to comment.