Opravy TypeScriptu
This commit is contained in:
		
							parent
							
								
									1a2b3c425e
								
							
						
					
					
						commit
						8615286c45
					
				@ -43,7 +43,7 @@ function App() {
 | 
			
		||||
  const bank = useBank();
 | 
			
		||||
  const [isConnected, setIsConnected] = useState<boolean>(false);
 | 
			
		||||
  const [data, setData] = useState<ClientData>();
 | 
			
		||||
  const [food, setFood] = useState<{ [key in Restaurants]: Menu }>();
 | 
			
		||||
  const [food, setFood] = useState<{ [key in Restaurants]?: Menu }>();
 | 
			
		||||
  const [myOrder, setMyOrder] = useState<Order>();
 | 
			
		||||
  const [foodChoiceList, setFoodChoiceList] = useState<Food[]>();
 | 
			
		||||
  const [closed, setClosed] = useState<boolean>(false);
 | 
			
		||||
@ -144,8 +144,8 @@ function App() {
 | 
			
		||||
      const restaurantKey = Object.keys(Restaurants).indexOf(locationsKey);
 | 
			
		||||
      if (restaurantKey > -1 && food) {
 | 
			
		||||
        const restaurant = Object.values(Restaurants)[restaurantKey];
 | 
			
		||||
        setFoodChoiceList(food[restaurant].food);
 | 
			
		||||
        setClosed(food[restaurant].closed);
 | 
			
		||||
        setFoodChoiceList(food[restaurant]?.food);
 | 
			
		||||
        setClosed(food[restaurant]?.closed ?? false);
 | 
			
		||||
      } else {
 | 
			
		||||
        setFoodChoiceList(undefined);
 | 
			
		||||
        setClosed(false);
 | 
			
		||||
@ -372,9 +372,9 @@ function App() {
 | 
			
		||||
            </div>
 | 
			
		||||
          }
 | 
			
		||||
          <Row className='food-tables'>
 | 
			
		||||
            {renderFoodTable('Sladovnická', food[Restaurants.SLADOVNICKA])}
 | 
			
		||||
            {renderFoodTable('U Motlíků', food[Restaurants.UMOTLIKU])}
 | 
			
		||||
            {renderFoodTable('TechTower', food[Restaurants.TECHTOWER])}
 | 
			
		||||
            {food[Restaurants.SLADOVNICKA] && renderFoodTable('Sladovnická', food[Restaurants.SLADOVNICKA])}
 | 
			
		||||
            {food[Restaurants.UMOTLIKU] && renderFoodTable('U Motlíků', food[Restaurants.UMOTLIKU])}
 | 
			
		||||
            {food[Restaurants.TECHTOWER] && renderFoodTable('TechTower', food[Restaurants.TECHTOWER])}
 | 
			
		||||
          </Row>
 | 
			
		||||
          <div className='content-wrapper'>
 | 
			
		||||
            <div className='content'>
 | 
			
		||||
@ -390,7 +390,7 @@ function App() {
 | 
			
		||||
                      const locationsKey = Object.keys(Locations)[locationIndex];
 | 
			
		||||
                      const restaurantKey = Object.keys(Restaurants).indexOf(locationsKey);
 | 
			
		||||
                      const v = Object.values(Restaurants)[restaurantKey];
 | 
			
		||||
                      return v == null || !food[v].closed;
 | 
			
		||||
                      return v == null || !food[v]?.closed;
 | 
			
		||||
                    })
 | 
			
		||||
                    .map(entry => <option key={entry[0]} value={entry[0]}>{entry[1]}</option>)}
 | 
			
		||||
                </Form.Select>
 | 
			
		||||
@ -444,7 +444,7 @@ function App() {
 | 
			
		||||
                                          const locationsKey = Object.keys(Locations)[Number(locationKey)]
 | 
			
		||||
                                          const restaurantKey = Object.keys(Restaurants).indexOf(locationsKey);
 | 
			
		||||
                                          const restaurant = Object.values(Restaurants)[restaurantKey];
 | 
			
		||||
                                          const foodName = food[restaurant].food[foodIndex].name;
 | 
			
		||||
                                          const foodName = food[restaurant]?.food[foodIndex].name;
 | 
			
		||||
                                          return <li key={foodIndex}>
 | 
			
		||||
                                            {foodName}
 | 
			
		||||
                                            {login === auth.login && <FontAwesomeIcon onClick={() => {
 | 
			
		||||
 | 
			
		||||
@ -91,13 +91,13 @@ export async function savePizzaList(pizzaList: Pizza[]): Promise<ClientData> {
 | 
			
		||||
 */
 | 
			
		||||
export async function getRestaurantMenu(restaurant: Restaurants, date?: Date): Promise<Menu> {
 | 
			
		||||
    await initIfNeeded(date);
 | 
			
		||||
    const today = formatDate(date ?? getToday());
 | 
			
		||||
    const clientData: ClientData = await storage.getData(today);
 | 
			
		||||
    const selectedDay = formatDate(date ?? getToday());
 | 
			
		||||
    const clientData: ClientData = await storage.getData(selectedDay);
 | 
			
		||||
    if (!clientData.menus) {
 | 
			
		||||
        clientData.menus = {};
 | 
			
		||||
        storage.setData(today, clientData);
 | 
			
		||||
        storage.setData(selectedDay, clientData);
 | 
			
		||||
    }
 | 
			
		||||
    if (!clientData?.menus?.[restaurant]) {
 | 
			
		||||
    if (!clientData.menus[restaurant]) {
 | 
			
		||||
        clientData.menus[restaurant] = {
 | 
			
		||||
            lastUpdate: getHumanTime(new Date()),
 | 
			
		||||
            closed: false,
 | 
			
		||||
@ -106,22 +106,22 @@ export async function getRestaurantMenu(restaurant: Restaurants, date?: Date): P
 | 
			
		||||
        const mock = process.env.MOCK_DATA === 'true';
 | 
			
		||||
        switch (restaurant) {
 | 
			
		||||
            case Restaurants.SLADOVNICKA:
 | 
			
		||||
                clientData.menus[restaurant].food = await getMenuSladovnicka(date, mock);
 | 
			
		||||
                clientData.menus[restaurant]!.food = await getMenuSladovnicka(date, mock);
 | 
			
		||||
                break;
 | 
			
		||||
            case Restaurants.UMOTLIKU:
 | 
			
		||||
                const uMotlikuFood = await getMenuUMotliku(date, mock);
 | 
			
		||||
                clientData.menus[restaurant].food = uMotlikuFood;
 | 
			
		||||
                clientData.menus[restaurant]!.food = uMotlikuFood;
 | 
			
		||||
                if (uMotlikuFood.length === 1 && uMotlikuFood[0].name.toLowerCase() === 'zavřeno') {
 | 
			
		||||
                    clientData.menus[restaurant].closed = true;
 | 
			
		||||
                    clientData.menus[restaurant]!.closed = true;
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            case Restaurants.TECHTOWER:
 | 
			
		||||
                clientData.menus[restaurant].food = await getMenuTechTower(date, mock);
 | 
			
		||||
                clientData.menus[restaurant]!.food = await getMenuTechTower(date, mock);
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
        storage.setData(today, clientData);
 | 
			
		||||
        storage.setData(selectedDay, clientData);
 | 
			
		||||
    }
 | 
			
		||||
    return clientData?.menus?.[restaurant];
 | 
			
		||||
    return clientData.menus[restaurant]!;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 | 
			
		||||
@ -72,7 +72,7 @@ export interface ClientData {
 | 
			
		||||
    isWeekend: boolean, // příznak, zda je dnes víkend
 | 
			
		||||
    weekIndex: number, // index aktuálního dne v týdnu (0-6)
 | 
			
		||||
    choices: Choices, // seznam voleb
 | 
			
		||||
    menus?: { [restaurant in Restaurants]: Menu }, // menu jednotlivých restaurací
 | 
			
		||||
    menus?: { [restaurant in Restaurants]?: Menu }, // menu jednotlivých restaurací
 | 
			
		||||
    pizzaDay?: PizzaDay, // pizza day pro dnešní den, pokud existuje
 | 
			
		||||
    pizzaList?: Pizza[], // seznam dostupných pizz pro dnešní den
 | 
			
		||||
    pizzaListLastUpdate?: Date, // datum a čas poslední aktualizace pizz
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user