diff --git a/app/components/Package/TrendsChart.vue b/app/components/Package/TrendsChart.vue index dd6efebd9..bb93697c4 100644 --- a/app/components/Package/TrendsChart.vue +++ b/app/components/Package/TrendsChart.vue @@ -5,6 +5,16 @@ import { useDebounceFn, useElementSize } from '@vueuse/core' import { useCssVariables } from '~/composables/useColors' import { OKLCH_NEUTRAL_FALLBACK, transparentizeOklch } from '~/utils/colors' import { getFrameworkColor, isListedFramework } from '~/utils/frameworks' +import type { + ChartTimeGranularity, + DailyDataPoint, + DateRangeFields, + EvolutionData, + EvolutionOptions, + MonthlyDataPoint, + WeeklyDataPoint, + YearlyDataPoint, +} from '~/types/chart' const props = defineProps<{ // For single package downloads history @@ -26,7 +36,9 @@ const props = defineProps<{ /** When true, shows facet selector (e.g. Downloads / Likes). */ showFacetSelector?: boolean + permalink?: boolean }>() +const emit = defineEmits(['update:startDate', 'update:endDate']) const { locale } = useI18n() const { accentColors, selectedAccentColor } = useAccentColor() @@ -103,14 +115,7 @@ const accent = computed(() => { const mobileBreakpointWidth = 640 const isMobile = computed(() => width.value > 0 && width.value < mobileBreakpointWidth) -type ChartTimeGranularity = 'daily' | 'weekly' | 'monthly' | 'yearly' const DEFAULT_GRANULARITY: ChartTimeGranularity = 'weekly' -type EvolutionData = DailyDataPoint[] | WeeklyDataPoint[] | MonthlyDataPoint[] | YearlyDataPoint[] - -type DateRangeFields = { - startDate?: string - endDate?: string -} function isRecord(value: unknown): value is Record { return typeof value === 'object' && value !== null @@ -315,7 +320,14 @@ const effectivePackageNames = computed(() => { return single ? [single] : [] }) -const selectedGranularity = shallowRef(DEFAULT_GRANULARITY) +const selectedGranularity = usePermalinkValue( + 'granularity', + DEFAULT_GRANULARITY, + { + permanent: props.permalink, + }, +) + const displayedGranularity = shallowRef(DEFAULT_GRANULARITY) const isEndDateOnPeriodEnd = computed(() => { @@ -345,8 +357,13 @@ const shouldRenderEstimationOverlay = computed( () => !pending.value && isEstimationGranularity.value, ) -const startDate = shallowRef('') // YYYY-MM-DD -const endDate = shallowRef('') // YYYY-MM-DD +const startDate = usePermalinkValue('start', '', { + permanent: props.permalink, +}) +const endDate = usePermalinkValue('end', '', { + permanent: props.permalink, +}) + const hasUserEditedDates = shallowRef(false) /** @@ -571,7 +588,9 @@ const METRICS = computed(() => [ }, ]) -const selectedMetric = shallowRef(DEFAULT_METRIC_ID) +const selectedMetric = usePermalinkValue('facet', DEFAULT_METRIC_ID, { + permanent: props.permalink, +}) // Per-metric state keyed by metric id const metricStates = reactive< diff --git a/app/components/Package/WeeklyDownloadStats.vue b/app/components/Package/WeeklyDownloadStats.vue index 8b522ee73..7bf6c2521 100644 --- a/app/components/Package/WeeklyDownloadStats.vue +++ b/app/components/Package/WeeklyDownloadStats.vue @@ -1,6 +1,7 @@