feat: update modal

This commit is contained in:
2024-05-08 16:41:14 +02:00
parent b3289d6aab
commit f1fcde8459
7 changed files with 91 additions and 87 deletions
+2
View File
@@ -16,6 +16,7 @@
"dotenv": "^16.3.1",
"pinia": "^2.1.6",
"sass": "^1.67.0",
"showdown": "^2.1.0",
"vue": "^3.3.4",
"vue-i18n": "^9.4.1",
"vue-router": "^4.2.4"
@@ -23,6 +24,7 @@
"devDependencies": {
"@rushstack/eslint-patch": "^1.3.3",
"@types/node": "^20.6.2",
"@types/showdown": "^2.0.6",
"@vite-pwa/assets-generator": "^0.2.4",
"@vitejs/plugin-vue": "^4.3.4",
"@vue/eslint-config-prettier": "^8.0.0",
+32 -28
View File
@@ -1,5 +1,10 @@
<template>
<div class="app_container">
<UpdateModal
:update-modal-open="updateModalOpen"
@toggle-modal="() => (updateModalOpen = false)"
/>
<Tooltip />
<transition name="modal-anim">
@@ -22,7 +27,10 @@
&copy;
<a href="https://td2.info.pl/profile/?u=20777" target="_blank">Spythere</a>
{{ new Date().getUTCFullYear() }} |
<a :href="releaseURL" target="_blank">v{{ VERSION }}{{ isOnProductionHost ? '' : 'dev' }}</a>
<a :href="store.appUpdate?.releaseURL" target="_blank"
>v{{ VERSION }}{{ isOnProductionHost ? '' : 'dev' }}</a
>
<br />
<a href="https://discord.gg/x2mpNN3svk">
<img src="/images/icon-discord.png" alt="" />&nbsp;<b>{{ $t('footer.discord') }}</b>
@@ -48,6 +56,7 @@ import StatusIndicator from './components/App/StatusIndicator.vue';
import AppHeader from './components/App/AppHeader.vue';
import TrainModal from './components/TrainsView/TrainModal.vue';
import Tooltip from './components/Tooltip/Tooltip.vue';
import UpdateModal from './components/App/UpdateModal.vue';
import StorageManager from './managers/storageManager';
@@ -59,6 +68,7 @@ export default defineComponent({
StatusIndicator,
AppHeader,
TrainModal,
UpdateModal,
Tooltip
},
@@ -68,8 +78,9 @@ export default defineComponent({
apiStore: useApiStore(),
tooltipStore: useTooltipStore(),
updateModalOpen: false,
currentLang: 'pl',
releaseURL: '',
isOnProductionHost: location.hostname == 'stacjownik-td2.web.app',
nextUpdateTime: 0
@@ -86,7 +97,6 @@ export default defineComponent({
methods: {
init() {
this.loadLang();
this.setReleaseURL();
this.setupOfflineHandling();
this.checkAppVersion();
@@ -104,20 +114,29 @@ export default defineComponent({
window.requestAnimationFrame(this.update);
},
checkAppVersion() {
if (import.meta.env.DEV) {
this.store.isNewUpdate = true;
return;
}
async checkAppVersion() {
const storageVersion = StorageManager.getStringValue(STORAGE_VERSION_KEY);
if (storageVersion === undefined || storageVersion != version) {
this.store.isNewUpdate = true;
try {
const releaseData = await (
await axios.get('https://api.github.com/repos/Spythere/stacjownik/releases/latest')
).data;
if (!releaseData) return;
this.store.appUpdate = {
version,
changelog: releaseData.body,
releaseURL: releaseData.html_url
};
this.updateModalOpen =
storageVersion != version || import.meta.env.VITE_UPDATE_TEST === 'test';
} catch (error) {
console.error(`Wystąpił błąd podczas pobierania danych z API GitHuba: ${error}`);
}
StorageManager.setStringValue(STORAGE_VERSION_KEY, version);
}
},
setupOfflineHandling() {
@@ -149,21 +168,6 @@ export default defineComponent({
StorageManager.setStringValue('lang', lang);
},
async setReleaseURL() {
try {
const releaseData = await (
await axios.get('https://api.github.com/repos/Spythere/stacjownik/releases/latest')
).data;
if (!releaseData) return;
this.releaseURL = releaseData.html_url;
} catch (error) {
console.error(`Wystąpił błąd podczas pobierania danych z API GitHuba: ${error}`);
return;
}
},
loadLang() {
const storageLang = StorageManager.getStringValue('lang');
+38 -55
View File
@@ -1,21 +1,14 @@
<template>
<AnimatedModal :is-open="mainStore.isNewUpdate" @toggle-modal="toggleModal">
<AnimatedModal :is-open="updateModalOpen" @toggle-modal="toggleModal">
<div class="modal_content">
<div>
<h1 style="margin-bottom: 0.5em">{{ $t('update.title') }}</h1>
<h2 class="text--primary">{{ $t('update.version', [version]) }}</h2>
<hr class="separator" />
</div>
<div class="features-list">
<h2>Nowości i zmiany:</h2>
<ul>
<li v-for="content in localeChangesArray" :key="content">{{ content }}</li>
</ul>
</div>
<div class="features-body" v-html="htmlChangelog"></div>
<div class="modal_actions">
<button class="btn--action">Przyjąłem!</button>
<button class="btn--action" @click="toggleModal">Przyjąłem!</button>
<p>Ten changelog będzie zawsze dostępny po kliknięciu numeru wersji w stopce strony!</p>
@@ -39,11 +32,24 @@
import { defineComponent } from 'vue';
import { useMainStore } from '../../store/mainStore';
import { version } from '../../../package.json';
import { Converter } from 'showdown';
import AnimatedModal from '../Global/AnimatedModal.vue';
const converter = new Converter();
export default defineComponent({
components: { AnimatedModal },
props: {
updateModalOpen: {
type: Boolean,
required: true
}
},
emits: ['toggleModal'],
data() {
return {
mainStore: useMainStore(),
@@ -52,8 +58,13 @@ export default defineComponent({
},
computed: {
localeChangesArray() {
return this.$t('update.content').split('\n');
htmlChangelog() {
if (this.mainStore.appUpdate == null) return '';
const x = converter.makeHtml(this.mainStore.appUpdate.changelog);
console.log(x);
return x;
}
},
@@ -66,10 +77,22 @@ export default defineComponent({
</script>
<style lang="scss" scoped>
.modal_content {
font-size: 1.2em;
::v-deep h1 {
text-align: center;
padding: 1em;
}
::v-deep h2 {
padding: 0.25em 0;
}
::v-deep ul {
list-style: inside;
padding: 0.5em;
line-height: 1.5em;
}
.modal_content {
padding: 2em;
height: 80vh;
min-height: 550px;
@@ -85,49 +108,9 @@ hr.separator {
background-color: #fff;
}
.features-list {
margin-top: 0.5em;
overflow: auto;
ul {
text-align: left;
list-style: '\21D2 ';
padding: 1em;
}
li {
margin: 0.5em 0;
}
}
.modal_actions {
display: flex;
flex-wrap: wrap;
gap: 0.5em;
button {
font-weight: bold;
padding: 0.35em;
}
p {
font-size: 0.9em;
}
}
.actions-checkboxes {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 1em;
label {
font-size: 0.9em;
}
label > input {
margin-right: 0.5em;
}
}
</style>
+1 -1
View File
@@ -18,7 +18,7 @@ export const useMainStore = defineStore('mainStore', {
region: { id: 'eu', value: 'PL1', name: 'PL1' },
isOffline: false,
isNewUpdate: false,
appUpdate: null,
dispatcherStatsName: '',
dispatcherStatsStatus: Status.Data.Initialized,
-2
View File
@@ -22,8 +22,6 @@ export const useTooltipStore = defineStore('tooltipStore', {
show(_e: MouseEvent, type: string, value?: string) {
if (!isTooltip(type)) return;
console.log(type, value);
this.type = type;
this.content = value ?? '';
},
+1 -1
View File
@@ -4,7 +4,7 @@ import { Availability, StationRoutesInfo, Status } from '../typings/common';
export interface MainStoreState {
region: { id: string; value: string; name: string };
isOffline: boolean;
isNewUpdate: boolean;
appUpdate: { version: string; changelog: string; releaseURL: string } | null;
dispatcherStatsName: string;
dispatcherStatsData?: API.DispatcherStats.Response;
driverStatsName: string;
+17
View File
@@ -1440,6 +1440,11 @@
resolved "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz"
integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==
"@types/showdown@^2.0.6":
version "2.0.6"
resolved "https://registry.yarnpkg.com/@types/showdown/-/showdown-2.0.6.tgz#3d7affd5f971b4a17783ec2b23b4ad3b97477b7e"
integrity sha512-pTvD/0CIeqe4x23+YJWlX2gArHa8G0J0Oh6GKaVXV7TAeickpkkZiNOgFcFcmLQ5lB/K0qBJL1FtRYltBfbGCQ==
"@types/trusted-types@^2.0.2":
version "2.0.7"
resolved "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz"
@@ -2077,6 +2082,11 @@ commander@^2.20.0:
resolved "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
commander@^9.0.0:
version "9.5.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30"
integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==
common-tags@^1.8.0:
version "1.8.2"
resolved "https://registry.npmjs.org/common-tags/-/common-tags-1.8.2.tgz"
@@ -3866,6 +3876,13 @@ shebang-regex@^3.0.0:
resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
showdown@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/showdown/-/showdown-2.1.0.tgz#1251f5ed8f773f0c0c7bfc8e6fd23581f9e545c5"
integrity sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==
dependencies:
commander "^9.0.0"
side-channel@^1.0.4, side-channel@^1.0.6:
version "1.0.6"
resolved "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz"