feat: saving original file
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { NWUIButtonComponent } from '@nwaifu-ui';
|
||||
import { TextListComponent } from './components/text_list/text_list.component';
|
||||
import { TranslateData } from './dto/translate_data.dto';
|
||||
import { LocalStorageKeys } from './consts';
|
||||
import { NpsFile, TranslateData } from './dto/translate_data.dto';
|
||||
import { saveOriginalFile } from './lib/file_tools';
|
||||
import { parse } from './lib/parser';
|
||||
@Component({
|
||||
standalone: true,
|
||||
@@ -16,14 +18,14 @@ export class AppComponent implements OnInit {
|
||||
@ViewChild('fileInput') fileInput: HTMLInputElement | null = null;
|
||||
|
||||
ngOnInit(): void {
|
||||
const data = localStorage.getItem('translations');
|
||||
const data = localStorage.getItem(LocalStorageKeys.TRANSLATIONS);
|
||||
if (data) {
|
||||
try {
|
||||
this.elements = JSON.parse(data);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert('Error while loading');
|
||||
localStorage.removeItem('translations');
|
||||
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||
this.elements = [];
|
||||
}
|
||||
}
|
||||
@@ -38,6 +40,11 @@ export class AppComponent implements OnInit {
|
||||
reader.onload = () => {
|
||||
if (reader.result) {
|
||||
this.onFileLoaded(reader.result.toString());
|
||||
const original_file: NpsFile = {
|
||||
file_name: file.name,
|
||||
original_text: reader.result.toString(),
|
||||
};
|
||||
saveOriginalFile(original_file);
|
||||
target.value = '';
|
||||
}
|
||||
};
|
||||
@@ -53,6 +60,6 @@ export class AppComponent implements OnInit {
|
||||
|
||||
onClearClicked() {
|
||||
this.elements = [];
|
||||
localStorage.removeItem('translations');
|
||||
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
|
||||
import { NWUIButtonComponent, NWUITextAreaComponent } from '@nwaifu-ui';
|
||||
import { LocalStorageKeys } from 'src/app/consts';
|
||||
import { TranslateData } from '../../dto/translate_data.dto';
|
||||
import { ETranslateService } from '../../services/translate.enums';
|
||||
import { TranslateService } from '../../services/translate.service';
|
||||
@@ -21,7 +22,7 @@ export class TranslateBlockComponent implements OnInit {
|
||||
isEditing = false;
|
||||
|
||||
saveChanges() {
|
||||
const data: TranslateData[] = JSON.parse(localStorage.getItem('translations') ?? '[]');
|
||||
const data: TranslateData[] = JSON.parse(localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? '[]');
|
||||
if (!data.length) {
|
||||
alert('No data');
|
||||
return;
|
||||
|
||||
4
src/app/consts.ts
Normal file
4
src/app/consts.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export enum LocalStorageKeys {
|
||||
TRANSLATIONS = 'translations',
|
||||
ORIGINAL_FILE = 'original_file',
|
||||
}
|
||||
@@ -2,3 +2,8 @@ export interface TranslateData {
|
||||
english_text: string;
|
||||
translated_text: string;
|
||||
}
|
||||
export interface NpsFile {
|
||||
file_name: string;
|
||||
original_text: string;
|
||||
translated_text?: string;
|
||||
}
|
||||
|
||||
6
src/app/lib/file_tools.ts
Normal file
6
src/app/lib/file_tools.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { LocalStorageKeys } from '../consts';
|
||||
import { NpsFile } from '../dto/translate_data.dto';
|
||||
|
||||
export function saveOriginalFile(file: NpsFile) {
|
||||
localStorage.setItem(LocalStorageKeys.ORIGINAL_FILE, JSON.stringify(file));
|
||||
}
|
||||
Reference in New Issue
Block a user