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

Add solution sum #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 00-intro/10-sum/sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* @return {number} сумма чисел a и b
*/
export function sum(a, b) {
// Решение
return a + b;
}
18 changes: 18 additions & 0 deletions 01-basics/10-create-app/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineComponent, computed } from 'vue'

export default defineComponent({
name: 'App',

setup() {
const date = new Date();
const formattedDate = new Intl.DateTimeFormat(navigator.language, {dateStyle: 'long'}).format(date)

return {
formattedDate,
}
},

template: `
<div>Сегодня {{ formattedDate }}</div>
`,
})
4 changes: 4 additions & 0 deletions 01-basics/10-create-app/script.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
import { defineComponent, createApp } from 'vue'

import App from './App.js'

createApp(App).mount('#app')
49 changes: 37 additions & 12 deletions 01-basics/20-weather/WeatherApp.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,72 @@
import { defineComponent } from 'vue'
import { defineComponent, onMounted, ref } from 'vue'
import { getWeatherData, WeatherConditionIcons } from './weather.service.ts'

export default defineComponent({
name: 'WeatherApp',
props: {
weatherData: {
type: Array,
required: true,
},
},
setup() {
const weatherDataList = ref(getWeatherData())

const parseTime = timeString =>
timeString.split(':').reduce((acc, time, index) => acc + Number(time) / (index === 0 ? 1 : 60), 0)

const isNightMode = (current, sunrise, sunset) => {
return parseTime(current) < parseTime(sunrise) || parseTime(current) > parseTime(sunset)
}

return {
weatherDataList,
WeatherConditionIcons,
isNightMode,
}
},

template: `
<div>
<h1 class="title">Погода в Средиземье</h1>

<ul class="weather-list unstyled-list">
<li class="weather-card weather-card--night">
<div class="weather-alert">
<li v-for="(city, index) in weatherDataList" :key="index"
:class="['weather-card', { 'weather-card--night': isNightMode(city.current.dt, city.current.sunrise, city.current.sunset) }]">
<div v-if=city.alert class="weather-alert">
<span class="weather-alert__icon">⚠️</span>
<span class="weather-alert__description">Королевская метеослужба короля Арагорна II: Предвещается наступление сильного шторма.</span>
<span class="weather-alert__description">{{ city.alert.sender_name }} : {{ city.alert.description }}</span>
</div>
<div>
<h2 class="weather-card__name">
Гондор
{{ city.geographic_name }}
</h2>
<div class="weather-card__time">
07:17
{{ city.current.dt }}
</div>
</div>
<div class="weather-conditions">
<div class="weather-conditions__icon" title="thunderstorm with heavy rain">⛈️</div>
<div class="weather-conditions__temp">15.0 °C</div>
<div class="weather-conditions__icon" :title="city.current.weather.description">
{{ WeatherConditionIcons[city.current.weather.id] }}
</div>
<div class="weather-conditions__temp">{{ (city.current.temp - 273.15).toFixed(1) }} °C</div>
</div>
<div class="weather-details">
<div class="weather-details__item">
<div class="weather-details__item-label">Давление, мм рт. ст.</div>
<div class="weather-details__item-value">754</div>
<div class="weather-details__item-value">{{ Math.round(city.current.pressure * 0.75) }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Влажность, %</div>
<div class="weather-details__item-value">90</div>
<div class="weather-details__item-value">{{ city.current.humidity }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Облачность, %</div>
<div class="weather-details__item-value">100</div>
<div class="weather-details__item-value">{{ city.current.clouds }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Ветер, м/с</div>
<div class="weather-details__item-value">10.5</div>
<div class="weather-details__item-value">{{ city.current.wind_speed }}</div>
</div>
</div>
</li>
Expand Down
33 changes: 27 additions & 6 deletions 02-basics-2/10-counter/CounterApp.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
import { defineComponent } from 'vue'
import { defineComponent, ref } from 'vue'

export default defineComponent({
name: 'CounterApp',

setup() {},
setup() {
const count = ref(0)

function increment() {
count.value++
}

function decrement() {
count.value--
}

return {
count,
increment,
decrement,
}
},

template: `
<div class="counter">
<button
@click="decrement"
class="button button--secondary"
type="button"
aria-label="Decrement"
disabled
>➖</button>
:disabled="count === 0"
>➖
</button>

<span class="count" data-testid="count">0</span>
<span class="count" data-testid="count"> {{ count }}</span>

<button
@click="increment"
class="button button--secondary"
type="button"
aria-label="Increment"
>➕</button>
:disabled="count === 5"
>➕
</button>
</div>
`,
})