Skip to content

Commit

Permalink
chore: fix pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lauramargar committed Jun 11, 2024
1 parent c78e274 commit a427fa7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
</template>

<script lang="ts">
import { computed, ComputedRef, defineComponent } from 'vue';
import { computed, defineComponent } from 'vue';
import { HistoryQuery } from '@empathyco/x-types';
import { Dictionary } from '@empathyco/x-utils';
import BaseSwitch from '../../../components/base-switch.vue';
import { historyQueriesXModule } from '../x-module';
import { isArrayEmpty } from '../../../utils/array';
Expand All @@ -31,40 +30,37 @@
const $x = use$x();
/**
* A boolean with the isEnabled value coming from the store state.
* An object with the isEnabled value and the history queries coming from the store state.
*
* @internal
*/
const { isEnabled } = useState('historyQueries', ['isEnabled']);
/**
* The history queries from the state.
*/
const { historyQueries }: Dictionary<ComputedRef<HistoryQuery[] | undefined>> = useState(
'historyQueries',
['historyQueries']
);
const { isEnabled, historyQueries } = useState('historyQueries', [
'isEnabled',
'historyQueries'
]);
/**
* Checks if there are history queries.
*
* @returns True if there are history queries; false otherwise.
*/
const hasHistoryQueries = computed(() => !isArrayEmpty(historyQueries.value));
const hasHistoryQueries = computed(
() => !isArrayEmpty(historyQueries.value as HistoryQuery[])
);
const disableEvent = computed(() =>
hasHistoryQueries.value
? 'UserClickedDisableHistoryQueries'
: 'UserClickedConfirmDisableHistoryQueries'
);
/**
* Emits an event based on the switch state.
*
* @internal
*/
const toggle = (): void => {
$x.emit(
isEnabled.value
? hasHistoryQueries.value
? 'UserClickedDisableHistoryQueries'
: 'UserClickedConfirmDisableHistoryQueries'
: 'UserClickedEnableHistoryQueries'
);
$x.emit(isEnabled.value ? disableEvent.value : 'UserClickedEnableHistoryQueries');
};
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<script lang="ts">
import { HistoryQuery as HistoryQueryType } from '@empathyco/x-types';
import { Dictionary } from '@empathyco/x-utils';
import { computed, ComputedRef, defineComponent, inject } from 'vue';
import { computed, defineComponent, inject } from 'vue';
import BaseSuggestions from '../../../components/suggestions/base-suggestions.vue';
import { groupItemsBy, isArrayEmpty } from '../../../utils/array';
import { SnippetConfig } from '../../../x-installer/api/api.types';
Expand Down Expand Up @@ -117,10 +117,7 @@
*
* @internal
*/
const { historyQueries }: Dictionary<ComputedRef<HistoryQueryType[]>> = useState(
'historyQueries',
['historyQueries']
);
const { historyQueries } = useState('historyQueries', ['historyQueries']);
/**
* The provided {@link SnippetConfig}.
Expand Down Expand Up @@ -160,7 +157,7 @@
* @internal
*/
const groupByDate = computed((): Dictionary<HistoryQueryType[]> => {
return groupItemsBy(historyQueries.value, current => {
return groupItemsBy(historyQueries.value as HistoryQueryType[], current => {
return new Date(current.timestamp).toLocaleDateString(usedLocale.value, {
day: 'numeric',
weekday: 'long',
Expand Down Expand Up @@ -198,13 +195,15 @@
* @returns True if there are history queries; false otherwise.
* @internal
*/
const hasHistoryQueries = computed(() => !isArrayEmpty(historyQueries.value));
const hasHistoryQueries = computed(
() => !isArrayEmpty(historyQueries.value as HistoryQueryType[])
);
return {
hasHistoryQueries,
formatTime,
groupByDate,
historyQueries
historyQueries,
formatTime
};
}
});
Expand Down

0 comments on commit a427fa7

Please sign in to comment.