refactor: 整体重构 (#1381)
* feat: pnpm new * Refactor build and release workflows, update dependencies Switch build scripts and workflows from npm to pnpm, update build and artifact paths, and simplify release workflow by removing version detection and changelog steps. Add new dependencies (silk-wasm, express, ws, node-pty-prebuilt-multiarch), update exports in package.json files, and add vite config for napcat-framework. Also, rename manifest.json for framework package and fix static asset copying in shell build config.
This commit is contained in:
1 parent
c3d1892545
commit
ed19c52f25
778 files changed
+2356
-26391
No files matched your search
@@ -0,0 +1,106 @@
|
||||
// Dialog Context
|
||||
import React from 'react';
|
||||
|
||||
import Modal from '@/components/modal';
|
||||
import type { ModalProps } from '@/components/modal';
|
||||
|
||||
export interface AlertProps
|
||||
extends Omit<ModalProps, 'onCancel' | 'showCancel' | 'cancelText'> {
|
||||
onConfirm?: () => void
|
||||
}
|
||||
|
||||
export interface ConfirmProps extends ModalProps {
|
||||
onConfirm?: () => void
|
||||
onCancel?: () => void
|
||||
}
|
||||
|
||||
export interface ModalItem extends ModalProps {
|
||||
id: number
|
||||
}
|
||||
|
||||
export interface DialogContextProps {
|
||||
alert: (config: AlertProps) => void
|
||||
confirm: (config: ConfirmProps) => void
|
||||
}
|
||||
|
||||
export interface DialogProviderProps {
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export const DialogContext = React.createContext<DialogContextProps>({
|
||||
alert: () => {},
|
||||
confirm: () => {},
|
||||
});
|
||||
|
||||
const DialogProvider: React.FC<DialogProviderProps> = ({ children }) => {
|
||||
const [dialogs, setDialogs] = React.useState<ModalItem[]>([]);
|
||||
const alert = (config: AlertProps) => {
|
||||
const { onConfirm, size = 'md', ...rest } = config;
|
||||
|
||||
setDialogs((before) => {
|
||||
const id = before[before.length - 1]?.id + 1 || 0;
|
||||
|
||||
return [
|
||||
...before,
|
||||
{
|
||||
id,
|
||||
size,
|
||||
backdrop: 'blur',
|
||||
showCancel: false,
|
||||
onConfirm: () => {
|
||||
onConfirm?.();
|
||||
setTimeout(() => {
|
||||
setDialogs((before) => before.filter((item) => item.id !== id));
|
||||
}, 300);
|
||||
},
|
||||
...rest,
|
||||
},
|
||||
];
|
||||
});
|
||||
};
|
||||
|
||||
const confirm = (config: ConfirmProps) => {
|
||||
const { onConfirm, onCancel, size = 'md', ...rest } = config;
|
||||
|
||||
setDialogs((before) => {
|
||||
const id = before[before.length - 1]?.id + 1 || 0;
|
||||
|
||||
return [
|
||||
...before,
|
||||
{
|
||||
id,
|
||||
size,
|
||||
backdrop: 'blur',
|
||||
showCancel: true,
|
||||
onConfirm: () => {
|
||||
onConfirm?.();
|
||||
setTimeout(() => {
|
||||
setDialogs((before) => before.filter((item) => item.id !== id));
|
||||
}, 300);
|
||||
},
|
||||
onCancel: () => {
|
||||
onCancel?.();
|
||||
setTimeout(() => {
|
||||
setDialogs((before) => before.filter((item) => item.id !== id));
|
||||
}, 300);
|
||||
},
|
||||
...rest,
|
||||
},
|
||||
];
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContext.Provider
|
||||
value={{
|
||||
alert,
|
||||
confirm,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
{dialogs?.map(({ id, ...props }) => <Modal key={id} {...props} />)}
|
||||
</DialogContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default DialogProvider;
|
||||
@@ -0,0 +1,91 @@
|
||||
// Songs Context
|
||||
import { useLocalStorage } from '@uidotdev/usehooks';
|
||||
import { createContext, useEffect, useState } from 'react';
|
||||
|
||||
import { PlayMode } from '@/const/enum';
|
||||
import key from '@/const/key';
|
||||
|
||||
import AudioPlayer from '@/components/audio_player';
|
||||
|
||||
import { get163MusicListSongs, getNextMusic } from '@/utils/music';
|
||||
|
||||
import type { FinalMusic } from '@/types/music';
|
||||
|
||||
export interface MusicContextProps {
|
||||
setListId: (id: string) => void
|
||||
listId: string
|
||||
onNext: () => void
|
||||
onPrevious: () => void
|
||||
}
|
||||
|
||||
export interface MusicProviderProps {
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export const AudioContext = createContext<MusicContextProps>({
|
||||
setListId: () => {},
|
||||
listId: '5438670983',
|
||||
onNext: () => {},
|
||||
onPrevious: () => {},
|
||||
});
|
||||
|
||||
const AudioProvider: React.FC<MusicProviderProps> = ({ children }) => {
|
||||
const [listId, setListId] = useLocalStorage(key.musicID, '5438670983');
|
||||
const [musicList, setMusicList] = useState<FinalMusic[]>([]);
|
||||
const [musicId, setMusicId] = useState<number>(0);
|
||||
const [playMode, setPlayMode] = useState<PlayMode>(PlayMode.Loop);
|
||||
const music = musicList.find((music) => music.id === musicId);
|
||||
const [token] = useLocalStorage(key.token, '');
|
||||
const onNext = () => {
|
||||
const nextID = getNextMusic(musicList, musicId, playMode);
|
||||
setMusicId(nextID);
|
||||
};
|
||||
const onPrevious = () => {
|
||||
const index = musicList.findIndex((music) => music.id === musicId);
|
||||
if (index === 0) {
|
||||
setMusicId(musicList[musicList.length - 1].id);
|
||||
} else {
|
||||
setMusicId(musicList[index - 1].id);
|
||||
}
|
||||
};
|
||||
const onPlayEnd = () => {
|
||||
const nextID = getNextMusic(musicList, musicId, playMode);
|
||||
setMusicId(nextID);
|
||||
};
|
||||
const changeMode = (mode: PlayMode) => {
|
||||
setPlayMode(mode);
|
||||
};
|
||||
const fetchMusicList = async (id: string) => {
|
||||
const res = await get163MusicListSongs(id);
|
||||
setMusicList(res);
|
||||
setMusicId(res[0].id);
|
||||
};
|
||||
useEffect(() => {
|
||||
if (listId && token) fetchMusicList(listId);
|
||||
}, [listId, token]);
|
||||
return (
|
||||
<AudioContext.Provider
|
||||
value={{
|
||||
setListId,
|
||||
listId,
|
||||
onNext,
|
||||
onPrevious,
|
||||
}}
|
||||
>
|
||||
<AudioPlayer
|
||||
title={music?.title}
|
||||
src={music?.url || ''}
|
||||
artist={music?.artist}
|
||||
cover={music?.cover}
|
||||
mode={playMode}
|
||||
pressNext={onNext}
|
||||
pressPrevious={onPrevious}
|
||||
onPlayEnd={onPlayEnd}
|
||||
onChangeMode={changeMode}
|
||||
/>
|
||||
{children}
|
||||
</AudioContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default AudioProvider;
|
||||
Reference in new issue
Block a user