Skip to content

Commit ab8a350

Browse files
committed
fix: create shared cache for user preferences provier, enhance useAtproto mocking
1 parent 785009b commit ab8a350

25 files changed

+470
-420
lines changed

app/app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const localeMap = locales.value.reduce(
2222
)
2323
2424
const darkMode = usePreferredDark()
25-
const colorMode = useColorMode()
25+
const { colorMode } = useColorModePreference()
2626
const colorScheme = computed(() => {
2727
return {
2828
system: darkMode ? 'dark light' : 'light dark',

app/components/Chart/SplitSparkline.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const props = defineProps<{
2828
}>()
2929
3030
const { locale } = useI18n()
31-
const colorMode = useColorMode()
31+
const { colorMode } = useColorModePreference()
3232
const resolvedMode = shallowRef<'light' | 'dark'>('light')
3333
const rootEl = shallowRef<HTMLElement | null>(null)
3434
const palette = getPalette('')

app/components/Compare/FacetBarChart.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const props = defineProps<{
2424
facetLoading?: boolean
2525
}>()
2626
27-
const colorMode = useColorMode()
27+
const { colorMode } = useColorModePreference()
2828
const resolvedMode = shallowRef<'light' | 'dark'>('light')
2929
const rootEl = shallowRef<HTMLElement | null>(null)
3030
const { width } = useElementSize(rootEl)

app/components/Package/Header.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const diffLink = computed((): RouteLocationRaw | null => {
120120
return diffRoute(props.pkg.name, props.resolvedVersion, props.latestVersion.version)
121121
})
122122
123-
const keyboardShortcuts = useKeyboardShortcuts()
123+
const keyboardShortcuts = useKeyboardShortcutsPreference()
124124
125125
onKeyStroke(
126126
e => keyboardShortcuts.value && isKeyWithoutModifiers(e, '.') && !isEditableElement(e.target),

app/components/Package/TrendsChart.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const { accentColors, selectedAccentColor } = useAccentColor();
6262
const { localSettings } = useUserLocalSettings();
6363
const { copy, copied } = useClipboard();
6464
65-
const colorMode = useColorMode();
65+
const { colorMode } = useColorModePreference();
6666
const resolvedMode = shallowRef<"light" | "dark">("light");
6767
const rootEl = shallowRef<HTMLElement | null>(null);
6868
const isZoomed = shallowRef(false);

app/components/Package/VersionDistribution.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const props = defineProps<{
2121
const { accentColors, selectedAccentColor } = useAccentColor()
2222
const { copy, copied } = useClipboard()
2323
24-
const colorMode = useColorMode()
24+
const { colorMode } = useColorModePreference()
2525
const resolvedMode = shallowRef<'light' | 'dark'>('light')
2626
const rootEl = shallowRef<HTMLElement | null>(null)
2727

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const props = defineProps<{
2020
const router = useRouter()
2121
const route = useRoute()
2222
const { localSettings } = useUserLocalSettings()
23+
const { preferences } = useUserPreferencesState()
2324
2425
const chartModal = useModal('chart-modal')
2526
const hasChartModalTransitioned = shallowRef(false)
@@ -63,7 +64,7 @@ const { fetchPackageDownloadEvolution } = useCharts()
6364
6465
const { accentColors, selectedAccentColor } = useAccentColor()
6566
66-
const colorMode = useColorMode()
67+
const { colorMode } = useColorModePreference()
6768
6869
const resolvedMode = shallowRef<'light' | 'dark'>('light')
6970
@@ -306,7 +307,7 @@ function layEgg() {
306307
showPulse.value = false
307308
nextTick(() => {
308309
showPulse.value = true
309-
settings.value.enableGraphPulseLooping = !settings.value.enableGraphPulseLooping
310+
preferences.value.enableGraphPulseLooping = !preferences.value.enableGraphPulseLooping
310311
playEggPulse()
311312
})
312313
}
@@ -364,7 +365,7 @@ const config = computed<VueUiSparklineConfig>(() => {
364365
color: colors.value.borderHover,
365366
pulse: {
366367
show: showPulse.value, // the pulse will not show if prefers-reduced-motion (enforced by vue-data-ui)
367-
loop: settings.value.enableGraphPulseLooping,
368+
loop: preferences.value.enableGraphPulseLooping,
368369
radius: 1.5,
369370
color: pulseColor.value!,
370371
easing: 'ease-in-out',

app/composables/atproto/useAtproto.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1-
export const useAtproto = createSharedComposable(function useAtproto() {
1+
import type { PublicUserSessionSchema } from "#shared/schemas/publicUserSession";
2+
import type { InferOutput } from "valibot";
3+
4+
type User = InferOutput<typeof PublicUserSessionSchema>;
5+
6+
export interface UseAtprotoReturn {
7+
user: Ref<User | null | undefined>;
8+
pending: Ref<boolean>;
9+
logout: () => Promise<void>;
10+
}
11+
12+
declare global {
13+
// eslint-disable-next-line no-var
14+
var __useAtprotoMock: UseAtprotoReturn | undefined
15+
}
16+
17+
function _useAtprotoImpl(): UseAtprotoReturn {
18+
if (import.meta.test && globalThis.__useAtprotoMock) {
19+
return globalThis.__useAtprotoMock
20+
}
21+
222
const {
323
data: user,
424
pending,
@@ -17,4 +37,10 @@ export const useAtproto = createSharedComposable(function useAtproto() {
1737
}
1838

1939
return { user, pending, logout }
20-
})
40+
}
41+
42+
// In tests, skip createSharedComposable so each call checks globalThis.__useAtprotoMock fresh.
43+
// In production, import.meta.test is false and the test branch is tree-shaken.
44+
export const useAtproto = import.meta.test
45+
? _useAtprotoImpl
46+
: createSharedComposable(_useAtprotoImpl)

0 commit comments

Comments
 (0)