All files / src/components/modal/actions FullscreenAction.vue

100% Statements 18/18
100% Branches 6/6
100% Functions 5/5
100% Lines 18/18

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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62  4x                                         3x       3x 3x 3x   3x 4x         3x 4x     3x 4x       1x 1x     1x 1x           1x 1x 1x      
<template>
  <Action
    :text="text"
    :icon="icon"
    :variant="variant"
    @click="action"
  />
</template>
 
<script setup lang="ts">
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { isFullscreen, previousLayout, scanState } from '@/models/scanState';
import { LayoutActions, ScanView, ViewSelectionActions } from '@3cr/types-ts';
import { useViewer3cr } from '@/composables/useViewer3cr';
import { useViewName } from '@/composables/useViewName';
 
interface Props {
  view: ScanView;
  variant?: 'button' | 'menu-item';
}
 
const props = withDefaults(defineProps<Props>(), {
  variant: 'button',
});
 
const { t } = useI18n();
const { name } = useViewName(props.view);
const viewer3cr = useViewer3cr();
 
const text = computed(() => {
  return isFullscreen.value
    ? t('labels.fullscreenExit')
    : t('labels.fullscreenEnter', { view: name.value });
});
 
const icon = computed(() => {
  return isFullscreen.value ? 'fullscreen_exit' : 'fullscreen';
});
 
const action = computed(() => {
  return isFullscreen.value ? exitFullscreen : fullscreen;
});
 
async function fullscreen(): Promise<void> {
  previousLayout.value = scanState.value.Layout.PositionData;
  await viewer3cr.viewSelection(
    `vs_0${props.view + 1}` as ViewSelectionActions,
  );
  await viewer3cr.layouts(LayoutActions.lo01);
  await viewer3cr.viewSelection(
    `vs_0${props.view + 1}` as ViewSelectionActions,
  ); // for compatibility < 3CR 2.1.0
}
 
async function exitFullscreen(): Promise<void> {
  const message = { Version: '0.0.0', PositionData: previousLayout.value };
  await viewer3cr.customLayout({ message });
  previousLayout.value = [];
}
</script>