Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain search condition up to tab session #893

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions dashboard/src/libs/localStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { createStore } from 'solid-js/store'

// https://www.solidjs.com/examples/todos

export const createLocalSignal = <T>(name: string, init: T): ReturnType<typeof createSignal<T>> => {
const localState = localStorage.getItem(name)
const createStorageSignal = <T>(name: string, init: T, storage: Storage): ReturnType<typeof createSignal<T>> => {
const localState = storage.getItem(name)
const [state, setState] = createSignal<T>(localState ? JSON.parse(localState) : init)
createEffect(() => localStorage.setItem(name, JSON.stringify(state())))
createEffect(() => storage.setItem(name, JSON.stringify(state())))
return [state, setState]
}

export const createSessionSignal = <T>(name: string, init: T): ReturnType<typeof createSignal<T>> =>
createStorageSignal(name, init, sessionStorage)
export const createLocalSignal = <T>(name: string, init: T): ReturnType<typeof createSignal<T>> =>
createStorageSignal(name, init, localStorage)

export const createLocalStore = <T extends {}>(name: string, init: T): ReturnType<typeof createStore<T>> => {
const localState = localStorage.getItem(name)
const [state, setState] = createStore<T>(localState ? JSON.parse(localState) : init)
Expand Down
14 changes: 7 additions & 7 deletions dashboard/src/pages/apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import type { SelectOption } from '/@/components/templates/Select'
import { client, getRepositoryCommits, user } from '/@/libs/api'
import { ApplicationState, type Provider, applicationState, repositoryURLToProvider } from '/@/libs/application'
import { createLocalSignal } from '/@/libs/localStore'
import { createSessionSignal } from '/@/libs/localStore'
import { Button } from '../components/UI/Button'
import { MaterialSymbols } from '../components/UI/MaterialSymbols'
import { TabRound } from '../components/UI/TabRound'
Expand Down Expand Up @@ -239,7 +239,7 @@ const AppsList: Component<{
}

export default () => {
const [scope, _setScope] = createLocalSignal('apps-scope', GetRepositoriesRequest_Scope.MINE)
const [scope, _setScope] = createSessionSignal('apps-scope', GetRepositoriesRequest_Scope.MINE)
const [isPending, start] = useTransition()

const setScope = (scope: GetRepositoriesRequest_Scope) => {
Expand All @@ -248,14 +248,14 @@ export default () => {
})
}

const [statuses, setStatuses] = createLocalSignal(
const [statuses, setStatuses] = createSessionSignal(
'apps-statuses-v1',
allStatuses.map((s) => s.value),
)
const [provider, setProvider] = createLocalSignal<Provider[]>('apps-provider', ['GitHub', 'GitLab', 'Gitea'])
const [query, setQuery] = createLocalSignal('apps-query', '')
const [sort, setSort] = createLocalSignal<keyof typeof sortItems>('apps-sort', sortItems.desc.value)
const [includeNoApp, setIncludeNoApp] = createLocalSignal('apps-include-no-app', false)
const [provider, setProvider] = createSessionSignal<Provider[]>('apps-provider', ['GitHub', 'GitLab', 'Gitea'])
const [query, setQuery] = createSessionSignal('apps-query', '')
const [sort, setSort] = createSessionSignal<keyof typeof sortItems>('apps-sort', sortItems.desc.value)
const [includeNoApp, setIncludeNoApp] = createSessionSignal('apps-include-no-app', false)

const [scrollParentRef, setScrollParentRef] = createSignal<HTMLDivElement>()

Expand Down
Loading