Skip to content
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
5 changes: 3 additions & 2 deletions src/features/editor/hooks/useAppControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSettingsMutation } from '@settings/hooks/useSettingsMutation'
import type { SettingsUpdateDto } from '@settings/lib/settings-actions.dto'
import { useSettingsStore } from '@settings/providers/settings.provider'
import { useShallow } from 'zustand/shallow'
import { areArraysEqualAsSets } from '@/utils/array'
import { areObjKeysEqual } from '@/utils/objects'

export const useAppControls = () => {
Expand Down Expand Up @@ -35,8 +36,8 @@ export const useAppControls = () => {
)
const initialSettings = useSettingsStore((s) => s.initialSettings)
const orderChanged = JSON.stringify(actions.order) !== JSON.stringify(initialSettings.actions?.order)
const hiddenAppIdsChanged =
JSON.stringify(actions.hiddenAppIds) !== JSON.stringify(initialSettings.actions?.hiddenAppIds)
// `hiddenAppIds` is an unordered deny-list, so compare membership rather than sequence.
const hiddenAppIdsChanged = !areArraysEqualAsSets(actions.hiddenAppIds, initialSettings.actions?.hiddenAppIds)
const show =
!areObjKeysEqual(settings, initialSettings, ['content', 'heading', 'subheading', 'backgroundColor']) ||
!areObjKeysEqual(actions, initialSettings.actions, ['tasks', 'invoices', 'contracts', 'forms']) ||
Expand Down
13 changes: 13 additions & 0 deletions src/utils/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ export const mapWithConcurrency = async <T, R>(
return results
}

// Membership equality for arrays whose order carries no meaning. A missing array counts as empty.
export const areArraysEqualAsSets = <T>(a: readonly T[] = [], b: readonly T[] = []): boolean => {
const setA = new Set(a)
const setB = new Set(b)
if (setA.size !== setB.size) return false

for (const item of setA) {
if (!setB.has(item)) return false
}

return true
}

export const getArraySymmetricDifference = <T>(a: T[], b: T[]): T[] => {
const setA = new Set(a)
const setB = new Set(b)
Expand Down
Loading