Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(theme): refactor useUiState #595

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/theme/components/__tests__/LoginModal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { waitFor } from '@testing-library/vue';
import { useUser, useForgotPassword } from '@vue-storefront/magento';
import { render, useUserMock, useForgotPasswordMock } from '~/test-utils';
import useUiState from '~/composables/useUiState.ts';
import useUiState from '~/composables/useUiState/useUiState.ts';

import LoginModal from '../LoginModal';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { computed, reactive } from '@nuxtjs/composition-api';
import { StateInterface, UseUiStateInterface } from '~/composables/useUiState/useUiState';

const state = reactive({
const state = reactive<StateInterface>({
isCartSidebarOpen: false,
isWishlistSidebarOpen: false,
isLoginModalOpen: false,
Expand All @@ -11,7 +12,7 @@ const state = reactive({
isMobileMenuOpen: false,
});

const useUiState = () => {
const useUiState = (): UseUiStateInterface => {
const isMobileMenuOpen = computed(() => state.isMobileMenuOpen);
const toggleMobileMenu = () => {
state.isMobileMenuOpen = !state.isMobileMenuOpen;
Expand Down
33 changes: 33 additions & 0 deletions packages/theme/composables/useUiState/useUiState.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { computed, ComputedRef } from '@nuxtjs/composition-api';

interface StateInterface {
isCartSidebarOpen: boolean,
isWishlistSidebarOpen: boolean,
isLoginModalOpen: boolean,
isNewsletterModalOpen: boolean,
isCategoryGridView: boolean,
isWishlistGridView: boolean,
isFilterSidebarOpen: boolean,
isMobileMenuOpen: boolean,
}

interface UseUiStateInterface {
isMobileMenuOpen: ComputedRef<boolean>,
toggleMobileMenu (): void,
isCartSidebarOpen: ComputedRef<boolean>,
isWishlistSidebarOpen: ComputedRef<boolean>,
toggleWishlistSidebar (): void,
isLoginModalOpen: ComputedRef<boolean>,
toggleLoginModal (): void,
isNewsletterModalOpen: ComputedRef<boolean>,
toggleNewsletterModal (): void,
isCategoryGridView: ComputedRef<boolean>,
isWishlistGridView: ComputedRef<boolean>,
changeToCategoryGridView (): void,
changeToCategoryListView (): void,
changeToWishlistGridView (): void,
changeToWishlistListView (): void,
isFilterSidebarOpen: ComputedRef<boolean>,
toggleFilterSidebar (): void,
toggleCartSidebar (): void,
}