Skip to content

Commit

Permalink
remove some store imports (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick authored Aug 7, 2024
1 parent 30e099e commit eef461f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
1 change: 1 addition & 0 deletions web/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './tailwind.css'
import './app.css'
import './dots.css'
import '@melloware/coloris/dist/coloris.css'
import './store'
import { Component, createMemo, Show, lazy, onMount, Switch, Match } from 'solid-js'
import { Route, Router, useLocation } from '@solidjs/router'
import NavBar from './shared/NavBar'
Expand Down
1 change: 0 additions & 1 deletion web/pages/Character/port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export async function importCharacterFile(file: FileInputResult) {
const ext = file.file.name.split('.').slice(-1)[0]
if (IMAGE_FORMATS[ext]) {
const char = await processImage(file)
console.log(char)
return { char, image: file.file }
}

Expand Down
12 changes: 1 addition & 11 deletions web/pages/Chat/helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ChevronLeft, ChevronRight } from 'lucide-solid'
import { Component, JSX, Show } from 'solid-js'
import { Component, Show } from 'solid-js'
import Button from '/web/shared/Button'
import { chatStore, msgStore } from '/web/store'
import { AppSchema, UI } from '/common/types'
import { getRootRgb } from '/web/shared/colors'

export const SwipeMessage: Component<{
chatId: string
Expand Down Expand Up @@ -76,15 +75,6 @@ export function getChatWidth(
}
}

export function getHeaderBg(mode: UI.UISettings['mode']) {
mode
const rgb = getRootRgb('bg-900')
const styles: JSX.CSSProperties = {
background: rgb ? `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0.7)` : 'bg-900',
}
return styles
}

export function emptyMsg(opts: {
id?: string
charId?: string
Expand Down
3 changes: 1 addition & 2 deletions web/pages/Saga/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ import { toastStore, userStore } from '/web/store'
import { Saga } from '/common/types'
import { getRgbaFromVar } from '/web/shared/colors'
import { trimSentence } from '/common/util'
import { sticky } from '/web/shared/util'
import { getHeaderBg } from '../Chat/helpers'
import { getHeaderBg, sticky } from '/web/shared/util'

export const SagaDetail: Component = (props) => {
const user = userStore()
Expand Down
16 changes: 8 additions & 8 deletions web/shared/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Accessor, JSX, Signal, createEffect, createMemo, onCleanup, onMount } from 'solid-js'
import { createSignal, createRenderEffect } from 'solid-js'
import { characterStore, chatStore, presetStore, settingStore, userStore } from '../store'
import { RootModal, rootModalStore } from '../store/root-modal'
import { useLocation, useSearchParams } from '@solidjs/router'
import { createImageCache } from '../store/images'
Expand All @@ -10,6 +9,7 @@ import { getAssetUrl } from './util'
import { AutoPreset, getPresetOptions } from './adapter'
import { ADAPTER_LABELS } from '/common/adapters'
import { forms } from '../emitter'
import { getStore } from '../store/create'

export function getPlatform() {
return window.innerWidth > 1024 ? 'xl' : window.innerWidth > 720 ? 'lg' : 'sm'
Expand All @@ -27,8 +27,8 @@ export function useFormField(field: string, init?: string) {
}

export function usePresetOptions() {
const presets = presetStore((s) => s.presets)
const user = userStore()
const presets = getStore('presets')((s) => s.presets)
const user = getStore('user')()

const options = createMemo(() => {
const opts = getPresetOptions(presets, { builtin: true }).filter((pre) => pre.value !== 'chat')
Expand Down Expand Up @@ -112,10 +112,10 @@ export function useCharacterBg(src: 'layout' | 'page') {
const isMobile = useMobileDetect()
const isChat = isChatPage()

const state = userStore()
const cfg = settingStore()
const chat = chatStore((s) => ({ active: s.active }))
const chars = characterStore((s) => ({ chatId: s.activeChatId, chars: s.chatChars }))
const state = getStore('user')()
const cfg = getStore('settings')()
const chat = getStore('chat')((s) => ({ active: s.active }))
const chars = getStore('character')((s) => ({ chatId: s.activeChatId, chars: s.chatChars }))

const bg = createMemo(() => {
if (src === 'page') return {}
Expand Down Expand Up @@ -380,7 +380,7 @@ export const usePaneManager = () => {
}

export function useBgStyle(props: { hex: string; opacity?: number; blur: boolean }) {
const user = userStore()
const user = getStore('user')()

const bgStyle = createMemo(() => {
// This causes this memoized value to re-evaluated as it becomes a subscriber of ui.mode
Expand Down
23 changes: 17 additions & 6 deletions web/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import * as lf from 'localforage'
import { UnwrapBody, Validator, assertValid } from '/common/valid'
import { AIAdapter, AI_ADAPTERS, PresetAISettings, ThirdPartyFormat } from '../../common/adapters'
import type { Option } from './Select'
import { createEffect, onCleanup } from 'solid-js'
import { UserState, settingStore, userStore } from '../store'
import { AppSchema } from '/common/types'
import { createEffect, JSX, onCleanup } from 'solid-js'
import type { UserState } from '../store'
import { AppSchema, UI } from '/common/types'
import { deepClone } from '/common/util'
import { getRootRgb } from './colors'
import { getStore } from '../store/create'

const [css, hooks] = createHooks(recommended)

Expand Down Expand Up @@ -39,6 +41,15 @@ export function downloadJson(content: string | object, filename: string = 'agnai
URL.revokeObjectURL(anchor.href)
}

export function getHeaderBg(mode: UI.UISettings['mode']) {
mode
const rgb = getRootRgb('bg-900')
const styles: JSX.CSSProperties = {
background: rgb ? `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0.7)` : 'bg-900',
}
return styles
}

export function getMaxChatWidth(chatWidth: UserState['ui']['chatWidth']) {
switch (chatWidth) {
case 'xl':
Expand Down Expand Up @@ -510,7 +521,7 @@ export function serviceHasSetting(

export function getAISettingServices(prop?: keyof PresetAISettings) {
if (!prop) return
const cfg = settingStore((s) => s.config)
const cfg = getStore('settings')((s) => s.config)
const base = adapterSettings[prop]
const names: Array<AIAdapter | ThirdPartyFormat> = []
for (const reg of cfg.registered) {
Expand Down Expand Up @@ -633,8 +644,8 @@ export function asyncFrame() {
}

export function getUsableServices() {
const { user } = userStore.getState()
const { config } = settingStore.getState()
const { user } = getStore('user').getState()
const { config } = getStore('settings').getState()

const services: AIAdapter[] = []

Expand Down

0 comments on commit eef461f

Please sign in to comment.