-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1be7e0
commit 4127c09
Showing
11 changed files
with
383 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function useClassState<S>( | ||
useState: [S, React.Dispatch<React.SetStateAction<S>>] | ||
): [S, (newState: Partial<S>) => void] { | ||
const setState = (newState: Partial<S>) => useState[1]((preState) => ({ ...preState, ...newState })); | ||
return [useState[0], setState]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function randomId() { | ||
return Math.random().toString(16).slice(2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
interface RepeatProps<T> { | ||
variable: T, | ||
repeat: number, | ||
func: (variable: T) => T, | ||
components: (variable: T) => React.ReactNode, | ||
} | ||
|
||
export default function Repeat<T>({ variable, repeat, func, components }: RepeatProps<T>) { | ||
const array = new Array(repeat).fill(null); | ||
array.forEach((_, i) => { | ||
array[i] = components(variable); | ||
variable = func(variable); | ||
}); | ||
return <>{array}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import ItemStyles from '@/styles/Item.module.scss'; | ||
import { studentsJson } from './students/students'; | ||
import { getStudentInfo } from './students/infoStudents'; | ||
|
||
interface StudentProps { | ||
id: number, | ||
allInfo: studentsJson, | ||
onClick: React.MouseEventHandler<HTMLDivElement>, | ||
select: boolean, | ||
onError: (id: number) => void, | ||
} | ||
|
||
export default function Student({ id, allInfo, onClick, select, onError }: StudentProps) { | ||
const info = getStudentInfo(allInfo, id); | ||
return ( | ||
<div onClick={onClick} style={{ backgroundColor: select ? '#dce5ec' : '#f3f7f8' }} title={`id:${id}`}> | ||
<div className={ItemStyles.img}> | ||
<img | ||
className={ItemStyles.col} | ||
src={`https://schale.gg/images/student/collection/${info.schale?.CollectionTexture}.webp`} | ||
alt={`${info.schale?.Name} collection image`} | ||
onError={_ => onError(id)} | ||
/> | ||
</div> | ||
<div className={ItemStyles.p}> | ||
<p className={ItemStyles.name}>{info.schale?.Name}</p> | ||
<p className={ItemStyles.info}>{info.file?.info}</p> | ||
</div> | ||
<div className={ItemStyles.line} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import React from "react"; | ||
import Repeat from "./repeat"; | ||
import { useClassState } from './extraReact'; | ||
import randomId from "./randomId"; | ||
|
||
interface WindowProps<C> { | ||
/**标题 */ | ||
title: string; | ||
/**关闭窗口时调用的函数 */ | ||
closeWindow: () => C; | ||
/**窗口渲染的元素 */ | ||
element: (closeWindow: () => C) => React.ReactNode; | ||
/**窗口zIndex */ | ||
zIndex: number; | ||
/**窗口是否显示 */ | ||
display: boolean; | ||
} | ||
|
||
interface WindowTypeAll { | ||
name: string, | ||
id: string, | ||
display: boolean, | ||
arg: any | ||
} | ||
|
||
type WindowTypeComArg<A> = ( | ||
zIndex: number, | ||
id: string, | ||
display: boolean, | ||
arg: A, | ||
all: AllWindow['all'] | ||
) => React.ReactNode; | ||
|
||
export interface AllWindow { | ||
all?: WindowTypeAll[]; | ||
component?: { | ||
[x: string]: WindowTypeComArg<any> | ||
}; | ||
} | ||
|
||
export default class Window<A> { | ||
name: string; | ||
|
||
constructor(name: string) { | ||
this.name = name; | ||
} | ||
|
||
Component<C>({ closeWindow, element, zIndex, display, title }: WindowProps<C>) { | ||
return (<> | ||
{display && ( | ||
<div className='ask' style={{ zIndex }}> | ||
<div className='up'> | ||
<h2>{title}</h2> | ||
<p onClick={_ => closeWindow()}>x</p> | ||
</div> | ||
<div | ||
className='element' | ||
children={element(closeWindow)} | ||
/> | ||
</div> | ||
)} | ||
</>); | ||
} | ||
} | ||
|
||
export function AllWindows({ zIndex, allWindow }: { | ||
zIndex: number, | ||
allWindow: AllWindow | ||
}) { | ||
if (allWindow.all?.length !== 0) | ||
return (<> | ||
<Repeat | ||
variable={0} | ||
repeat={allWindow.all?.length || 0} | ||
func={v => v + 1} | ||
components={v => { | ||
if (allWindow.component && allWindow.all) | ||
return ( | ||
<React.Fragment key={allWindow.all[v].id}> | ||
<div className='back' style={{ zIndex: zIndex + (2 * v) }} /> | ||
{allWindow.component[allWindow.all[v].name]( | ||
zIndex + 1 + (2 * v), | ||
allWindow.all[v].id, | ||
allWindow.all[v].display, | ||
allWindow.all[v].arg, | ||
allWindow.all | ||
)} | ||
</React.Fragment> | ||
); | ||
}} | ||
/> | ||
</>); | ||
return null; | ||
} | ||
|
||
export function getWindowFun( | ||
useState: [AllWindow, React.Dispatch<React.SetStateAction<AllWindow>>] | ||
) { | ||
const [allWindow, setAllWindow] = useClassState(useState); | ||
function addNewWindow<A>( | ||
window: Window<A>, | ||
Component: WindowTypeComArg<A> | ||
) { | ||
let component = allWindow.component || {}; | ||
component[window.name] = Component; | ||
return setAllWindow({ component }); | ||
}; | ||
function openWindow<A>(all: AllWindow['all'], window: Window<A>, arg: A) { | ||
const { name } = window; | ||
all?.push({ name, id: randomId(), display: true, arg }); | ||
setAllWindow({ all }); | ||
}; | ||
const closeWindow = (all: AllWindow['all'], id: string) => { | ||
all = all?.filter(v => v.id !== id); | ||
setAllWindow({ all }); | ||
}; | ||
return { allWindow, setAllWindow, addNewWindow, openWindow, closeWindow }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.