feat: added ts
This commit is contained in:
@@ -4,7 +4,7 @@ export default defineConfig({
|
|||||||
e2e: {
|
e2e: {
|
||||||
baseUrl: 'http://localhost:5173',
|
baseUrl: 'http://localhost:5173',
|
||||||
supportFile: 'tests/e2e/support/e2e.js',
|
supportFile: 'tests/e2e/support/e2e.js',
|
||||||
specPattern: 'tests/e2e/specs/**/*.cy.{js,jsx}',
|
specPattern: 'tests/e2e/specs/**/*.cy.{js,jsx,ts,tsx}',
|
||||||
videosFolder: 'tests/e2e/videos',
|
videosFolder: 'tests/e2e/videos',
|
||||||
screenshotsFolder: 'tests/e2e/screenshots',
|
screenshotsFolder: 'tests/e2e/screenshots',
|
||||||
setupNodeEvents(on, config) {
|
setupNodeEvents(on, config) {
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module" src="/src/main.js"></script>
|
<script type="module" src="/src/main.ts"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -5,5 +5,5 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { IonApp, IonRouterOutlet } from '@ionic/vue'
|
import { IonApp, IonRouterOutlet } from '@ionic/vue'
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { appLocalDataDir } from '@tauri-apps/api/path';
|
import { appLocalDataDir } from '@tauri-apps/api/path';
|
||||||
|
|
||||||
export async function getDB_URL() {
|
/** Возвращает URL подключения к SQLite */
|
||||||
// Функция верёнт путь до бд
|
export async function getDB_URL(): Promise<string> {
|
||||||
|
|
||||||
const appDir = await appLocalDataDir();
|
const appDir = await appLocalDataDir();
|
||||||
return `sqlite:${appDir}/timer.db`;
|
return `sqlite:${appDir}/timer.db`;
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { getDb } from "../initDb";
|
|
||||||
import { SELECT_TIMERS } from "../dml/timerDML";
|
|
||||||
|
|
||||||
|
|
||||||
export async function getTimers() {
|
|
||||||
// Функция для получения списка таймеров
|
|
||||||
|
|
||||||
const db = await getDb();
|
|
||||||
return await db.select(SELECT_TIMERS);
|
|
||||||
}
|
|
||||||
10
client/src/db/crud/timerCrud.ts
Normal file
10
client/src/db/crud/timerCrud.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { getDb } from "@/db/initDb";
|
||||||
|
import { SELECT_TIMERS } from "@/db/dml/timerDML";
|
||||||
|
import { TimersRow } from "@/types/timerType"
|
||||||
|
|
||||||
|
|
||||||
|
/** Получает список таймеров */
|
||||||
|
export async function getTimers(): Promise<TimersRow[]> {
|
||||||
|
const db = await getDb();
|
||||||
|
return await db.select<TimersRow[]>(SELECT_TIMERS);
|
||||||
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
import Database from '@tauri-apps/plugin-sql';
|
import Database from '@tauri-apps/plugin-sql';
|
||||||
import { CREATE_TIMER } from './ddl/timerDDL';
|
import { CREATE_TIMER } from '@/db/ddl/timerDDL';
|
||||||
import { getDB_URL } from '../config';
|
import { getDB_URL } from '@/config';
|
||||||
import { seedDb } from './seed';
|
import { seedDb } from '@/db/seed';
|
||||||
|
|
||||||
let dbPromise = null;
|
let dbPromise: Promise<Database> | null = null;
|
||||||
|
|
||||||
export async function getDb() {
|
|
||||||
// Функция для получения подключения к базе данных
|
|
||||||
|
|
||||||
|
/** Получает подключение к бд */
|
||||||
|
export async function getDb(): Promise<Database> {
|
||||||
if (!dbPromise) {
|
if (!dbPromise) {
|
||||||
dbPromise = (async () => {
|
dbPromise = (async () => {
|
||||||
try {
|
try {
|
||||||
@@ -22,5 +21,5 @@ export async function getDb() {
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
return await dbPromise; // await для консистентности
|
return await dbPromise;
|
||||||
}
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { INSERT_SEED_DB, COUNT_TIMERS } from './dml/timerDML'
|
|
||||||
|
|
||||||
|
|
||||||
export async function seedDb(db) {
|
|
||||||
// Функция для заполнения бд данными
|
|
||||||
|
|
||||||
const count = await db.select(COUNT_TIMERS);
|
|
||||||
if (count[0].cnt === 0) {
|
|
||||||
await db.execute(INSERT_SEED_DB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
client/src/db/seed.ts
Normal file
14
client/src/db/seed.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import Database from '@tauri-apps/plugin-sql';
|
||||||
|
import { INSERT_SEED_DB, COUNT_TIMERS } from '@/db/dml/timerDML'
|
||||||
|
import { CountRow } from '@/types/timerType'
|
||||||
|
|
||||||
|
|
||||||
|
/** Заполняет бд данными (демо таймерами) */
|
||||||
|
export async function seedDb(db: Database) {
|
||||||
|
|
||||||
|
const count = await db.select<CountRow[]>(COUNT_TIMERS);
|
||||||
|
const cnt = count[0]?.cnt ?? 0;
|
||||||
|
if (cnt === 0) {
|
||||||
|
await db.execute(INSERT_SEED_DB);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import App from './App.vue'
|
import App from '@/App.vue'
|
||||||
import router from './router';
|
import router from '@/router';
|
||||||
|
|
||||||
import { IonicVue } from '@ionic/vue';
|
import { IonicVue } from '@ionic/vue';
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ import '@ionic/vue/css/flex-utils.css';
|
|||||||
import '@ionic/vue/css/display.css';
|
import '@ionic/vue/css/display.css';
|
||||||
|
|
||||||
/* Theme variables */
|
/* Theme variables */
|
||||||
import './theme/variables.css';
|
import '@/theme/variables.css';
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
.use(IonicVue)
|
.use(IonicVue)
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { createRouter, createWebHistory } from '@ionic/vue-router';
|
import { createRouter, createWebHistory } from '@ionic/vue-router';
|
||||||
import TimersList from '../views/TimersList/TimersList.vue';
|
import type { RouteRecordRaw } from 'vue-router';
|
||||||
|
import TimersList from '@/views/TimersList/TimersList.vue';
|
||||||
|
|
||||||
const routes = [
|
const routes: RouteRecordRaw[] = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
redirect: '/timers'
|
redirect: '/timers'
|
||||||
8
client/src/types/timerType.ts
Normal file
8
client/src/types/timerType.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export type TimersRow = {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
pomodoro_time: number;
|
||||||
|
count_pomodoro: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CountRow = { cnt: number };
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import { IonIcon } from '@ionic/vue';
|
|
||||||
import {
|
|
||||||
timerOutline,
|
|
||||||
chevronUp,
|
|
||||||
chevronDown,
|
|
||||||
playCircleOutline,
|
|
||||||
pencilOutline,
|
|
||||||
trashOutline
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
|
|
||||||
import { ref, onMounted } from 'vue';
|
|
||||||
import { getTimers } from '../../db/crud/timerCrud';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'TimersList',
|
|
||||||
components: {
|
|
||||||
IonIcon,
|
|
||||||
},
|
|
||||||
setup() {
|
|
||||||
const timers = ref([]);
|
|
||||||
const loading = ref(true);
|
|
||||||
const error = ref(null);
|
|
||||||
const expandedId = ref(null);
|
|
||||||
|
|
||||||
const loadTimers = async () => {
|
|
||||||
loading.value = true;
|
|
||||||
error.value = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await getTimers();
|
|
||||||
timers.value = result;
|
|
||||||
} catch (err) {
|
|
||||||
error.value = err.message || 'Ошибка загрузки таймеров';
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggleExpand = (id) => {
|
|
||||||
expandedId.value = expandedId.value === id ? null : id;
|
|
||||||
};
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadTimers();
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
// состояние
|
|
||||||
timers,
|
|
||||||
loading,
|
|
||||||
error,
|
|
||||||
expandedId,
|
|
||||||
|
|
||||||
// методы
|
|
||||||
toggleExpand,
|
|
||||||
|
|
||||||
// иконки
|
|
||||||
timerOutline,
|
|
||||||
chevronUp,
|
|
||||||
chevronDown,
|
|
||||||
playCircleOutline,
|
|
||||||
pencilOutline,
|
|
||||||
trashOutline,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
60
client/src/views/TimersList/TimersList.ts
Normal file
60
client/src/views/TimersList/TimersList.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { defineComponent, onMounted, ref } from 'vue'
|
||||||
|
import { IonIcon } from '@ionic/vue'
|
||||||
|
import {
|
||||||
|
timerOutline,
|
||||||
|
chevronUp,
|
||||||
|
chevronDown,
|
||||||
|
playCircleOutline,
|
||||||
|
pencilOutline,
|
||||||
|
trashOutline,
|
||||||
|
} from 'ionicons/icons'
|
||||||
|
|
||||||
|
import { getTimers } from '@/db/crud/timerCrud'
|
||||||
|
import type { TimersRow } from '@/types/timerType'
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'TimersList',
|
||||||
|
components: { IonIcon },
|
||||||
|
setup() {
|
||||||
|
const timers = ref<TimersRow[]>([])
|
||||||
|
const loading = ref<boolean>(true)
|
||||||
|
const error = ref<string | null>(null)
|
||||||
|
const expandedId = ref<number | null>(null)
|
||||||
|
|
||||||
|
const loadTimers = async (): Promise<void> => {
|
||||||
|
loading.value = true
|
||||||
|
error.value = null
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await getTimers()
|
||||||
|
timers.value = result
|
||||||
|
} catch (e: unknown) {
|
||||||
|
error.value = e instanceof Error ? e.message : 'Ошибка загрузки таймеров'
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleExpand = (id: number): void => {
|
||||||
|
expandedId.value = expandedId.value === id ? null : id
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(loadTimers)
|
||||||
|
|
||||||
|
return {
|
||||||
|
timers,
|
||||||
|
loading,
|
||||||
|
error,
|
||||||
|
expandedId,
|
||||||
|
|
||||||
|
toggleExpand,
|
||||||
|
|
||||||
|
timerOutline,
|
||||||
|
chevronUp,
|
||||||
|
chevronDown,
|
||||||
|
playCircleOutline,
|
||||||
|
pencilOutline,
|
||||||
|
trashOutline,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- TimersList.vue -->
|
<!-- TimersList.vue -->
|
||||||
<template src="./TimersList.html"></template>
|
<template src="@/views/TimersList/TimersList.html"></template>
|
||||||
<script src="./TimersList.js"></script>
|
<script lang="ts" src="@/views/TimersList/TimersList.ts"></script>
|
||||||
<style src="./TimersList.css" scoped></style>
|
<style src="@/views/TimersList/TimersList.css" scoped></style>
|
||||||
|
|||||||
1
client/src/vite-env.d.ts
vendored
Normal file
1
client/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
11
client/tsconfig.json
Normal file
11
client/tsconfig.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["src/*"]
|
||||||
|
},
|
||||||
|
"module": "ESNext",
|
||||||
|
"target": "ES2020",
|
||||||
|
"moduleResolution": "Bundler"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn apply_linux_webkit_cli_flags() {
|
||||||
|
let disable = std::env::args().any(|a| a == "--disable-webkit-compositing");
|
||||||
|
if disable {
|
||||||
|
unsafe { std::env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
|
apply_linux_webkit_cli_flags();
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_sql::Builder::default().build())
|
.plugin(tauri_plugin_sql::Builder::default().build())
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
|
||||||
"productName": "Kawai-Focus",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"identifier": "com.kawai.focus",
|
|
||||||
"build": {
|
|
||||||
"frontendDist": "../../client/dist",
|
|
||||||
"devUrl": "http://localhost:8100",
|
|
||||||
"beforeDevCommand": "cd ../client && ionic serve",
|
|
||||||
"beforeBuildCommand": "cd ../client && npm run build"
|
|
||||||
},
|
|
||||||
"app": {
|
|
||||||
"withGlobalTauri": true,
|
|
||||||
"windows": [
|
|
||||||
{
|
|
||||||
"label": "main",
|
|
||||||
"title": "Kawai-Focus",
|
|
||||||
"width": 800,
|
|
||||||
"height": 600,
|
|
||||||
"resizable": true,
|
|
||||||
"fullscreen": false,
|
|
||||||
"devtools": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"security": {
|
|
||||||
"csp": null,
|
|
||||||
"capabilities": ["default"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"bundle": {
|
|
||||||
"active": true,
|
|
||||||
"targets": "all",
|
|
||||||
"icon": [
|
|
||||||
"icons/32x32.png",
|
|
||||||
"icons/128x128.png",
|
|
||||||
"icons/128x128@2x.png",
|
|
||||||
"icons/icon.icns",
|
|
||||||
"icons/icon.ico"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user