Skip to content

Commit 957950b

Browse files
committed
update
1 parent 559902e commit 957950b

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

apps/bplan-client/src/components/midi-player/SSetting.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {cx} from 'class-variance-authority'
22
import {JSX, splitProps} from 'solid-js'
3+
import {getRegistrations} from 'src/utils/service-worker'
34
import {SPlayerButton} from './SPlayerButton'
45
import {SSettingItem} from './SSettingItem'
56
import {HUNDRED} from '@winter-love/utils'
@@ -16,6 +17,12 @@ export interface SSettingProps extends JSX.HTMLAttributes<HTMLDivElement> {
1617
settingData?: SettingData
1718
}
1819

20+
const unregisterServiceWorker = async () => {
21+
const registrations = await getRegistrations()
22+
23+
return Promise.all(registrations.map((registration) => registration.unregister()))
24+
}
25+
1926
const DEFAULT_MIN_SCALE = 20
2027

2128
export const SSetting = (props: SSettingProps) => {
@@ -51,6 +58,7 @@ export const SSetting = (props: SSettingProps) => {
5158
innerProps.class,
5259
)}
5360
>
61+
<SSettingItem label="reset PWA" type="button" onClick={unregisterServiceWorker} />
5462
<SSettingItem
5563
label="Piano Size"
5664
type="slider"

apps/bplan-client/src/components/midi-player/SSettingItem.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {createUniqueId, JSX, Match, splitProps, Switch} from 'solid-js'
22

3-
export type SSettingItemType = 'switch' | 'slider'
3+
export type SSettingItemType = 'switch' | 'slider' | 'button'
44

55
export interface SSettingItemProps<T extends SSettingItemType>
6-
extends JSX.HTMLAttributes<HTMLDivElement> {
6+
extends Omit<JSX.HTMLAttributes<HTMLDivElement>, 'onClick'> {
77
label: string
88
max?: T extends 'slider' ? number : never
99
min?: T extends 'slider' ? number : never
10+
onClick?: () => void
1011
onValueChange?: (value: T extends 'switch' ? boolean : number) => void
1112
type: T
1213
value?: T extends 'switch' ? boolean : number
@@ -20,6 +21,7 @@ export function SSettingItem<T extends SSettingItemType>(props: SSettingItemProp
2021
'min',
2122
'max',
2223
'onValueChange',
24+
'onClick',
2325
])
2426
const id = createUniqueId()
2527

@@ -37,6 +39,10 @@ export function SSettingItem<T extends SSettingItemType>(props: SSettingItemProp
3739
;(event.target as any)?.click()
3840
}
3941

42+
const handleClick = () => {
43+
innerProps.onClick?.()
44+
}
45+
4046
return (
4147
<div {...restProps} class="flex items-center justify-start gap-2">
4248
<label class="text-nowrap text-4" for={id}>
@@ -64,6 +70,11 @@ export function SSettingItem<T extends SSettingItemType>(props: SSettingItemProp
6470
onInput={handleSliderChange}
6571
/>
6672
</Match>
73+
<Match when={innerProps.type === 'button'}>
74+
<button class="p-2 touch-none" onClick={handleClick}>
75+
Run
76+
</button>
77+
</Match>
6778
</Switch>
6879
</div>
6980
)

apps/bplan-client/src/utils/service-worker/get-registration.ts renamed to apps/bplan-client/src/utils/service-worker/get-registrations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {getWindow} from '@winter-love/utils'
22

3-
export const getRegistration = async (): Promise<
3+
export const getRegistrations = async (): Promise<
44
readonly ServiceWorkerRegistration[]
55
> => {
66
const window = getWindow()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './get-registration'
1+
export * from './get-registrations'

0 commit comments

Comments
 (0)