Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Appbird/kss-recorders into …
Browse files Browse the repository at this point in the history
…topic/#5-ruleClass-pageJump
  • Loading branch information
Appbird committed Sep 2, 2021
2 parents 18064bb + cda8560 commit bbed0e1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 35 deletions.
31 changes: 9 additions & 22 deletions src/ts/client/Administrator/HistoryAdministrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,43 @@ import { LanguageInApplication } from "../../type/LanguageInApplication";
export class HistoryAdministrator{
private app:IAppUsedToReadAndChangePage;
private urlAd:URLAdministrator
private transitionPile:TransitionItem<keyof PageStates>[] = [];
constructor(app:IAppUsedToReadAndChangePage){
this.app = app;
this.urlAd = new URLAdministrator(app)
window.addEventListener('popstate', (e) => {
this.back();
window.addEventListener('popstate', ({state}) => {
this.app.transition(state.pageState,state.requiredObject,{ifAppendHistory:false})
});
}
async appendHistory(){
this.transitionPile.push({
pageState:this.app.state.state,
requiredObject:this.app.state.requiredObj
})

}
clearIntroduction(){
localStorage.setItem("KSSRs::HistoryAdministrator::clearIntroduction_v1","true")

}
checkIfIntroductionIsOver(){
return localStorage.getItem("KSSRs::HistoryAdministrator::clearIntroduction_v1") === "true"
}
registerCurrentPage(){
localStorage.setItem("KSSRs::HistoryAdministrator::PreviousPage",JSON.stringify({
const data = {
pageState:this.app.state.state,
requiredObject:this.app.state.requiredObj
}))
}
localStorage.setItem("KSSRs::HistoryAdministrator::PreviousPage",JSON.stringify(data))
switch(this.app.state.state){
case "detailView":{
const obj = this.app.state.requiredObj as APIFunctions["record_detail"]["atServer"]
history.pushState(null,`Kirby-Speed/ScoreRecorders:${this.app.state.state}`,`/ogpDetailView/?state=detailView&gs=${obj.gameSystemEnv.gameSystemID}&gm=${obj.gameSystemEnv.gameModeID}&id=${obj.id}`)
history.pushState(data,`Kirby-Speed/ScoreRecorders:${this.app.state.state}`,`/ogpDetailView/?state=detailView&gs=${obj.gameSystemEnv.gameSystemID}&gm=${obj.gameSystemEnv.gameModeID}&id=${obj.id}`)
break;
}
case "userPageInWhole":{
const obj = this.app.state.requiredObj as {runnerID:string}
history.pushState(null,`Kirby-Speed/ScoreRecorders:${this.app.state.state}`,`/?state=userPageInWhole&id=${obj.runnerID}`)
history.pushState(data,`Kirby-Speed/ScoreRecorders:${this.app.state.state}`,`/?state=userPageInWhole&id=${obj.runnerID}`)
break;
}
case "userPageInSpecific":{
const obj = this.app.state.requiredObj as TargetGameMode&{runnerID:string}
history.pushState(null,`Kirby-Speed/ScoreRecorders:${this.app.state.state}`,`/?state=userPageInWhole&id=${obj.runnerID}`)
history.pushState(data,`Kirby-Speed/ScoreRecorders:${this.app.state.state}`,`/?state=userPageInWhole&id=${obj.runnerID}`)
break;
}
default:
history.pushState(null,`Kirby-Speed/ScoreRecorders:${this.app.state.state}`,`/`)
history.pushState(data,`Kirby-Speed/ScoreRecorders:${this.app.state.state}`,`/`)
break;

}
Expand All @@ -63,11 +55,6 @@ export class HistoryAdministrator{
console.info(`[KSSRs::HistoryAdministrator::TargetMode] register current target gamemode: ${this.app.state.gameSystemEnvDisplayed.gameSystem?.English} / ${this.app.state.gameSystemEnvDisplayed.gameMode?.Japanese}`)
}

back(){
const past = this.transitionPile.pop();
if (past === undefined) return;
this.app.transition(past.pageState,past.requiredObject,{ifAppendHistory:false})
}
getPreviousPageData():TransitionItem<keyof PageStates>|"redirect"|null{
const str = localStorage.getItem("KSSRs::HistoryAdministrator::PreviousPage")
if (str === null) return null;
Expand Down
2 changes: 0 additions & 2 deletions src/ts/client/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ export default class App implements IAppUsedToChangeState{
}
async transition<T extends keyof PageStates>(nextState:T, requestObject:RequiredObjectType<PageStates[T]>,{ifAppendHistory=true,title=""}:{ifAppendHistory?:boolean,title?:string} = {}){
this.goToTop();
if (ifAppendHistory) this.historyAd.appendHistory()

try {
await this.transitionAd.transition(nextState,requestObject,{title:title})
if (ifAppendHistory) this.historyAd.registerCurrentPage();
Expand Down
7 changes: 1 addition & 6 deletions src/ts/client/view/parts/Input/searchConditionSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class SearchConditionSelectorView implements IView{
new DecideButtonPart(this.container.appendChild(elementWithoutEscaping`<div class="u-width50per u-margin2em"></div>`) as HTMLElement,{
text:{Japanese:"決定",English:"Submit"},language,
onClick:() => {
if (!(!this.isAbilitySelectEditor(abilitySelectEditor) && abilitySelectEditor.isFillAllAbility())){
if (abilitySelectEditor.kind === "PlayersWithAttributesPart" && !abilitySelectEditor.isAttributeConditionWithAbilityCondition()){
errorViewer.innerHTML = choiceString({Japanese:"能力欄の入力が不十分です。(能力属性のみを指定した検索は現在できません。)",English:"The input of Ability isn't enough. (For now, searching with only specifying attributes of ability is not implemented.)"},language)
return;
}
Expand All @@ -199,11 +199,6 @@ export class SearchConditionSelectorView implements IView{
if (difficultyID !== undefined) this.getTargetItems(difficultyID).then(targetItems => targetSelectEditor.refreshOption(targetItems))

}
isAbilitySelectEditor(editor:EditorPlayersWithAttributesPart|EditorMultipleIDPart):editor is EditorMultipleIDPart{
const value = editor.value
if (value === undefined) return false
return typeof value[0] === "string"
}
destroy(){
this.editorManager.destroy()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { MultiLanguageDescription } from "../../../../../utility/aboutLang";
import { ILabelledDocument } from "../../../../../type/list/ILabelledDocument";

export class EditorMultipleIDPart implements EditorPart<string[]> {
public readonly kind = "MultipleIDPart"
private container: HTMLElement;
private selectInput: SelectChoicesCapsuled<ITargetItem>;
private htmlCon: HTMLConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ export class EditorPlayerWithAttributesPart implements EditorPart<HandledType> {
get requiredField(){
return this._requiredField;
}
isFillAllAbility(){
isAttributeConditionWithAbilityCondition(){
const abilityFill = this.selectInput.getValueAsArray()[0] !== undefined
const attributeEmpty = this.selectInput.getValueAsArray().length === 0
return (abilityFill && attributeEmpty) || !attributeEmpty
const attributeConditionExist = this.attributeChoices.some(attributeChoice => attributeChoice.editor.value.length !== 0)
return abilityFill || !attributeConditionExist
}
destroy(){
if (this.unsubscribe !== null)this.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SmallButtonPart } from "../../MultiButtonPart";

type HandledType ={abilityID:string,attribute:OnePlayerOfAbilityAttribute}
export class EditorPlayersWithAttributesPart implements EditorPart<HandledType[]> {
public readonly kind = "PlayersWithAttributesPart"
private container: HTMLElement;
private playersWithAttributesChoices:EditorPlayerWithAttributesPart[] = [];
private htmlCon: HTMLConverter;
Expand Down Expand Up @@ -142,8 +143,8 @@ export class EditorPlayersWithAttributesPart implements EditorPart<HandledType[]
disabled(state:boolean){
for (const editor of this.playersWithAttributesChoices) editor.disabled(state)
}
isFillAllAbility(){
return this.playersWithAttributesChoices.every((editor) => editor.isFillAllAbility())
isAttributeConditionWithAbilityCondition(){
return this.playersWithAttributesChoices.every((editor) => editor.isAttributeConditionWithAbilityCondition())
}
refresh(values:{abilityID:string,attribute:OnePlayerOfAbilityAttribute}[]) {
while (true){
Expand Down

0 comments on commit bbed0e1

Please sign in to comment.