Skip to content

Commit

Permalink
start using prettier for frontend formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
h1-the-swan committed Jul 13, 2024
1 parent 9902e7a commit b4ce6e0
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 198 deletions.
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ services:
- ./mydiary-vuetify/package.json:/usr/local/src/app/mydiary-vuetify/package.json
- ./mydiary-vuetify/tsconfig.json:/usr/local/src/app/mydiary-vuetify/tsconfig.json
- ./mydiary-vuetify/tsconfig.node.json:/usr/local/src/app/mydiary-vuetify/tsconfig.node.json
- ./mydiary-vuetify/.prettierrc:/usr/local/src/app/mydiary-vuetify/.prettierrc
- ./mydiary-vuetify/package-lock.json:/usr/local/src/app/mydiary-vuetify/package-lock.json
- ./mydiary-vuetify/vite.config.ts:/usr/local/src/app/mydiary-vuetify/vite.config.ts
- /etc/passwd:/etc/passwd:ro
Expand Down
3 changes: 2 additions & 1 deletion mydiary-vuetify/.devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"Vue.volar"
"Vue.volar",
"esbenp.prettier-vscode"
]
}
}
Expand Down
5 changes: 0 additions & 5 deletions mydiary-vuetify/.editorconfig

This file was deleted.

6 changes: 6 additions & 0 deletions mydiary-vuetify/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
111 changes: 60 additions & 51 deletions mydiary-vuetify/src/components/NextcloudThumbnails.vue
Original file line number Diff line number Diff line change
@@ -1,84 +1,93 @@
<template>
<div v-if="nextCloudThumbs">
<v-form @submit.prevent="onSubmit">
<v-row>
<v-col
v-for="(nImage) in nextCloudThumbs"
:key="nImage.url"
class="d-flex child-flex nextcloud-thumb"
:class="{selectedImg: nImage.selected}"
cols="4"
>
<v-img
:src="nImage.src"
aspect-ratio="1"
@click="nImage.selected = !nImage.selected"
></v-img>
</v-col>
</v-row>
<v-btn class="mt-2" type="submit" block>Submit</v-btn>
</v-form>
</div>
<div v-if="nextCloudThumbs">
<v-form @submit.prevent="onSubmit">
<v-row>
<v-col
v-for="nImage in nextCloudThumbs"
:key="nImage.url"
class="d-flex child-flex nextcloud-thumb"
:class="{ selectedImg: nImage.selected }"
cols="4"
>
<v-img
:src="nImage.src"
aspect-ratio="1"
@click="nImage.selected = !nImage.selected"
></v-img>
</v-col>
</v-row>
<v-btn class="mt-2" type="submit" block>Submit</v-btn>
</v-form>
</div>
</template>

<script setup lang="ts">
import Axios from 'axios'
Axios.defaults.baseURL = '/api'
import { nextcloudPhotosThumbnailUrls, joplinNoteImages, MyDiaryImageRead } from '@/api'
import { ref, watch, watchEffect } from 'vue';
import {
nextcloudPhotosThumbnailUrls,
joplinNoteImages,
MyDiaryImageRead,
} from '@/api'
import { ref, watch, watchEffect } from 'vue'
const props = defineProps<{
dt: string;
joplinNoteId?: string;
dt: string
joplinNoteId?: string
}>()
interface INextCloudThumb {
url: string;
src: string;
selected: boolean;
url: string
src: string
selected: boolean
}
const nextCloudThumbs = ref<INextCloudThumb[]>([])
const diaryNoteImages = ref<MyDiaryImageRead[]>([])
async function fetchImageUrls() {
const imgUrls = (await nextcloudPhotosThumbnailUrls(props.dt)).data
nextCloudThumbs.value = imgUrls.map((url => {
return {
url: url,
src: `/api/nextcloud/thumbnail_img?url=${url}`,
selected: false
}
}))
const imgUrls = (await nextcloudPhotosThumbnailUrls(props.dt)).data
nextCloudThumbs.value = imgUrls.map((url) => {
return {
url: url,
src: `/api/nextcloud/thumbnail_img?url=${url}`,
selected: false,
}
})
}
async function fetchJoplinNoteImages() {
diaryNoteImages.value = []
if (props.joplinNoteId) {
diaryNoteImages.value = (await joplinNoteImages(props.joplinNoteId)).data
}
diaryNoteImages.value = []
if (props.joplinNoteId) {
diaryNoteImages.value = (
await joplinNoteImages(props.joplinNoteId)
).data
}
}
watch(props, fetchImageUrls, { immediate: true })
watch(props, fetchJoplinNoteImages, { immediate: true })
watchEffect(() => {
const existingUrls = diaryNoteImages.value.map((item) => item.nextcloud_path)
nextCloudThumbs.value.forEach((item) => item.selected = existingUrls.includes(item.url))
const existingUrls = diaryNoteImages.value.map(
(item) => item.nextcloud_path
)
nextCloudThumbs.value.forEach(
(item) => (item.selected = existingUrls.includes(item.url))
)
})
watchEffect(() => {
const numSelected = nextCloudThumbs.value.filter((t => t.selected)).length
console.log(`${numSelected} selected!`)
console.log(nextCloudThumbs.value)
const numSelected = nextCloudThumbs.value.filter((t) => t.selected).length
console.log(`${numSelected} selected!`)
console.log(nextCloudThumbs.value)
})
function onSubmit() {
const numSelected = nextCloudThumbs.value.filter((t => t.selected)).length
console.log(`submitted! ${numSelected} selected!`)
// TODO: implement add thumbnail to joplin
const numSelected = nextCloudThumbs.value.filter((t) => t.selected).length
console.log(`submitted! ${numSelected} selected!`)
// TODO: implement add thumbnail to joplin
}
</script>

<style>
.nextcloud-thumb {
opacity: 50%;
opacity: 50%;
}
.nextcloud-thumb.selectedImg {
opacity: 100%;
opacity: 100%;
}
</style>
</style>
2 changes: 1 addition & 1 deletion mydiary-vuetify/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const app = createApp(App)

registerPlugins(app)

import { setupCalendar } from 'v-calendar';
import { setupCalendar } from 'v-calendar'

// Use calendar defaults (optional)
app.use(setupCalendar, {})
Expand Down
50 changes: 32 additions & 18 deletions mydiary-vuetify/src/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import { defineStore } from 'pinia'
import { computed, nextTick, ref, watchEffect } from 'vue'
import Axios from 'axios'
import { readPerformSongsList, PerformSongRead, spotifyHistoryCount, joplinGetInfoAllDays } from '@/api'
import {
readPerformSongsList,
PerformSongRead,
spotifyHistoryCount,
joplinGetInfoAllDays,
} from '@/api'

// export const useAppStore = defineStore('app', {
// state: () => ({
Expand All @@ -11,24 +16,33 @@ import { readPerformSongsList, PerformSongRead, spotifyHistoryCount, joplinGetIn
// })

export const useAppStore = defineStore('app', () => {
Axios.defaults.baseURL = '/api'
Axios.defaults.baseURL = '/api'

const performSongs = ref<PerformSongRead[]>()
async function loadPerformSongs() {
performSongs.value = await readPerformSongsList({ limit: 5000 })
.then((res) => {
return res.data.sort((a, b) => a.name.localeCompare(b.name))
})
}
function getPerformSongById(id: number) {
if (!performSongs.value) return
return performSongs.value.filter((performSong) => performSong.id === id)[0]
}
const performSongs = ref<PerformSongRead[]>()
async function loadPerformSongs() {
performSongs.value = await readPerformSongsList({ limit: 5000 }).then(
(res) => {
return res.data.sort((a, b) => a.name.localeCompare(b.name))
}
)
}
function getPerformSongById(id: number) {
if (!performSongs.value) return
return performSongs.value.filter(
(performSong) => performSong.id === id
)[0]
}

const joplinInfoAllDays = ref<any>()
async function loadJoplinInfoAllDays() {
joplinInfoAllDays.value = (await joplinGetInfoAllDays()).data
}
const joplinInfoAllDays = ref<any>()
async function loadJoplinInfoAllDays() {
joplinInfoAllDays.value = (await joplinGetInfoAllDays()).data
}

return { performSongs, loadPerformSongs, getPerformSongById, joplinInfoAllDays, loadJoplinInfoAllDays }
return {
performSongs,
loadPerformSongs,
getPerformSongById,
joplinInfoAllDays,
loadJoplinInfoAllDays,
}
})
83 changes: 48 additions & 35 deletions mydiary-vuetify/src/views/PerformSongs.vue
Original file line number Diff line number Diff line change
@@ -1,49 +1,62 @@
<template>
<v-container>
<v-list>
<v-list-item>
<PerformSongsDropdown v-if="performSongsList" :items="performSongsList" />
</v-list-item>
<v-list-item>
<PerformSongsRandomButton v-if="performSongsList" :items="performSongsList" :current-id="Number(props.id)" />
</v-list-item>
</v-list>
<PerformSongCard :perform-song="performSong" :image-url="imageUrl" />
<PerformSongEdit :perform-song="performSong" />
</v-container>
<v-container>
<v-list>
<v-list-item>
<PerformSongsDropdown
v-if="performSongsList"
:items="performSongsList"
/>
</v-list-item>
<v-list-item>
<PerformSongsRandomButton
v-if="performSongsList"
:items="performSongsList"
:current-id="Number(props.id)"
/>
</v-list-item>
</v-list>
<PerformSongCard :perform-song="performSong" :image-url="imageUrl" />
<PerformSongEdit :perform-song="performSong" />
</v-container>
</template>

<script lang="ts" setup>
import PerformSongCard from '@/components/PerformSongCard.vue';
import PerformSongsDropdown from '@/components/PerformSongsDropdown.vue';
import PerformSongsRandomButton from '@/components/PerformSongsRandomButton.vue';
import PerformSongEdit from '@/components/PerformSongEdit.vue';
import PerformSongCard from '@/components/PerformSongCard.vue'
import PerformSongsDropdown from '@/components/PerformSongsDropdown.vue'
import PerformSongsRandomButton from '@/components/PerformSongsRandomButton.vue'
import PerformSongEdit from '@/components/PerformSongEdit.vue'
import { computed, nextTick, ref, watch, watchEffect } from 'vue'
import Axios from 'axios';
Axios.defaults.baseURL = '/api';
import { readPerformSong, PerformSongRead, getSpotifyImageUrl, readPerformSongsList } from '@/api';
import { onMounted } from 'vue';
import { useAppStore } from '@/store/app';
import Axios from 'axios'
Axios.defaults.baseURL = '/api'
import {
readPerformSong,
PerformSongRead,
getSpotifyImageUrl,
readPerformSongsList,
} from '@/api'
import { onMounted } from 'vue'
import { useAppStore } from '@/store/app'
const app = useAppStore()
const props = defineProps<{
id: number | string | undefined;
}>();
const performSong = ref<PerformSongRead>();
const imageUrl = ref('');
const performSongsList = ref<PerformSongRead[]>();
id: number | string | undefined
}>()
const performSong = ref<PerformSongRead>()
const imageUrl = ref('')
const performSongsList = ref<PerformSongRead[]>()
onMounted(async () => {
await app.loadPerformSongs()
performSongsList.value = app.performSongs
await app.loadPerformSongs()
performSongsList.value = app.performSongs
})
watchEffect(async () => {
imageUrl.value = '';
// performSong.value = await readPerformSong(Number(props.id)).then((res) => res.data);
performSong.value = app.getPerformSongById(Number(props.id))
imageUrl.value = ''
// performSong.value = await readPerformSong(Number(props.id)).then((res) => res.data);
performSong.value = app.getPerformSongById(Number(props.id))
})
watchEffect(async () => {
if (performSong.value && performSong.value.spotify_id) {
imageUrl.value = await getSpotifyImageUrl(performSong.value.spotify_id).then((res) => res.data);
}
if (performSong.value && performSong.value.spotify_id) {
imageUrl.value = await getSpotifyImageUrl(
performSong.value.spotify_id
).then((res) => res.data)
}
})
</script>

Loading

0 comments on commit b4ce6e0

Please sign in to comment.