enhance(client): 広告・お知らせが新規登録時に増殖しないように (#10412)

This commit is contained in:
atsuchan
2023-04-08 17:42:08 +09:00
committed by GitHub
parent 6892e9fbb7
commit 5cd93834d1
2 changed files with 51 additions and 2 deletions

View File

@@ -113,16 +113,37 @@ function remove(ad) {
function save(ad) {
if (ad.id == null) {
os.apiWithDialog('admin/ad/create', {
os.api('admin/ad/create', {
...ad,
expiresAt: new Date(ad.expiresAt).getTime(),
startsAt: new Date(ad.startsAt).getTime(),
}).then(() => {
os.alert({
type: 'success',
text: i18n.ts.saved,
});
refresh();
}).catch(err => {
os.alert({
type: 'error',
text: err,
});
});
} else {
os.apiWithDialog('admin/ad/update', {
os.api('admin/ad/update', {
...ad,
expiresAt: new Date(ad.expiresAt).getTime(),
startsAt: new Date(ad.startsAt).getTime(),
}).then(() => {
os.alert({
type: 'success',
text: i18n.ts.saved,
});
}).catch(err => {
os.alert({
type: 'error',
text: err,
});
});
}
}
@@ -141,6 +162,25 @@ function more() {
}));
});
}
function refresh() {
os.api('admin/ad/list').then(adsResponse => {
ads = adsResponse.map(r => {
const exdate = new Date(r.expiresAt);
const stdate = new Date(r.startsAt);
exdate.setMilliseconds(exdate.getMilliseconds() - localTimeDiff);
stdate.setMilliseconds(stdate.getMilliseconds() - localTimeDiff);
return {
...r,
expiresAt: exdate.toISOString().slice(0, 16),
startsAt: stdate.toISOString().slice(0, 16),
};
});
});
}
refresh();
const headerActions = $computed(() => [{
asFullButton: true,
icon: 'ti ti-plus',