From 489bf41f6aab5dd6f223c4d7062f79c9122349a2 Mon Sep 17 00:00:00 2001 From: Daniel Shleifman Date: Mon, 23 Aug 2021 15:14:39 +0300 Subject: [PATCH] DebugMode toggle added --- .../DetailedView/index.jsx | 25 +++++++++++++++++-- .../TorrentCache/index.jsx | 11 ++++---- web/src/locales/en/translation.json | 1 + web/src/locales/ru/translation.json | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx b/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx index 4222d7d..5dc8e2b 100644 --- a/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx +++ b/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx @@ -1,4 +1,6 @@ import { useTranslation } from 'react-i18next' +import { Checkbox, FormControlLabel } from '@material-ui/core' +import { useState } from 'react' import { SectionTitle, WidgetWrapper } from '../style' import { DetailedViewCacheSection, DetailedViewWidgetSection } from './style' @@ -24,6 +26,9 @@ export default function DetailedView({ cache, }) { const { t } = useTranslation() + const [isSnakeDebugMode, setIsSnakeDebugMode] = useState( + JSON.parse(localStorage.getItem('isSnakeDebugMode')) || false, + ) return ( <> @@ -43,9 +48,25 @@ export default function DetailedView({ - {t('Cache')} +
+ {t('Cache')} + + { + setIsSnakeDebugMode(checked) + localStorage.setItem('isSnakeDebugMode', checked) + }} + /> + } + label={t('DebugMode')} + /> +
- + +
) diff --git a/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx b/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx index 99af7c9..ba21254 100644 --- a/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx +++ b/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx @@ -10,7 +10,7 @@ import getShortCacheMap from './getShortCacheMap' import { SnakeWrapper, ScrollNotification } from './style' import { createGradient, snakeSettings } from './snakeSettings' -const TorrentCache = ({ cache, isMini }) => { +const TorrentCache = ({ cache, isMini, isSnakeDebugMode }) => { const { t } = useTranslation() const [dimensions, setDimensions] = useState({ width: 0, height: 0 }) const { width } = dimensions @@ -91,16 +91,16 @@ const TorrentCache = ({ cache, isMini }) => { ctx.strokeRect(0, 0, pieceSize, pieceSize) ctx.setTransform(1, 0, 0, 1, 0, 0) - if (priority > 0) { + if (!isMini && isSnakeDebugMode && priority > 0) { let info = '' if (priority === 1) info = '*' else if (priority === 2) info = 'H' else if (priority === 3) info = 'R' else if (priority === 4) info = 'N' else if (priority === 5) info = 'A' - ctx.font = isMini ? '12px monospace' : '10px monospace' - const xpad = isMini ? pieceSize * 0.34 : pieceSize * 0.28 - const ypad = isMini ? pieceSize * 0.69 : pieceSize * 0.78 + ctx.font = '10px monospace' + const xpad = pieceSize * 0.28 + const ypad = pieceSize * 0.78 ctx.fillStyle = 'black' ctx.fillText(info, x + xpad, y + ypad) } @@ -123,6 +123,7 @@ const TorrentCache = ({ cache, isMini }) => { rangeColor, isMini, theme, + isSnakeDebugMode, ]) return ( diff --git a/web/src/locales/en/translation.json b/web/src/locales/en/translation.json index 2913290..b2eb3c9 100644 --- a/web/src/locales/en/translation.json +++ b/web/src/locales/en/translation.json @@ -33,6 +33,7 @@ "CopyHash": "Copy Hash", "CopyLink": "Copy link", "Data": "Data", + "DebugMode": "Debug mode", "Delete": "Delete", "DeleteTorrent?": "Delete Torrent?", "DeleteTorrents?": "Delete All Torrents?", diff --git a/web/src/locales/ru/translation.json b/web/src/locales/ru/translation.json index a344d3f..6208c40 100644 --- a/web/src/locales/ru/translation.json +++ b/web/src/locales/ru/translation.json @@ -33,6 +33,7 @@ "CopyHash": "Скопировать хеш", "CopyLink": "Копировать", "Data": "Данные", + "DebugMode": "Режим отладки", "Delete": "Удалить", "DeleteTorrent?": "Удалить торрент?", "DeleteTorrents?": "Удалить все торренты?",