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.

2.0 KB
Raw Blame
import { MakeLogicType, actions, kea, listeners, path, reducers } from 'kea'

export interface FloatingMaxPosition {
    side: 'left' | 'right'
}

const FLOATING_MAX_POSITION_STORAGE_KEY = 'floating_max_position'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface floatingMaxPositionLogicValues {
    position: FloatingMaxPosition
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface floatingMaxPositionLogicActions {
    setPosition: (position: FloatingMaxPosition) => {
        position: FloatingMaxPosition
    }
}

export type floatingMaxPositionLogicType = MakeLogicType<
    floatingMaxPositionLogicValues,
    floatingMaxPositionLogicActions
>

export const floatingMaxPositionLogic = kea<floatingMaxPositionLogicType>([
    path(['scenes', 'max', 'floatingMaxPositionLogic']),

    actions({
        setPosition: (position: FloatingMaxPosition) => ({ position }),
    }),

    reducers({
        position: [
            { side: 'right' } as FloatingMaxPosition,
            {
                setPosition: (_, { position }) => position,
            },
        ],
    }),

    listeners(({ actions }) => ({
        setPosition: ({ position }) => {
            // Persist position to localStorage
            try {
                localStorage.setItem(FLOATING_MAX_POSITION_STORAGE_KEY, JSON.stringify(position))
            } catch {
                // Ignore localStorage errors
            }
        },
        afterMount: () => {
            // Load position from localStorage on mount
            try {
                const stored = localStorage.getItem(FLOATING_MAX_POSITION_STORAGE_KEY)
                if (stored) {
                    const position = JSON.parse(stored)
                    if (position && (position.side === 'left' || position.side === 'right')) {
                        actions.setPosition(position)
                    }
                }
            } catch {
                // Ignore localStorage errors, use default position
            }
        },
    })),
])