Skip to content

Commit

Permalink
chore: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
jingming295 committed Jan 12, 2024
1 parent 69a3e1b commit c31e92f
Showing 1 changed file with 114 additions and 61 deletions.
175 changes: 114 additions & 61 deletions src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,88 +18,141 @@ class init
{
const hash = window.location.hash;
const changePage = new ChangePage();
if (hash.startsWith('#/u'))
{
const id = hash.slice(hash.indexOf('?id=') + 4);
if (id && Number.isInteger(parseInt(id)))
{
await changePage.toUserProfile(id);
} else
let conformPromis: Promise<boolean> | null = null;

([{
inc: ['#/u'],
fn: async () =>
{
await changePage.toIndex();
const id = hash.slice(hash.indexOf('?id=') + 4);
if (id && Number.isInteger(parseInt(id)))
{
await changePage.toUserProfile(id);
} else
{
await changePage.toIndex();
}
return true;
}
} else if (hash === '')
{
await changePage.toIndex();
} else if (hash.startsWith('#/newpost'))
{
await changePage.toPostArticle();
} else if (hash.startsWith('#/p'))
{
const id = hash.slice(hash.indexOf('?id=') + 4);
if (id && Number.isInteger(parseInt(id)))
{
await changePage.toArticle(id);
} else
}, {
inc: ['#/newpost'],
fn: async () =>
{
await changePage.toIndex();
await changePage.toPostArticle();
return true;
}
} else if (hash.startsWith('#/404'))
{
changePage.to404Page();
} else if (hash.startsWith('#/manage%20article'))
{
await changePage.toManageArticle();
} else if (hash.startsWith('#/editArticle'))
{
const id = hash.slice(hash.indexOf('?id=') + 4);
if (id && Number.isInteger(parseInt(id)))
}, {
inc: ['#/p'],
fn: async () =>
{
await changePage.toEditArticle(parseInt(id));
} else
const id = hash.slice(hash.indexOf('?id=') + 4);
if (id && Number.isInteger(parseInt(id)))
{
await changePage.toArticle(id);
} else
{
await changePage.toIndex();
}
return true;
}
}, {
inc: ['#/404'],
fn: async () =>
{
await changePage.toIndex();
changePage.to404Page();
return true;
}
} else if (hash.startsWith('#/area'))
{
const area = hash.slice(hash.indexOf('?area=') + 6);
if (area)
}, {
inc: ['#/manage%20article'],
fn: async () =>
{
await changePage.toArea(area);
} else
await changePage.toManageArticle();
return true;
}
}, {
inc: ['#/editArticle'],
fn: async () =>
{
await changePage.toIndex();
const id = hash.slice(hash.indexOf('?id=') + 4);
if (id && Number.isInteger(parseInt(id)))
{
await changePage.toEditArticle(parseInt(id));
} else
{
await changePage.toIndex();
}
return true;
}
} else if (hash.startsWith('#/search')){
const keyword = hash.slice(hash.indexOf('?keyword=') + 9);
console.log(keyword)
if (keyword)
}, {
inc: ['#/area'],
fn: async () =>
{
await changePage.toSearch(keyword);
} else
const area = hash.slice(hash.indexOf('?area=') + 6);
if (area)
{
await changePage.toArea(area);
} else
{
await changePage.toIndex();
}
return true;
}
}, {
inc: ['#/search'],
fn: async () =>
{
await changePage.toIndex();
const keyword = hash.slice(hash.indexOf('?keyword=') + 9);
console.log(keyword);
if (keyword)
{
await changePage.toSearch(keyword);
} else
{
await changePage.toIndex();
}
return true;
}

} else if (hash.startsWith('#/admin')){
await changePage.toAdminPage();
} else if(hash.startsWith('#/activateAccount')){
const token = hash.slice(hash.indexOf('?token=') + 7);
if (token)
}, {
inc: ['#/admin'],
fn: async () =>
{
await changePage.toActivateAccountPage();
} else
await changePage.toAdminPage();
return true;
}
}, {
inc: ['#/activateAccount'],
fn: async () =>
{
await changePage.toIndex();
const token = hash.slice(hash.indexOf('?token=') + 7);
if (token)
{
await changePage.toActivateAccountPage();
} else
{
await changePage.toIndex();
}
return true;
}

}else
}]).some(o =>
{
if (o.inc.every(k => hash.startsWith(k)))
{
conformPromis = o.fn();
console.log(conformPromis);
return true;
}
else
return false;
});
console.log(conformPromis);
console.log(hash);
if(!conformPromis){
await changePage.toIndex();
}

const navigationProgress = new NavigationProgress();
navigationProgress.init();


}

Expand Down

0 comments on commit c31e92f

Please sign in to comment.