2022-05-10 13:52:06 +00:00
|
|
|
import { h } from 'preact';
|
2022-06-05 17:57:04 +00:00
|
|
|
import { useCallback, useState } from 'preact/hooks';
|
2022-05-10 13:52:06 +00:00
|
|
|
import cs from 'classnames';
|
|
|
|
import Disk2 from '../cards/disk2';
|
2022-06-01 00:41:24 +00:00
|
|
|
import { ErrorModal } from './ErrorModal';
|
2022-06-05 17:57:04 +00:00
|
|
|
import { FileModal } from './FileModal';
|
2022-05-10 13:52:06 +00:00
|
|
|
|
2022-06-03 22:30:39 +00:00
|
|
|
import styles from './css/DiskII.module.css';
|
|
|
|
|
2022-05-10 13:52:06 +00:00
|
|
|
/**
|
|
|
|
* Storage structure for Disk II state returned via callbacks.
|
|
|
|
*/
|
|
|
|
export interface DiskIIData {
|
|
|
|
number: 1 | 2;
|
|
|
|
on: boolean;
|
2022-05-12 00:20:49 +00:00
|
|
|
name: string;
|
|
|
|
side?: string | undefined;
|
2022-05-10 13:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for Disk II component.
|
|
|
|
*/
|
|
|
|
export interface DiskIIProps extends DiskIIData {
|
|
|
|
disk2: Disk2 | undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disk II component
|
|
|
|
*
|
|
|
|
* Includes drive light, disk name and side, and UI for loading disks.
|
|
|
|
*
|
|
|
|
* @param disk2 Disk2 object
|
|
|
|
* @param number Drive 1 or 2
|
|
|
|
* @param on Active state
|
|
|
|
* @param name Disk name identifier
|
|
|
|
* @param side Disk side identifier
|
|
|
|
* @returns DiskII component
|
|
|
|
*/
|
|
|
|
export const DiskII = ({ disk2, number, on, name, side }: DiskIIProps) => {
|
|
|
|
const label = side ? `${name} - ${side}` : name;
|
|
|
|
const [modalOpen, setModalOpen] = useState(false);
|
2022-06-01 13:28:05 +00:00
|
|
|
const [error, setError] = useState<unknown>();
|
2022-05-10 13:52:06 +00:00
|
|
|
|
|
|
|
const doClose = useCallback(() => {
|
|
|
|
setModalOpen(false);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const onOpenModal = useCallback(() => {
|
|
|
|
setModalOpen(true);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2022-06-03 22:30:39 +00:00
|
|
|
<div className={styles.disk}>
|
2022-05-10 13:52:06 +00:00
|
|
|
<FileModal disk2={disk2} number={number} onClose={doClose} isOpen={modalOpen} />
|
2022-06-01 00:41:24 +00:00
|
|
|
<ErrorModal error={error} setError={setError} />
|
2022-06-04 18:38:59 +00:00
|
|
|
<div className={cs(styles.diskLight, { [styles.on]: on })} />
|
2022-06-04 21:31:57 +00:00
|
|
|
<button title="Load Disk" onClick={onOpenModal}>
|
|
|
|
<i className="fas fa-folder-open" />
|
2022-05-10 13:52:06 +00:00
|
|
|
</button>
|
2022-06-03 22:30:39 +00:00
|
|
|
<div className={styles.diskLabel}>
|
2022-05-10 13:52:06 +00:00
|
|
|
{label}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|