Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ff-pwa): ui issue #524

Merged
merged 18 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion uniquely/flight-finder-pwa/l10n/fa-IR.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"flight_finder": "پرواز یاب",
"search_list": "لیست جستجو",
"seconds_ago": "ثانیه پیش",
"minutes_ago": "دقیقه پیش",
"origin": "مبدا",
"destination": "مقصد",
"confirm": "تایید",
Expand Down
2 changes: 1 addition & 1 deletion uniquely/flight-finder-pwa/src/component/job-add-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class JobAddForm extends AlwatrElement {
<ion-label position="floating">${l10n.localize('origin')}</ion-label>
<ion-select
name="origin"
ok-text="${l10n.localize('confirm')}l"
ok-text="${l10n.localize('confirm')}"
cancel-text=${l10n.localize('cancel')}
@ionChange=${this.__inputChanged}
>
Expand Down
5 changes: 5 additions & 0 deletions uniquely/flight-finder-pwa/src/component/job-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export class JobItem extends AlwatrElement {
.job .job__subtitle .job__subtitle-price {
color: var(--ion-color-base);
}

ion-item-options {
-ms-flex-pack: start;
justify-content: flex-start;
}
`,
];

Expand Down
40 changes: 32 additions & 8 deletions uniquely/flight-finder-pwa/src/component/page-flight-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {l10n} from '@alwatr/i18n';
import {SignalInterface} from '@alwatr/signal';
import {modalController} from '@ionic/core';
import {css, html} from 'lit';
import {customElement} from 'lit/decorators.js';
import {customElement, query} from 'lit/decorators.js';
import {map} from 'lit/directives/map.js';

import ionNormalize from '../style/ionic.normalize.js';
Expand Down Expand Up @@ -42,6 +42,11 @@ export class PageFlightFinder extends AlwatrElement {
justify-content: center;
}

span#timer{
alimd marked this conversation as resolved.
Show resolved Hide resolved
display:inline-block;
min-width:23px;
}

.version {
direction: ltr;
margin: 0 16px 8px;
Expand All @@ -50,22 +55,42 @@ export class PageFlightFinder extends AlwatrElement {
`,
];

private __jobList: Array<Job> = [];

static jobListSignal = new SignalInterface('job-list');
static jobDocumentStorageSignal = new SignalInterface('job-document-storage');
static jobAddSignal = new SignalInterface('job-add');

private __jobList?: Array<Job>;
private __lastUpdate = 0;
@query('#timer') protected _timer?: HTMLSpanElement;

constructor() {
super();
this.__updateTimer = this.__updateTimer.bind(this);
}

private __updateTimer(): void {
const timer = this._timer;
if (timer == null || this.__lastUpdate === 0) return;

const time = Math.floor((Date.now() - this.__lastUpdate) / 6_000) / 10;

timer.innerText = l10n.formatNumber(time);
}

override connectedCallback(): void {
super.connectedCallback();

l10n.resourceChangeSignal.addListener(() => {
this.requestUpdate();
});

PageFlightFinder.jobListSignal.addListener((jobList) => {
this.__jobList = jobList;
PageFlightFinder.jobDocumentStorageSignal.addListener((jobList) => {
this.__jobList = Object.values(jobList.data);
this.__lastUpdate = jobList.meta.lastUpdated;
this.requestUpdate();
});

setInterval(this.__updateTimer, 3_000);
}
override render(): TemplateResult {
return html`
Expand All @@ -84,7 +109,7 @@ export class PageFlightFinder extends AlwatrElement {
</ion-fab-button>
</ion-fab>

<div class="version">v${Alwatr.version}-prv3</div>
<div class="version">v${Alwatr.version}-prv4</div>
</ion-content>
`;
}
Expand All @@ -94,7 +119,7 @@ export class PageFlightFinder extends AlwatrElement {
<ion-card class="job__list">
<ion-card-header>
<ion-card-title>${l10n.localize('search_list')}</ion-card-title>
<ion-card-subtitle>۵ ${l10n.localize('seconds_ago')}</ion-card-subtitle>
<ion-card-subtitle><span id="timer">-</span> ${l10n.localize('minutes_ago')}</ion-card-subtitle>
</ion-card-header>

<ion-list lines="full">
Expand All @@ -113,7 +138,6 @@ export class PageFlightFinder extends AlwatrElement {
modal.dismiss();
});


await modal.present();
}
}
6 changes: 3 additions & 3 deletions uniquely/flight-finder-pwa/src/director/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './job-add';
import './job-delete';
import './job-list.js';
import './job-add.js';
import './job-delete.js';
import './job-document-storage.js';
import './toast.js';
4 changes: 2 additions & 2 deletions uniquely/flight-finder-pwa/src/director/job-add.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {fetch} from '@alwatr/fetch';
import {SignalInterface} from '@alwatr/signal';

import {jobListSignal} from './job-list.js';
import {jobDocumentStorageSignal} from './job-document-storage.js';
import {showToastSignal} from './toast.js';

import type {Job} from '../type.js';
Expand Down Expand Up @@ -34,5 +34,5 @@ jobAddSignal.addListener(async (job) => {
});
}

jobListSignal.request(null);
jobDocumentStorageSignal.request(null);
});
4 changes: 2 additions & 2 deletions uniquely/flight-finder-pwa/src/director/job-delete.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {fetch} from '@alwatr/fetch';
import {SignalInterface} from '@alwatr/signal';

import {jobListSignal} from './job-list.js';
import {jobDocumentStorageSignal} from './job-document-storage.js';
import {showToastSignal} from './toast.js';

import type {AlwatrServiceResponse} from '@alwatr/fetch';
Expand Down Expand Up @@ -33,5 +33,5 @@ jobDeleteSignal.addListener(async (id) => {
});
}

jobListSignal.request(null);
jobDocumentStorageSignal.request(null);
});
40 changes: 40 additions & 0 deletions uniquely/flight-finder-pwa/src/director/job-document-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {serviceRequest} from '@alwatr/fetch';
import {AlwatrDocumentStorage, CacheStrategy} from '@alwatr/fetch/src/type.js';
import {createLogger} from '@alwatr/logger';
import {SignalInterface} from '@alwatr/signal';

import {showToastSignal} from './toast.js';

import type {Job} from '../type.js';

export const logger = createLogger('[director/job-document-storage]');
export const jobDocumentStorageSignal = new SignalInterface('job-document-storage');

async function requestJobStorage(cacheStrategy: CacheStrategy): Promise<void> {
logger.logMethod('jobListProvider');

try {
jobDocumentStorageSignal.dispatch(
<AlwatrDocumentStorage<Job>> await serviceRequest({
url: window.appConfig?.api ? window.appConfig.api + '/job' : '/job',
token: window.appConfig?.token,
cache: 'no-cache',
cacheStrategy,
}),
);
}
catch (error) {
if ((error as Error).message !== 'fetch_cache_not_found') {
logger.error('jobListProvider', 'fetch_failed', error);
showToastSignal.dispatch({
message: 'عملیات با خطا رو به رو شد',
});
}
}
}

jobDocumentStorageSignal.setProvider(() => requestJobStorage('network_first'));

requestJobStorage('cache_only').then(() => requestJobStorage('network_first'));

setInterval(() => jobDocumentStorageSignal.request(null), 60_000);
48 changes: 0 additions & 48 deletions uniquely/flight-finder-pwa/src/director/job-list.ts

This file was deleted.

14 changes: 7 additions & 7 deletions uniquely/flight-finder-pwa/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {AlwatrDocumentObject} from '@alwatr/fetch';
import type {AlwatrDocumentObject, AlwatrDocumentStorage} from '@alwatr/fetch/type.js';
import type {ToastOptions} from '@ionic/core';

declare global {
Expand All @@ -8,11 +8,11 @@ declare global {
interface AlwatrSignals {
readonly 'job-add': Pick<Job, 'detail'>;
readonly 'job-delete': string;
readonly 'job-list': Array<Job>;
readonly 'job-document-storage': AlwatrDocumentStorage<Job>;
readonly toast: Partial<ToastOptions> & {message: string};
}
interface AlwatrRequestSignals {
readonly 'job-list': null;
readonly 'job-document-storage': null;
}
}

Expand Down Expand Up @@ -42,8 +42,8 @@ export type JobResult = {
price: number;
time: string;
seatCount: number;
airline: string,
airplane: string,
flightId: string,
arrivalTime: string,
airline: string;
airplane: string;
flightId: string;
arrivalTime: string;
};