Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

3.2 KB
Raw Blame
import { MakeLogicType, actions, kea, path, reducers, selectors } from 'kea'

import { DEFAULT_RECENT_SORT, TodayRecentSort } from '~/layout/today/todayRecentOrder'

import {
    DEFAULT_SPACE_FEED_FILTERS,
    DEFAULT_SPACE_FEED_TYPES,
    SpaceFeedFilters,
    SpaceFeedGrouping,
    SpaceFeedType,
    SpaceFeedView,
    hasActiveSpaceFeedFilters,
} from './spaceFeedEntries'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface spaceFeedViewLogicValues {
    filters: SpaceFeedFilters
    filtersActive: boolean
    grouping: SpaceFeedGrouping
    sort: TodayRecentSort
    types: SpaceFeedType[]
    view: SpaceFeedView
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface spaceFeedViewLogicActions {
    clearFilters: () => {
        value: true
    }
    setFilters: (filters: SpaceFeedFilters) => {
        filters: SpaceFeedFilters
    }
    setGrouping: (grouping: SpaceFeedGrouping) => {
        grouping: SpaceFeedGrouping
    }
    setSort: (sort: TodayRecentSort) => {
        sort: TodayRecentSort
    }
    setTypes: (types: SpaceFeedType[]) => {
        types: SpaceFeedType[]
    }
    setView: (view: SpaceFeedView) => {
        view: SpaceFeedView
    }
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface spaceFeedViewLogicMeta {
    __keaTypeGenInternalSelectorTypes: {
        filtersActive: (filters: SpaceFeedFilters) => boolean
    }
}

export type spaceFeedViewLogicType = MakeLogicType<
    spaceFeedViewLogicValues,
    spaceFeedViewLogicActions,
    Record<string, any>,
    spaceFeedViewLogicMeta
>

/** How a person likes to read space feeds. One choice for every space, like PostHog Desktop. */
export const spaceFeedViewLogic = kea<spaceFeedViewLogicType>([
    path(['products', 'tasks', 'spaces', 'spaceFeedViewLogic']),
    actions({
        setView: (view: SpaceFeedView) => ({ view }),
        setTypes: (types: SpaceFeedType[]) => ({ types }),
        setFilters: (filters: SpaceFeedFilters) => ({ filters }),
        clearFilters: true,
        setSort: (sort: TodayRecentSort) => ({ sort }),
        setGrouping: (grouping: SpaceFeedGrouping) => ({ grouping }),
    }),
    reducers({
        view: ['cards' as SpaceFeedView, { persist: true }, { setView: (_, { view }) => view }],
        types: [
            DEFAULT_SPACE_FEED_TYPES,
            { persist: true },
            // At least one type stays on, so the feed never goes blank from the toggles alone.
            { setTypes: (state, { types }) => (types.length ? types : state) },
        ],
        filters: [
            DEFAULT_SPACE_FEED_FILTERS,
            { persist: true },
            { setFilters: (_, { filters }) => filters, clearFilters: () => DEFAULT_SPACE_FEED_FILTERS },
        ],
        sort: [DEFAULT_RECENT_SORT as TodayRecentSort, { persist: true }, { setSort: (_, { sort }) => sort }],
        grouping: ['date' as SpaceFeedGrouping, { persist: true }, { setGrouping: (_, { grouping }) => grouping }],
    }),
    selectors({
        filtersActive: [(s) => [s.filters], (filters: SpaceFeedFilters): boolean => hasActiveSpaceFeedFilters(filters)],
    }),
])