Merge pull request #34 from bitfeed-project/tiny-screens

Support for tiny screens
This commit is contained in:
Mononaut 2022-03-09 20:56:04 +00:00 committed by GitHub
commit 058cbb70a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 40 deletions

View File

@ -4,13 +4,6 @@
import config from './config.js' import config from './config.js'
import { settings } from './stores.js' import { settings } from './stores.js'
if (URL) {
const queryParams = (new URL(document.location)).searchParams
if (queryParams.get('noTrack') != null) {
$settings.noTrack = true
}
}
if (!$settings.noTrack && config.public) analytics.init() if (!$settings.noTrack && config.public) analytics.init()
</script> </script>

View File

@ -56,6 +56,10 @@ function showBlock () {
flex-direction: column-reverse; flex-direction: column-reverse;
justify-content: flex-start; justify-content: flex-start;
align-items: flex-start; align-items: flex-start;
@media (max-width: 480px) and (max-height: 480px) {
display: none;
}
} }
</style> </style>

View File

@ -3,7 +3,7 @@
import TxController from '../controllers/TxController.js' import TxController from '../controllers/TxController.js'
import TxRender from './TxRender.svelte' import TxRender from './TxRender.svelte'
import getTxStream from '../controllers/TxStream.js' import getTxStream from '../controllers/TxStream.js'
import { settings, overlay, serverConnected, serverDelay, txCount, mempoolCount, mempoolScreenHeight, frameRate, avgFrameRate, blockVisible, currentBlock, selectedTx, blockAreaSize, devEvents, devSettings } from '../stores.js' import { settings, overlay, serverConnected, serverDelay, txCount, mempoolCount, mempoolScreenHeight, frameRate, avgFrameRate, blockVisible, tinyScreen, currentBlock, selectedTx, blockAreaSize, devEvents, devSettings } from '../stores.js'
import BlockInfo from '../components/BlockInfo.svelte' import BlockInfo from '../components/BlockInfo.svelte'
import TxInfo from '../components/TxInfo.svelte' import TxInfo from '../components/TxInfo.svelte'
import Sidebar from '../components/Sidebar.svelte' import Sidebar from '../components/Sidebar.svelte'
@ -74,8 +74,6 @@
$devEvents.addOneCallback = fakeTx $devEvents.addOneCallback = fakeTx
$devEvents.addManyCallback = fakeTxs $devEvents.addManyCallback = fakeTxs
$devEvents.addBlockCallback = fakeBlock $devEvents.addBlockCallback = fakeBlock
if (!$settings.showMessages) $settings.showMessages = true
}) })
function resize () { function resize () {
@ -88,6 +86,12 @@
height height
}) })
} }
const aspectRatio = window.innerWidth / window.innerHeight
if ((aspectRatio >= 1 && window.innerWidth < 480) || (aspectRatio <= 1 && window.innerHeight < 480)) {
$tinyScreen = true
} else {
$tinyScreen = false
}
} }
function changedMode () { function changedMode () {
@ -226,17 +230,19 @@
left: 0.5rem; left: 0.5rem;
font-size: 0.9rem; font-size: 0.9rem;
color: var(--palette-x); color: var(--palette-x);
}
// &::before { .mempool-info {
// content: ''; position: absolute;
// position: absolute; bottom: .5em;
// left: 0; left: 0.5rem;
// top: 0; right: 0.5em;
// right: 0; font-size: 0.9rem;
// bottom: 0; color: var(--palette-x);
// background: var(--palette-b); display: flex;
// opacity: 0.5; flex-direction: row;
// } justify-content: space-between;
align-items: baseline;
} }
.height-bar { .height-bar {
@ -277,6 +283,11 @@
text-align: left; text-align: left;
padding: 1rem; padding: 1rem;
flex-shrink: 0; flex-shrink: 0;
box-sizing: border-box;
.row {
margin-bottom: 5px;
}
.status-light { .status-light {
display: inline-block; display: inline-block;
@ -296,7 +307,6 @@
} }
.stat-counter, .fx-ticker { .stat-counter, .fx-ticker {
margin-top: 5px;
white-space: nowrap; white-space: nowrap;
cursor: pointer; cursor: pointer;
@ -310,6 +320,21 @@
color: var(--palette-good); color: var(--palette-good);
} }
} }
.block-height {
margin-bottom: 5px;
color: white;
}
&.tiny {
width: 100%;
.row {
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
}
}
} }
} }
@ -399,14 +424,21 @@
<div class="mempool-height" style="bottom: calc({$mempoolScreenHeight + 20}px)"> <div class="mempool-height" style="bottom: calc({$mempoolScreenHeight + 20}px)">
<div class="height-bar" /> <div class="height-bar" />
<span class="mempool-count">Mempool: { numberFormat.format(Math.round($mempoolCount)) } unconfirmed</span> {#if $tinyScreen}
<div class="mempool-info">
<span class="left">Mempool</span>
<span class="right">{ numberFormat.format(Math.round($mempoolCount)) }</span>
</div>
{:else}
<span class="mempool-count">Mempool: { numberFormat.format(Math.round($mempoolCount)) } unconfirmed</span>
{/if}
</div> </div>
<div class="block-area-wrapper"> <div class="block-area-wrapper">
<div class="spacer"></div> <div class="spacer"></div>
<div class="block-area-outer" style="width: {$blockAreaSize}px; height: {$blockAreaSize}px"> <div class="block-area-outer" style="width: {$blockAreaSize}px; height: {$blockAreaSize}px">
<div class="block-area"> <div class="block-area">
<BlockInfo block={$currentBlock} visible={$blockVisible} on:hideBlock={hideBlock} /> <BlockInfo block={$currentBlock} visible={$blockVisible && !$tinyScreen} on:hideBlock={hideBlock} />
</div> </div>
{#if config.dev && config.debug && $devSettings.guides } {#if config.dev && config.debug && $devSettings.guides }
<div class="guide-area" /> <div class="guide-area" />
@ -422,11 +454,14 @@
{/if} {/if}
<div class="top-bar"> <div class="top-bar">
<div class="status"> <div class="status" class:tiny={$tinyScreen}>
<div class="row"> <div class="row">
{#if $settings.showFX && fxLabel } {#if $settings.showFX && fxLabel }
<span class="fx-ticker {fxColor}" on:click={() => { $sidebarToggle = 'settings'}}>{ fxLabel }</span> <span class="fx-ticker {fxColor}" on:click={() => { $sidebarToggle = 'settings'}}>{ fxLabel }</span>
{/if} {/if}
{#if $tinyScreen && $currentBlock }
<span class="block-height"><b>Block: </b>{ numberFormat.format($currentBlock.height) }</span>
{/if}
</div> </div>
<div class="row"> <div class="row">
{#if $settings.showNetworkStatus } {#if $settings.showNetworkStatus }
@ -435,7 +470,7 @@
</div> </div>
</div> </div>
<div class="spacer" /> <div class="spacer" />
{#if config.messagesEnabled && $settings.showMessages } {#if config.messagesEnabled && $settings.showMessages && !$tinyScreen }
<Alerts /> <Alerts />
{/if} {/if}
</div> </div>

View File

@ -107,8 +107,6 @@ export default class TxController {
return return
} }
this.poolScene.scrollLock = true
const block = new BitcoinBlock(blockData) const block = new BitcoinBlock(blockData)
this.knownBlocks[block.id] = true this.knownBlocks[block.id] = true
if (this.clearBlockTimeout) clearTimeout(this.clearBlockTimeout) if (this.clearBlockTimeout) clearTimeout(this.clearBlockTimeout)
@ -142,9 +140,10 @@ export default class TxController {
this.blockScene.initialLayout() this.blockScene.initialLayout()
setTimeout(() => { this.poolScene.scrollLock = false; this.poolScene.layoutAll() }, 4000) setTimeout(() => { this.poolScene.scrollLock = false; this.poolScene.layoutAll() }, 4000)
currentBlock.set(block)
blockVisible.set(true) blockVisible.set(true)
currentBlock.set(block)
return block return block
} }

View File

@ -19,19 +19,22 @@ function createCounter () {
} }
} }
function createCachedDict (namespace, defaultValues) { function createCachedDict (namespace, setValues, defaultValues) {
const initial = { const initial = {
...defaultValues ...defaultValues
} }
// load from local storage
Object.keys(initial).forEach(field => { Object.keys(initial).forEach(field => {
const val = localStorage.getItem(`${namespace}-${field}`) // fields take setValues first, then fall back to cached values, then defaults
if (val != null) { if (setValues[field] != null) initial[field] = setValues[field]
try { else {
initial[field] = JSON.parse(val) const val = localStorage.getItem(`${namespace}-${field}`)
} catch (e) { if (val != null) {
initial[field] = val try {
initial[field] = JSON.parse(val)
} catch (e) {
initial[field] = val
}
} }
} }
}) })
@ -96,7 +99,7 @@ export const settingsOpen = writable(false)
let localeCurrencyCode = LocaleCurrency.getCurrency(navigator.language) let localeCurrencyCode = LocaleCurrency.getCurrency(navigator.language)
if (!currencies[localeCurrencyCode]) localeCurrencyCode = 'USD' if (!currencies[localeCurrencyCode]) localeCurrencyCode = 'USD'
export const settings = createCachedDict('settings', { const defaultSettings = {
darkMode: true, darkMode: true,
showNetworkStatus: true, showNetworkStatus: true,
currency: localeCurrencyCode, currency: localeCurrencyCode,
@ -105,13 +108,28 @@ export const settings = createCachedDict('settings', {
colorByFee: false, colorByFee: false,
fancyGraphics: true, fancyGraphics: true,
showMessages: true, showMessages: true,
noTrack: false noTrack: false,
}) }
const searchParams = URL ? (new URL(document.location)).searchParams : {}
const urlSettings = Object.keys(defaultSettings).reduce((map, key) => {
const param = searchParams.get(key)
if (param != null) {
if (param.toLowerCase() === 'false') map[key] = false
else map[key] = param
}
return map
}, {})
if (urlSettings.showMessages == null) urlSettings.showMessages = true
export const settings = createCachedDict('settings', urlSettings, defaultSettings)
export const colorMode = derived([settings], ([$settings]) => { export const colorMode = derived([settings], ([$settings]) => {
return $settings.colorByFee ? "fee" : "age" return $settings.colorByFee ? "fee" : "age"
}) })
export const devSettings = (config.dev && config.debug) ? createCachedDict('dev-settings', { export const devSettings = (config.dev && config.debug) ? createCachedDict('dev-settings', {}, {
guides: false, guides: false,
layoutHints: false, layoutHints: false,
}) : writable({}) }) : writable({})
@ -127,3 +145,7 @@ export const overlay = writable(null)
export const highlight = writable([]) export const highlight = writable([])
export const newHighlightQuery = writable(null) export const newHighlightQuery = writable(null)
export const highlightingFull = writable(false) export const highlightingFull = writable(false)
const aspectRatio = window.innerWidth / window.innerHeight
let isTinyScreen = (window.innerWidth < 480 && window.innerHeight < 480)
export const tinyScreen = writable(isTinyScreen)