Skip to content

Commit bdbbaaa

Browse files
committed
Save last text
1 parent 449ac1d commit bdbbaaa

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

mobile.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/components/app/app.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { prepareLocale } from '../../helpers/prepareLocale';
22
import { I18NLanguage, i18n, i18nUpdatePage, setI18nLang } from '../../i18n/i18n';
3-
import { getHashParam, isPrefsHash, resetHash, setPrefsHash, setTextHashParam } from '../../helpers/hash';
3+
import { getHashParam, isPrefsHash, resetHash, setPrefsHash } from '../../helpers/hash';
44
import { metrikaReachGoal } from '../../services/metrika';
55
import { config } from './config';
66
import { Typograf } from '../../helpers/typograf';
@@ -41,8 +41,10 @@ export class App {
4141
document.body.classList.remove('transition_no');
4242

4343
this.input = new Input({
44+
value: config.text,
4445
isMobile: this.isMobile,
4546
onChange: () => {
47+
config.text = this.input.getValue();
4648
this.execute();
4749
},
4850
});
@@ -97,7 +99,10 @@ export class App {
9799
this.prepareRules();
98100

99101
if (!this.isMobile) {
100-
this.setValue(getHashParam('text') || '');
102+
const hash = getHashParam('text');
103+
if (hash) {
104+
this.setValue(hash);
105+
}
101106
}
102107

103108
this.execute();
@@ -193,8 +198,6 @@ export class App {
193198
if (this.isMobile || this.prefs.opened()) {
194199
return;
195200
}
196-
197-
setTextHashParam(value);
198201
}
199202

200203
private handlePrefsClick = () => {

src/components/app/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class Config {
1414
private rulesInner: ConfigRules = defaultRules;
1515
private modeInner: TypografHtmlEntity['type'];
1616
private onlyInvisibleInner = false;
17+
private textInner = '';
1718

1819
constructor() {
1920
this.languageInner = myLocalStorage.getItem('settings.langUI', 'ru');
@@ -30,6 +31,7 @@ export class Config {
3031

3132
this.modeInner = myLocalStorage.getItem<TypografHtmlEntity['type']>('settings.mode', 'default');
3233
this.onlyInvisibleInner = myLocalStorage.getItem('settings.onlyInvisible', false);
34+
this.textInner = myLocalStorage.getItem('text', '');
3335
}
3436

3537
get locale() {
@@ -68,6 +70,15 @@ export class Config {
6870
myLocalStorage.setItem('settings.langUI', value);
6971
}
7072

73+
get text() {
74+
return this.textInner;
75+
}
76+
77+
set text(value: string) {
78+
this.textInner = value;
79+
myLocalStorage.setItem('text', value);
80+
}
81+
7182
get rules() {
7283
return this.rulesInner;
7384
}

src/components/input/input.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import './input.css';
55

66
interface InputParams {
77
isMobile: boolean;
8+
value?: string;
89
onChange: () => void;
910
}
1011

@@ -15,6 +16,12 @@ export class Input {
1516

1617
constructor(private params: InputParams) {
1718
this.bindEvents();
19+
20+
const { value } = params;
21+
if (value) {
22+
this.setValue(value);
23+
setTimeout(() => { this.handleInput() }, 0);
24+
}
1825
}
1926

2027
setValue(value: string) {

src/components/prefs/prefs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class Prefs {
179179

180180
this.save();
181181

182-
metrikaReachGoal('select-locale');
182+
metrikaReachGoal('select-locale', { changeLocale: value });
183183
}
184184

185185
private handleModeChange = () => {

0 commit comments

Comments
 (0)