All files / src/composables useViewName.ts

100% Statements 12/12
100% Branches 5/5
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35          18x   18x     18x   3x   2x   8x   4x   1x       18x 18x   18x         18x    
import { ScanView } from '@3cr/types-ts';
import { MaybeRef, ref, unref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
 
export function useViewName(view: MaybeRef<ScanView>) {
  const { t } = useI18n();
 
  const name = ref<string>();
 
  function getViewName(view: ScanView): string {
    switch (view) {
      case ScanView.Volume:
        return t('enums.scanView.volume');
      case ScanView.Transverse:
        return t('enums.scanView.transverse');
      case ScanView.Sagittal:
        return t('enums.scanView.sagittal');
      case ScanView.Coronal:
        return t('enums.scanView.coronal');
      default:
        return '';
    }
  }
 
  watch(
    () => unref(view),
    (value: ScanView) => {
      name.value = getViewName(value);
    },
    { immediate: true },
  );
 
  return { name };
}