Migrate to Vue 3 and vite
This commit is contained in:
parent
bdf9b1637f
commit
f1995232bb
@ -1,11 +0,0 @@
|
||||
{
|
||||
"plugins": ["@babel/plugin-transform-runtime"],
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"useBuiltIns": "usage"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
11
index.html
Normal file
11
index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Tool Reservations</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/index.ts"></script>
|
||||
</body>
|
||||
</html>
|
28
package.json
28
package.json
@ -1,30 +1,26 @@
|
||||
{
|
||||
"browserslist": [
|
||||
"defaults",
|
||||
"ios 9.3"
|
||||
],
|
||||
"scripts": {
|
||||
"start": "parcel src/index.html"
|
||||
"start": "npm run dev",
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"serve": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.8.7",
|
||||
"@babel/plugin-transform-runtime": "^7.8.3",
|
||||
"@babel/preset-env": "^7.8.7",
|
||||
"@vue/component-compiler-utils": "^3.0.0",
|
||||
"@types/intl": "^1.2.0",
|
||||
"@vitejs/plugin-legacy": "^1.6.2",
|
||||
"@vitejs/plugin-vue": "^1.9.4",
|
||||
"sass": "^1.23.1",
|
||||
"typescript": "^4.2.3",
|
||||
"vue-template-compiler": "^2.6.10"
|
||||
"vite": "^2.6.13",
|
||||
"vue-tsc": "^0.28.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fullcalendar/core": "^5.6.0",
|
||||
"@fullcalendar/core": "^5.10.0",
|
||||
"@fullcalendar/google-calendar": "^5.6.0",
|
||||
"@fullcalendar/timegrid": "^5.6.0",
|
||||
"@fullcalendar/vue": "^5.6.0",
|
||||
"core-js": "^3.6.4",
|
||||
"@fullcalendar/vue3": "^5.10.0",
|
||||
"equicolor": "^1.1.0",
|
||||
"intl": "^1.2.5",
|
||||
"vue": "^2.6.10",
|
||||
"vue-hot-reload-api": "^2.3.4",
|
||||
"vue-property-decorator": "^9.1.2"
|
||||
"vue": "^3.2.20"
|
||||
}
|
||||
}
|
||||
|
47
src/App.vue
47
src/App.vue
@ -2,18 +2,20 @@
|
||||
<FullCalendar ref="calendar" :options="calendarOptions"> </FullCalendar>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Vue, Component } from 'vue-property-decorator';
|
||||
<script setup lang="ts">
|
||||
import { ref, Ref } from 'vue';
|
||||
import equicolor from 'equicolor/src/Equicolor';
|
||||
|
||||
import FullCalendar from '@fullcalendar/vue';
|
||||
import '@fullcalendar/core/vdom'; // solve problem with Vite
|
||||
import FullCalendar, {
|
||||
EventInput,
|
||||
Calendar,
|
||||
CalendarOptions,
|
||||
} from '@fullcalendar/vue3';
|
||||
import timeGridPlugin from '@fullcalendar/timegrid';
|
||||
import dayGridPlugin from '@fullcalendar/daygrid';
|
||||
import googleCalendarPlugin from '@fullcalendar/google-calendar';
|
||||
|
||||
import { EventInput, CalendarOptions } from '@fullcalendar/core';
|
||||
import { Calendar } from '@fullcalendar/core';
|
||||
|
||||
import { googleCalendarApiKey } from './secrets.json';
|
||||
|
||||
const calendars: { [key: string]: string } = {
|
||||
@ -31,9 +33,7 @@ const colors: string[] = equicolor.findNextColors(
|
||||
Object.keys(calendars).length
|
||||
);
|
||||
|
||||
@Component({ components: { FullCalendar } })
|
||||
export default class App extends Vue {
|
||||
calendarOptions: CalendarOptions = {
|
||||
const calendarOptions: CalendarOptions = {
|
||||
plugins: [timeGridPlugin, dayGridPlugin, googleCalendarPlugin],
|
||||
allDaySlot: false,
|
||||
nowIndicator: true,
|
||||
@ -51,7 +51,7 @@ export default class App extends Vue {
|
||||
return {
|
||||
googleCalendarId: id,
|
||||
color: colors[idx],
|
||||
eventDataTransform: this.eventDataTransform,
|
||||
eventDataTransform: eventDataTransform,
|
||||
};
|
||||
}),
|
||||
slotLabelFormat: {
|
||||
@ -66,25 +66,21 @@ export default class App extends Vue {
|
||||
},
|
||||
};
|
||||
|
||||
toolFilter: string | null = null;
|
||||
|
||||
created() {
|
||||
// refresh data every five minutes
|
||||
window.setInterval(this.refresh, 5 * 60 * 1000);
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
this.toolFilter = urlParams.get('tool');
|
||||
}
|
||||
const toolFilter: string | null = urlParams.get('tool');
|
||||
const calendar_ref: Ref<InstanceType<typeof FullCalendar> | null> = ref(null);
|
||||
|
||||
refresh() {
|
||||
const calendarComponent = this.$refs.calendar as InstanceType<
|
||||
typeof FullCalendar
|
||||
>;
|
||||
const calendar = calendarComponent.getApi() as Calendar;
|
||||
// refresh data every five minutes
|
||||
window.setInterval(refresh, 5 * 60 * 1000);
|
||||
|
||||
function refresh() {
|
||||
if (calendar_ref.value !== null) {
|
||||
const calendar = calendar_ref.value.getApi() as Calendar;
|
||||
calendar.refetchEvents();
|
||||
}
|
||||
}
|
||||
|
||||
eventDataTransform(eventData: EventInput): EventInput | false {
|
||||
function eventDataTransform(eventData: EventInput): EventInput | false {
|
||||
// clear the url to prevent clicking on the event
|
||||
delete eventData.url;
|
||||
|
||||
@ -92,13 +88,12 @@ export default class App extends Vue {
|
||||
if (match) {
|
||||
const [, member, shop, tool] = match;
|
||||
eventData.title = `${tool} - ${member}`;
|
||||
if (this.toolFilter === null || tool.includes(this.toolFilter)) {
|
||||
if (toolFilter === null || tool.includes(toolFilter)) {
|
||||
return eventData;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss"></style>
|
||||
|
@ -1,4 +0,0 @@
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="index.ts"></script>
|
||||
</body>
|
17
src/index.ts
17
src/index.ts
@ -1,18 +1,7 @@
|
||||
import 'core-js/modules/es.object.entries';
|
||||
|
||||
// TODO: could probably be a dynamic import
|
||||
import intl from 'intl';
|
||||
import 'intl/locale-data/jsonp/en.js';
|
||||
import * as Vue from 'vue';
|
||||
|
||||
if (!window.Intl) {
|
||||
// No `Intl`, so use and load the polyfill.
|
||||
window.Intl = intl;
|
||||
}
|
||||
import App from './App.vue';
|
||||
|
||||
import Vue from 'vue';
|
||||
|
||||
import App from './App';
|
||||
|
||||
let app = new Vue({
|
||||
render: (h) => h(App),
|
||||
}).$mount('#app');
|
||||
const app = Vue.createApp(App).mount('#app');
|
||||
|
@ -1,9 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"strict": true,
|
||||
"module": "es2015",
|
||||
"target": "esnext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true
|
||||
}
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["esnext", "dom"]
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
|
||||
}
|
||||
|
13
vite.config.ts
Normal file
13
vite.config.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import legacy from '@vitejs/plugin-legacy'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
legacy({
|
||||
targets: ['defaults', 'not IE 11', "ios 8.4"]
|
||||
}),
|
||||
],
|
||||
});
|
Loading…
Reference in New Issue
Block a user