Zobrazování data u poslední aktualizace menu
This commit is contained in:
parent
3021e6159d
commit
2b9d817af5
@ -20,6 +20,7 @@ import { faChainBroken, faChevronLeft, faChevronRight, faGear, faSatelliteDish,
|
|||||||
import Loader from './components/Loader';
|
import Loader from './components/Loader';
|
||||||
import { getData, errorHandler, getQrUrl } from './api/Api';
|
import { getData, errorHandler, getQrUrl } from './api/Api';
|
||||||
import { addChoice, removeChoices, removeChoice, changeDepartureTime, jdemeObed } from './api/FoodApi';
|
import { addChoice, removeChoices, removeChoice, changeDepartureTime, jdemeObed } from './api/FoodApi';
|
||||||
|
import { getHumanDateTime } from './Utils';
|
||||||
|
|
||||||
const EVENT_CONNECT = "connect"
|
const EVENT_CONNECT = "connect"
|
||||||
|
|
||||||
@ -315,7 +316,7 @@ function App() {
|
|||||||
}
|
}
|
||||||
return <Col md={12} lg={4}>
|
return <Col md={12} lg={4}>
|
||||||
<h3>{name}</h3>
|
<h3>{name}</h3>
|
||||||
{menu?.lastUpdate && <small>Poslední aktualizace: {menu.lastUpdate}</small>}
|
{menu?.lastUpdate && <small>Poslední aktualizace: {getHumanDateTime(new Date(menu.lastUpdate))}</small>}
|
||||||
{content}
|
{content}
|
||||||
</Col>
|
</Col>
|
||||||
}
|
}
|
||||||
|
@ -36,3 +36,15 @@ export const getToken = (): string | null => {
|
|||||||
export const deleteToken = () => {
|
export const deleteToken = () => {
|
||||||
localStorage.removeItem(TOKEN_KEY);
|
localStorage.removeItem(TOKEN_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vrátí human-readable reprezentaci předaného data a času pro zobrazení.
|
||||||
|
*/
|
||||||
|
export function getHumanDateTime(datetime: Date) {
|
||||||
|
let currentDay = String(datetime.getDate()).padStart(2, '0');
|
||||||
|
let currentMonth = String(datetime.getMonth() + 1).padStart(2, "0");
|
||||||
|
let currentYear = datetime.getFullYear();
|
||||||
|
let currentHours = String(datetime.getHours()).padStart(2, '0');
|
||||||
|
let currentMinutes = String(datetime.getMinutes()).padStart(2, "0");
|
||||||
|
return `${currentDay}.${currentMonth}.${currentYear} ${currentHours}:${currentMinutes}`;
|
||||||
|
}
|
||||||
|
@ -99,9 +99,10 @@ async function getMenu(date: Date): Promise<WeekMenu | undefined> {
|
|||||||
export async function getRestaurantMenu(restaurant: Restaurants, date?: Date): Promise<DayMenu> {
|
export async function getRestaurantMenu(restaurant: Restaurants, date?: Date): Promise<DayMenu> {
|
||||||
const usedDate = date ?? getToday();
|
const usedDate = date ?? getToday();
|
||||||
const dayOfWeekIndex = getDayOfWeekIndex(usedDate);
|
const dayOfWeekIndex = getDayOfWeekIndex(usedDate);
|
||||||
|
const now = new Date().getTime();
|
||||||
if (getIsWeekend(usedDate)) {
|
if (getIsWeekend(usedDate)) {
|
||||||
return {
|
return {
|
||||||
lastUpdate: getHumanTime(new Date()),
|
lastUpdate: now,
|
||||||
closed: true,
|
closed: true,
|
||||||
food: [],
|
food: [],
|
||||||
};
|
};
|
||||||
@ -117,7 +118,7 @@ export async function getRestaurantMenu(restaurant: Restaurants, date?: Date): P
|
|||||||
}
|
}
|
||||||
if (menus[i][restaurant] == null) {
|
if (menus[i][restaurant] == null) {
|
||||||
menus[i][restaurant] = {
|
menus[i][restaurant] = {
|
||||||
lastUpdate: getHumanTime(new Date()),
|
lastUpdate: now,
|
||||||
closed: false,
|
closed: false,
|
||||||
food: [],
|
food: [],
|
||||||
};
|
};
|
||||||
|
@ -93,7 +93,7 @@ export interface ClientData extends DayData {
|
|||||||
|
|
||||||
/** Nabídka jídel jednoho podniku pro jeden konkrétní den. */
|
/** Nabídka jídel jednoho podniku pro jeden konkrétní den. */
|
||||||
export interface DayMenu {
|
export interface DayMenu {
|
||||||
lastUpdate: string, // human-readable čas poslední aktualizace menu
|
lastUpdate: number, // UNIX timestamp poslední aktualizace menu
|
||||||
closed: boolean, // příznak, zda je daný podnik v tento den zavřený
|
closed: boolean, // příznak, zda je daný podnik v tento den zavřený
|
||||||
food: Food[], // seznam jídel v menu
|
food: Food[], // seznam jídel v menu
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user