Merge branch 'feature/scroll-to-top' into dev
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Component } from "@angular/core";
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { RouterModule } from "@angular/router";
|
||||
import { PanelComponent } from "./modules/panel/panel.component";
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
margin-inline: 2rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
h1, h2 {
|
||||
color: #efdee0;
|
||||
text-align: center;
|
||||
margin: 1rem 2rem;
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, Input, QueryList, ViewChildren } from '@angular/core';
|
||||
import { TranslateData } from '../../dto/translate_data.dto';
|
||||
import { TranslateBlockComponent } from '../translate_block/translate_block.component';
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, Input, OnInit, QueryList, ViewChildren } from "@angular/core";
|
||||
import { NpsFile, TranslateData } from "../../dto/translate_data.dto";
|
||||
import { TranslateBlockComponent } from "../translate_block/translate_block.component";
|
||||
|
||||
@Component({
|
||||
selector: 'app-text-list',
|
||||
templateUrl: './text_list.component.html',
|
||||
styleUrls: ['./text_list.component.scss'],
|
||||
selector: "app-text-list",
|
||||
templateUrl: "./text_list.component.html",
|
||||
styleUrls: ["./text_list.component.scss"],
|
||||
standalone: true,
|
||||
imports: [CommonModule, TranslateBlockComponent],
|
||||
})
|
||||
export class TextListComponent {
|
||||
@ViewChildren('translateBlock') translate_blocks: QueryList<TranslateBlockComponent> | null = null;
|
||||
export class TextListComponent implements OnInit {
|
||||
@ViewChildren("translateBlock") translate_blocks: QueryList<TranslateBlockComponent> | null =
|
||||
null;
|
||||
fileName = "";
|
||||
elements_data: TranslateData[] = [];
|
||||
@Input() set elements(el: TranslateData[]) {
|
||||
this.elements_data = el;
|
||||
localStorage.setItem('translations', JSON.stringify(this.elements_data));
|
||||
localStorage.setItem("translations", JSON.stringify(this.elements_data));
|
||||
}
|
||||
|
||||
get elements() {
|
||||
return this.elements_data;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
const data = localStorage.getItem("original_file");
|
||||
if (data) {
|
||||
const file: NpsFile = JSON.parse(data);
|
||||
this.fileName = file.file_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,3 +28,6 @@
|
||||
<button id="close_win" (click)="onCloseClicked()"><i class="lni lni-close"></i></button>
|
||||
</div>
|
||||
<app-text-list [elements]="elements"></app-text-list>
|
||||
<nwui-button class="to-top-btn" (click)="scrollToTop()"
|
||||
><i class="lni lni-arrow-up"></i
|
||||
></nwui-button>
|
||||
|
||||
@@ -45,3 +45,14 @@
|
||||
min-height: calc(100vh - 2rem);
|
||||
scrollbar-color: #413738;
|
||||
}
|
||||
.to-top-btn {
|
||||
position: fixed;
|
||||
width: 2rem;
|
||||
left: 2rem;
|
||||
bottom: -5rem;
|
||||
transition: bottom 0.3s ease-in-out;
|
||||
|
||||
&.active {
|
||||
bottom: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, OnInit, ViewChild } from "@angular/core";
|
||||
import { AfterViewInit, Component, OnInit, ViewChild } from "@angular/core";
|
||||
import { Router } from "@angular/router";
|
||||
import { NWUIButtonComponent } from "@nwaifu-ui";
|
||||
import { fromEvent, map } from "rxjs";
|
||||
import { TextListComponent } from "./components/text_list/text_list.component";
|
||||
import { LocalStorageKeys } from "./consts";
|
||||
import { NpsFile, TranslateData } from "./dto/translate_data.dto";
|
||||
@@ -14,7 +15,7 @@ import { parse } from "./lib/parser";
|
||||
templateUrl: "./nitroplus-translator.component.html",
|
||||
styleUrl: "./nitroplus-translator.component.less",
|
||||
})
|
||||
export class NitroplusComponent implements OnInit {
|
||||
export class NitroplusComponent implements OnInit, AfterViewInit {
|
||||
title = "NitroPlusTranslator";
|
||||
elements: TranslateData[] = [];
|
||||
@ViewChild("fileInput") fileInput: HTMLInputElement | null = null;
|
||||
@@ -36,6 +37,25 @@ export class NitroplusComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
const container = document.querySelector("main");
|
||||
if (container) {
|
||||
fromEvent(container, "scroll")
|
||||
.pipe(map(() => container.scrollTop > 100))
|
||||
.subscribe((val) => {
|
||||
if (val) document.querySelector(".to-top-btn")?.classList.add("active");
|
||||
else document.querySelector(".to-top-btn")?.classList.remove("active");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
scrollToTop() {
|
||||
const container = document.querySelector("main");
|
||||
if (container) {
|
||||
container.scrollTo({ top: 0, behavior: "smooth" });
|
||||
}
|
||||
}
|
||||
|
||||
submitFile($event: Event) {
|
||||
const target = $event.target as HTMLInputElement;
|
||||
if (target.files) {
|
||||
|
||||
Reference in New Issue
Block a user