[Update/Refactor] Plugins: Organize codes.
This commit is contained in:
@@ -3,14 +3,12 @@ import { SwitchBox } from "../index";
|
|||||||
import { _DownloadButton } from "../_atoms/_download_button/_DownloadButton";
|
import { _DownloadButton } from "../_atoms/_download_button/_DownloadButton";
|
||||||
import styles from "./PluginsControlComponent.module.scss";
|
import styles from "./PluginsControlComponent.module.scss";
|
||||||
|
|
||||||
// メインのコントロールコンポーネント。ダウンロード済み / 未ダウンロードで分岐して表示する
|
|
||||||
export const PluginsControlComponent = ({
|
export const PluginsControlComponent = ({
|
||||||
variable_state,
|
variable_state,
|
||||||
plugin_status,
|
plugin_status,
|
||||||
toggleFunction,
|
toggleFunction,
|
||||||
downloadStartFunction,
|
downloadStartFunction,
|
||||||
}) => {
|
}) => {
|
||||||
// 共通オプション(各子コンポーネントに引き回す情報)
|
|
||||||
const option = {
|
const option = {
|
||||||
id: plugin_status.plugin_id,
|
id: plugin_status.plugin_id,
|
||||||
is_pending: plugin_status.is_pending,
|
is_pending: plugin_status.is_pending,
|
||||||
@@ -41,84 +39,53 @@ export const PluginsControlComponent = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
// ダウンロード済みのプラグイン用コンポーネント
|
|
||||||
// 状態により以下の分岐を行う
|
|
||||||
// ・ is_latest_version_already が true なら「最新版を使用中」
|
|
||||||
// ・ is_latest_version_already が false かつ is_latest_version_available が true なら「最新版を利用可能」(アップデートボタン+スイッチ)
|
|
||||||
// ・ それ以外(is_latest_version_already:false && is_latest_version_available: false)なら、desc等の情報とスイッチのみ表示
|
|
||||||
const DownloadedPluginControl = ({
|
const DownloadedPluginControl = ({
|
||||||
option,
|
option,
|
||||||
plugin_status,
|
plugin_status,
|
||||||
toggleFunction,
|
toggleFunction,
|
||||||
downloadStartFunction,
|
downloadStartFunction,
|
||||||
}) => {
|
}) => {
|
||||||
// on/off トグル時の処理
|
|
||||||
const togglePlugin = () => {
|
const togglePlugin = () => {
|
||||||
toggleFunction(plugin_status.plugin_id);
|
toggleFunction(plugin_status.plugin_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const latest_version = plugin_status.latest_plugin_info?.plugin_version;
|
||||||
|
|
||||||
// ダウンロード済みの場合、ダウンロードされた情報からタイトルやバージョンを取得
|
|
||||||
const title = plugin_status.downloaded_plugin_info?.title || plugin_status.latest_plugin_info.title;
|
|
||||||
const current_version =
|
|
||||||
plugin_status.downloaded_plugin_info?.plugin_version || plugin_status.latest_plugin_info.plugin_version;
|
|
||||||
|
|
||||||
// コンポーネントごとに表示内容を分岐
|
|
||||||
if (plugin_status.is_latest_version_already) {
|
if (plugin_status.is_latest_version_already) {
|
||||||
// 最新版が既に使用中
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<p>{title}</p>
|
<p>最新のバージョン: {latest_version}</p>
|
||||||
<p>現在のバージョン: {current_version}</p>
|
|
||||||
<p>最新版を使用中</p>
|
<p>最新版を使用中</p>
|
||||||
<SwitchBox variable={option} toggleFunction={togglePlugin} />
|
<SwitchBox variable={option} toggleFunction={togglePlugin} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if (plugin_status.is_latest_version_available) {
|
} else if (plugin_status.is_latest_version_available) {
|
||||||
// 最新版の利用可能なお知らせとアップデートボタン+スイッチ
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<p>{title}</p>
|
<p>最新のバージョン: {latest_version}</p>
|
||||||
<p>現在のバージョン: {current_version}</p>
|
|
||||||
<p>最新版を利用可能</p>
|
<p>最新版を利用可能</p>
|
||||||
<_DownloadButton option={option} downloadStartFunction={downloadStartFunction} />
|
<_DownloadButton option={option} downloadStartFunction={downloadStartFunction} />
|
||||||
<SwitchBox variable={option} toggleFunction={togglePlugin} />
|
<SwitchBox variable={option} toggleFunction={togglePlugin} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// 最新版利用可能ではないがダウンロード済み
|
|
||||||
// ※「desc」に関しては、情報があればplugin_status.descやlatest_plugin_info.descを利用してください
|
|
||||||
const desc =
|
|
||||||
plugin_status.latest_plugin_info.desc ||
|
|
||||||
"追加情報がありません。";
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<p>{title}</p>
|
<p>最新のバージョン: {latest_version}</p>
|
||||||
<p>現在のバージョン: {current_version}</p>
|
|
||||||
<p>{desc}</p>
|
|
||||||
<SwitchBox variable={option} toggleFunction={togglePlugin} />
|
<SwitchBox variable={option} toggleFunction={togglePlugin} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
// 未ダウンロードのプラグイン用コンポーネント
|
|
||||||
// 状態により以下の分岐を行う
|
|
||||||
// ・ is_latest_version_available が true なら:info_title, 最新バージョン情報とダウンロードボタン
|
|
||||||
// ・ is_latest_version_available が false なら:info_title, 最新バージョン情報と「現在利用不可」
|
|
||||||
const NotDownloadedPluginControl = ({ option, plugin_status, downloadStartFunction }) => {
|
const NotDownloadedPluginControl = ({ option, plugin_status, downloadStartFunction }) => {
|
||||||
const title = plugin_status.latest_plugin_info.title;
|
|
||||||
const latest_version = plugin_status.latest_plugin_info.plugin_version;
|
const latest_version = plugin_status.latest_plugin_info.plugin_version;
|
||||||
// ※未ダウンロードの場合、current_versionは「未ダウンロード」や「なし」といった扱いとする
|
|
||||||
const current_version = "未ダウンロード";
|
|
||||||
|
|
||||||
if (plugin_status.is_latest_version_available) {
|
if (plugin_status.is_latest_version_available) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<p>{title}</p>
|
|
||||||
<p>現在のバージョン: {current_version}</p>
|
|
||||||
<p>最新バージョン: {latest_version}</p>
|
<p>最新バージョン: {latest_version}</p>
|
||||||
<_DownloadButton option={option} downloadStartFunction={downloadStartFunction} />
|
<_DownloadButton option={option} downloadStartFunction={downloadStartFunction} />
|
||||||
</div>
|
</div>
|
||||||
@@ -126,8 +93,6 @@ const NotDownloadedPluginControl = ({ option, plugin_status, downloadStartFuncti
|
|||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<p>{title}</p>
|
|
||||||
<p>現在のバージョン: {current_version}</p>
|
|
||||||
<p>最新バージョン: {latest_version}</p>
|
<p>最新バージョン: {latest_version}</p>
|
||||||
<p>現在利用不可</p>
|
<p>現在利用不可</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -79,20 +79,19 @@ const PluginDownloadContainer = () => {
|
|||||||
<div key={plugin.plugin_id} className={styles.plugin_wrapper}>
|
<div key={plugin.plugin_id} className={styles.plugin_wrapper}>
|
||||||
<p className={styles.title}>
|
<p className={styles.title}>
|
||||||
{plugin.is_downloaded
|
{plugin.is_downloaded
|
||||||
? plugin.downloaded_plugin_info?.title || plugin.latest_plugin_info.title
|
? plugin.downloaded_plugin_info?.title
|
||||||
: plugin.latest_plugin_info.title}
|
: plugin.latest_plugin_info?.title}
|
||||||
</p>
|
</p>
|
||||||
<p className={styles.plugin_id}>{plugin.plugin_id}</p>
|
<p className={styles.plugin_id}>{plugin.plugin_id}</p>
|
||||||
{plugin.error ? (
|
{plugin.is_error ? (
|
||||||
<p style={{ color: "red" }}>Error: {plugin.error}</p>
|
<p style={{ color: "red" }}>Error: {plugin.error_message}</p>
|
||||||
) : (
|
) : (
|
||||||
<div className={styles.plugin_info_wrapper}>
|
<div className={styles.plugin_info_wrapper}>
|
||||||
<div className={styles.plugin_info}>
|
<div className={styles.plugin_info}>
|
||||||
{/* 状態に応じた情報表示(例:バージョン等) */}
|
|
||||||
<p>
|
<p>
|
||||||
{plugin.is_downloaded
|
{plugin.is_downloaded
|
||||||
? `現在のバージョン: ${plugin.downloaded_plugin_info?.plugin_version}`
|
? `現在のバージョン: ${plugin.downloaded_plugin_info?.plugin_version}`
|
||||||
: `最新バージョン: ${plugin.latest_plugin_info.plugin_version}`}
|
: null}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<PluginsControlComponent
|
<PluginsControlComponent
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export const usePlugins = () => {
|
|||||||
const prev_map = new Map(prev.data.map(item => [item.plugin_id, item]));
|
const prev_map = new Map(prev.data.map(item => [item.plugin_id, item]));
|
||||||
const new_data = [];
|
const new_data = [];
|
||||||
let new_value = {};
|
let new_value = {};
|
||||||
|
const { is_plugin_supported, is_plugin_supported_latest_vrct } = checkVrctVerCompatibility(downloaded_plugin_info.min_supported_vrct_version, downloaded_plugin_info.max_supported_vrct_version);
|
||||||
|
|
||||||
if (!prev_map.has(downloaded_plugin_info.plugin_id)) { // 未ダウンロード 新規登録
|
if (!prev_map.has(downloaded_plugin_info.plugin_id)) { // 未ダウンロード 新規登録
|
||||||
new_value = {
|
new_value = {
|
||||||
@@ -67,9 +68,8 @@ export const usePlugins = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const old_plugin_data of prev.data) {
|
for (const old_plugin_data of prev.data) {
|
||||||
const { is_plugin_supported, is_plugin_supported_latest_vrct } = checkVrctVerCompatibility(downloaded_plugin_info.min_supported_vrct_version, downloaded_plugin_info.max_supported_vrct_version);
|
|
||||||
|
|
||||||
if (prev_map.has(downloaded_plugin_info.plugin_id) && old_plugin_data.plugin_id === downloaded_plugin_info.plugin_id) { // ダウンロード済み
|
if (prev_map.has(downloaded_plugin_info.plugin_id) && old_plugin_data.plugin_id === downloaded_plugin_info.plugin_id) { // ダウンロード済み アップデート
|
||||||
|
|
||||||
|
|
||||||
const target_prev_plugin = prev_map.get(downloaded_plugin_info.plugin_id);
|
const target_prev_plugin = prev_map.get(downloaded_plugin_info.plugin_id);
|
||||||
@@ -262,7 +262,7 @@ export const usePlugins = () => {
|
|||||||
title: plugin_data.title,
|
title: plugin_data.title,
|
||||||
plugin_id: plugin_data.plugin_id || plugin_data.title,
|
plugin_id: plugin_data.plugin_id || plugin_data.title,
|
||||||
is_error: true,
|
is_error: true,
|
||||||
error: error.message,
|
error_message: error.message,
|
||||||
url: plugin_data.url
|
url: plugin_data.url
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user