Skip to content

Commit c965aa5

Browse files
author
web3blind
committed
Preserve chronicle draft text
1 parent fbc5a63 commit c965aa5

5 files changed

Lines changed: 25 additions & 7 deletions

File tree

app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
<script src="js/ui/screens/character.js?v=20260713b"></script>
195195
<script src="js/ui/screens/hunt.js?v=20260713d"></script>
196196
<script src="js/ui/screens/inventory.js?v=20260713a"></script>
197-
<script src="js/ui/screens/chronicle.js?v=20260712a"></script>
197+
<script src="js/ui/screens/chronicle.js?v=20260713a"></script>
198198
<script src="js/ui/screens/duel.js"></script>
199199
<script src="js/ui/screens/arena.js?v=20260621d"></script>
200200
<script src="js/ui/screens/guild.js?v=20260621l"></script>

app/js/ui/screens/chronicle.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var ChronicleScreen = (function() {
1212
var currentTab = 'all'; // all, guild, friends, world
1313
var REQUIRED_TAG = '#viz_magic';
1414
var cachedFeedHtml = {};
15+
var DRAFT_KEY = VizMagicConfig.STORAGE_PREFIX + 'chronicle_draft';
1516

1617
function render() {
1718
var t = Helpers.t;
@@ -34,7 +35,7 @@ var ChronicleScreen = (function() {
3435
'<textarea id="chronicle-input" class="input-field" rows="3" ' +
3536
'maxlength="' + MAX_POST_LENGTH + '" ' +
3637
'placeholder="' + t('chronicle_placeholder') + '" ' +
37-
'aria-label="' + t('chronicle_write') + '"></textarea>' +
38+
'aria-label="' + t('chronicle_write') + '">' + Helpers.escapeHtml(_getDraft()) + '</textarea>' +
3839
'<div class="chronicle-compose-footer">' +
3940
'<span id="chronicle-char-count" class="chronicle-char-count" aria-live="polite">0/' + MAX_POST_LENGTH + '</span>' +
4041
'<button class="btn btn-primary" id="btn-chronicle-send">' + t('chronicle_send') + '</button>' +
@@ -53,6 +54,14 @@ var ChronicleScreen = (function() {
5354
_loadFeed();
5455
}
5556

57+
function _getDraft() {
58+
try { return localStorage.getItem(DRAFT_KEY) || ''; } catch (e) { return ''; }
59+
}
60+
61+
function _setDraft(text) {
62+
try { localStorage.setItem(DRAFT_KEY, text || ''); } catch (e) {}
63+
}
64+
5665
function _tabButton(id, label) {
5766
var isActive = currentTab === id;
5867
return '<button class="btn ' + (isActive ? 'btn-primary' : 'btn-secondary') + ' btn-sm chronicle-tab-btn" ' +
@@ -76,6 +85,7 @@ var ChronicleScreen = (function() {
7685
var counter = Helpers.$('chronicle-char-count');
7786
if (input && counter) {
7887
input.addEventListener('input', function() {
88+
_setDraft(this.value);
7989
var len = this.value.length;
8090
counter.textContent = len + '/' + MAX_POST_LENGTH;
8191
if (len > MAX_POST_LENGTH) {
@@ -100,6 +110,7 @@ var ChronicleScreen = (function() {
100110
_injectLocalPost(text);
101111
Toast.success('\u2728 ' + Helpers.t('chronicle_send'));
102112
Helpers.$('chronicle-input').value = '';
113+
_setDraft('');
103114
Helpers.$('chronicle-char-count').textContent = '0/' + MAX_POST_LENGTH;
104115
_loadFeed();
105116
}

app/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"short_name": "VizMagic",
44
"description": "Viz Magic — accessible browser RPG on the VIZ blockchain",
55
"id": "https://vizmagic.web3blind.xyz/",
6-
"start_url": "/?pwa=viz-magic-v57",
6+
"start_url": "/?pwa=viz-magic-v58",
77
"scope": "/",
88
"display": "standalone",
99
"display_override": ["standalone", "minimal-ui"],

app/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Viz Magic — Service Worker
2-
var CACHE_NAME = 'viz-magic-v57';
2+
var CACHE_NAME = 'viz-magic-v58';
33
var ASSETS = [
44
'/',
55
'/index.html',

tests/player-bug-regressions.test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ test('high-traffic UI narration, screen announcements, and inventory stat labels
348348

349349
test('service worker updates quickly and keeps navigations network-first', function () {
350350
const swJs = read('app/sw.js');
351-
assert.ok(/viz-magic-v57/.test(swJs), 'service worker cache version should be bumped');
351+
assert.ok(/viz-magic-v58/.test(swJs), 'service worker cache version should be bumped');
352352
assert.ok(/self\.skipWaiting\(\)/.test(swJs), 'service worker should activate new cache without waiting for all tabs to close');
353353
assert.ok(/self\.clients\.claim\(\)/.test(swJs), 'service worker should claim clients after activation');
354354
assert.ok(/event\.request\.mode === 'navigate'[\s\S]*fetch\(event\.request\)/.test(swJs), 'navigation requests should prefer network to avoid stale cached index');
@@ -397,7 +397,7 @@ test('mobile entry helpers cover keyboard paste, home-screen shortcut, nav parit
397397
assert.ok(/SoundManager\.setVolume\(sfxVolume \/ 100\)/.test(read('app/js/ui/screens/settings.js')), 'settings should apply stored SFX volume on render');
398398
assert.ok(/localStorage\.setItem\(STORAGE_PREFIX \+ 'sfx_volume'/.test(read('app/js/ui/sound.js')), 'sound manager should persist SFX volume');
399399
assert.ok(/var volume = _getStoredNumber\('sfx_volume', 0\.5\)/.test(read('app/js/ui/sound.js')), 'sound manager should restore persisted SFX volume');
400-
assert.ok(/viz-magic-v57/.test(read('app/sw.js')), 'service worker cache should be bumped for UI changes');
400+
assert.ok(/viz-magic-v58/.test(read('app/sw.js')), 'service worker cache should be bumped for UI changes');
401401
});
402402

403403

@@ -527,7 +527,7 @@ test('reported mobile UX issues have explicit fixes', function () {
527527

528528
test('PWA icon and HP heart use expressive color accents', function () {
529529
assert.ok(/viz-magic-192\.png\?v=20260713a/.test(indexHtml), 'PWA icon link should be cache-busted after plus placement/color update');
530-
assert.ok(/viz-magic-v57/.test(read('app/manifest.json')), 'manifest start URL should change so launchers can refresh icons');
530+
assert.ok(/viz-magic-v58/.test(read('app/manifest.json')), 'manifest start URL should change so launchers can refresh icons');
531531
assert.ok(/label:' HP'/.test(homeJs), 'HP label should use a red heart emoji variant');
532532
});
533533

@@ -676,6 +676,13 @@ test('reported ux polish issues have explicit fixes', function () {
676676
assert.ok(/matchedVoice/.test(read('app/js/ui/components/battle-narrator.js')), 'male narrator should avoid fake pitch-shift when no male browser voice exists');
677677
});
678678

679+
680+
test('chronicle draft survives rerenders while feed loads', function () {
681+
assert.ok(/chronicle.js\?v=20260713a/.test(indexHtml), 'chronicle screen should be cache-busted for draft preservation');
682+
assert.ok(/DRAFT_KEY/.test(chronicleJs), 'chronicle should keep a draft key');
683+
assert.ok(/_getDraft\(\)/.test(chronicleJs) && /_setDraft\(this\.value\)/.test(chronicleJs), 'typed chronicle text should be restored and saved during rerenders');
684+
});
685+
679686
if (process.exitCode) {
680687
process.exit(process.exitCode);
681688
}

0 commit comments

Comments
 (0)