web/satellite: migrate OSContainer component to use SFC composition api
Change-Id: Ibc4baa713850c2a209bccf861847278818a7e01f
This commit is contained in:
parent
214e962263
commit
d9c179162f
@ -35,81 +35,80 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import { Component, Prop, Vue } from 'vue-property-decorator';
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
import { OnboardingOS } from '@/types/common';
|
import { OnboardingOS } from '@/types/common';
|
||||||
import { APP_STATE_MUTATIONS } from '@/store/mutationConstants';
|
import { APP_STATE_MUTATIONS } from '@/store/mutationConstants';
|
||||||
|
import { useStore } from '@/utils/hooks';
|
||||||
|
|
||||||
// @vue/component
|
const store = useStore();
|
||||||
@Component
|
|
||||||
export default class OSContainer extends Vue {
|
|
||||||
@Prop({ default: false })
|
|
||||||
public readonly isInstallStep: boolean;
|
|
||||||
|
|
||||||
public osSelected = OnboardingOS.WINDOWS;
|
const props = withDefaults(defineProps<{
|
||||||
// This is done to fix "non-reactive property issue" to be able to use enum in template.
|
isInstallStep: boolean;
|
||||||
public OnboardingOS = OnboardingOS;
|
}>(), {
|
||||||
|
isInstallStep: false,
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
const osSelected = ref<OnboardingOS>(OnboardingOS.WINDOWS);
|
||||||
* Lifecycle hook after initial render.
|
|
||||||
* Checks user's OS.
|
|
||||||
*/
|
|
||||||
public mounted(): void {
|
|
||||||
if (this.storedOsSelected) {
|
|
||||||
this.setTab(this.storedOsSelected);
|
|
||||||
|
|
||||||
return;
|
/**
|
||||||
}
|
* Returns selected os from store.
|
||||||
|
*/
|
||||||
|
const storedOsSelected = computed((): OnboardingOS | null => {
|
||||||
|
return store.state.appStateModule.viewsState.onbSelectedOs;
|
||||||
|
});
|
||||||
|
|
||||||
switch (true) {
|
/**
|
||||||
case navigator.appVersion.indexOf('Mac') !== -1:
|
* Indicates if mac tab is selected.
|
||||||
this.setTab(OnboardingOS.MAC);
|
*/
|
||||||
return;
|
const isMacOS = computed((): boolean => {
|
||||||
case navigator.appVersion.indexOf('Linux') !== -1:
|
return osSelected.value === OnboardingOS.MAC;
|
||||||
this.setTab(OnboardingOS.LINUX);
|
});
|
||||||
return;
|
|
||||||
default:
|
|
||||||
this.setTab(OnboardingOS.WINDOWS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets view to given state.
|
* Indicates if linux tab is selected.
|
||||||
*/
|
*/
|
||||||
public setTab(os: OnboardingOS): void {
|
const isLinux = computed((): boolean => {
|
||||||
this.osSelected = os;
|
return osSelected.value === OnboardingOS.LINUX;
|
||||||
this.$store.commit(APP_STATE_MUTATIONS.SET_ONB_OS, os);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns selected os from store.
|
* Indicates if windows tab is selected.
|
||||||
*/
|
*/
|
||||||
public get storedOsSelected(): OnboardingOS | null {
|
const isWindows = computed((): boolean => {
|
||||||
return this.$store.state.appStateModule.viewsState.onbSelectedOs;
|
return osSelected.value === OnboardingOS.WINDOWS;
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if mac tab is selected.
|
* Sets view to given state.
|
||||||
*/
|
*/
|
||||||
private get isMacOS(): boolean {
|
function setTab(os: OnboardingOS): void {
|
||||||
return this.osSelected === OnboardingOS.MAC;
|
osSelected.value = os;
|
||||||
}
|
store.commit(APP_STATE_MUTATIONS.SET_ONB_OS, os);
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates if linux tab is selected.
|
|
||||||
*/
|
|
||||||
private get isLinux(): boolean {
|
|
||||||
return this.osSelected === OnboardingOS.LINUX;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates if windows tab is selected.
|
|
||||||
*/
|
|
||||||
private get isWindows(): boolean {
|
|
||||||
return this.osSelected === OnboardingOS.WINDOWS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lifecycle hook after initial render.
|
||||||
|
* Checks user's OS.
|
||||||
|
*/
|
||||||
|
onMounted((): void => {
|
||||||
|
if (storedOsSelected.value) {
|
||||||
|
setTab(storedOsSelected.value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case navigator.appVersion.indexOf('Mac') !== -1:
|
||||||
|
setTab(OnboardingOS.MAC);
|
||||||
|
return;
|
||||||
|
case navigator.appVersion.indexOf('Linux') !== -1:
|
||||||
|
setTab(OnboardingOS.LINUX);
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
setTab(OnboardingOS.WINDOWS);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
Loading…
Reference in New Issue
Block a user