Skip to content

Commit

Permalink
[refactor] fix modals
Browse files Browse the repository at this point in the history
  • Loading branch information
acvigue committed Jul 27, 2023
1 parent c25fabb commit bcafa4f
Show file tree
Hide file tree
Showing 31 changed files with 310 additions and 381 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<title>Tranquil</title>
</head>
<body>
<div id="app" class="w-full h-full"></div>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const loader = useLoader()
</script>

<template>
<RouterView v-slot="{ Component, route }" class="h-[calc(100dvh-3.5rem)]">
<RouterView v-slot="{ Component, route }">
<Transition name="fade" mode="out-in">
<component :is="Component" :key="route.path" />
<component :is="Component" :key="route.path" class="mb-20" />
</Transition>
</RouterView>

Expand Down
6 changes: 2 additions & 4 deletions src/components/PatternGridItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const isPatternDownloaded = computed(() => {
>
<HeartIcon class="absolute z-20 top-3 right-3 text-red-400 w-4 md:w-7" v-if="item.isFavorite" />
<ArrowDownTrayIcon
class="absolute z-20 top-3 right-3 text-orange-400 w-3 md:w-6"
class="absolute z-20 top-3 right-3 text-orange-400 w-5 md:w-5"
v-if="!isPatternDownloaded"
/>
<PatternPreview
Expand All @@ -37,9 +37,7 @@ const isPatternDownloaded = computed(() => {
class="h-36 w-36 md:h-44 md:w-44 rounded-full border-gray-500 border-[3px] bg-gray-800 group-hover:scale-105 transition transform-gpu duration-300"
lineColor="#ffffff"
/>
<span
class="w-[90%] text-center text-md font-medium line-clamp-1 text-ellipsis break-words"
>
<span class="w-[90%] text-center text-md font-medium line-clamp-1 text-ellipsis break-words">
{{ item.name }}</span
>
</button>
Expand Down
54 changes: 29 additions & 25 deletions src/components/PatternPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface PatternPreviewProps {
lineColor: string
pattern?: Pattern
mode: 'thumb' | 'render'
progress?: number
}
const props = defineProps<PatternPreviewProps>()
Expand All @@ -24,6 +25,7 @@ const isLoaded = ref(false)
const thumbSrc = ref('')
let patternData: [number, number][] = []
let uninterpolatedData: [number, number][] = []
let patternID = ''
onMounted(async () => {
Expand Down Expand Up @@ -69,25 +71,28 @@ const getPatternData = async () => {
}
let patternDataResponse
try {
patternDataResponse = await tranquilapi.get(`/patterns/${props.pattern.uuid}/data`)
} catch (e) {
throw new Error(`Pattern preview generation failed for ${props.pattern.name}`)
}
const patternDataRaw = patternDataResponse.data
const uninterpolatedData: [number, number][] = []
for (const patternDataLine of (patternDataRaw as string).split('\n')) {
if (patternDataLine.charAt(0) === '#') {
continue
if (uninterpolatedData.length === 0 || patternID != props.pattern.uuid) {
try {
patternDataResponse = await tranquilapi.get(`/patterns/${props.pattern.uuid}/data`)
patternID = props.pattern.uuid
} catch (e) {
throw new Error(`Pattern preview generation failed for ${props.pattern.name}`)
}
const patternCoordinates = patternDataLine.split(' ')
const theta = parseFloat(patternCoordinates[0])
const rho = parseFloat(patternCoordinates[1])
uninterpolatedData.push([theta, rho])
const patternDataRaw = patternDataResponse.data
for (const patternDataLine of (patternDataRaw as string).split('\n')) {
if (patternDataLine.charAt(0) === '#') {
continue
}
const patternCoordinates = patternDataLine.split(' ')
const theta = parseFloat(patternCoordinates[0])
const rho = parseFloat(patternCoordinates[1])
uninterpolatedData.push([theta, rho])
}
}
patternData = []
patternData.push(uninterpolatedData[0])
let previousPoint = uninterpolatedData[0]
for (const uninterpolatedPoint of uninterpolatedData) {
Expand Down Expand Up @@ -116,15 +121,15 @@ const render = async () => {
return
}
if (patternID != props.pattern.uuid) {
patternData = []
try {
await getPatternData()
} catch (e) {
isLoaded.value = true
return
}
patternID = props.pattern.uuid
try {
await getPatternData()
} catch (e) {
isLoaded.value = true
return
}
if (props.progress) {
patternData = patternData.slice(0, Math.floor(patternData.length * props.progress))
}
context.value.strokeStyle = props.lineColor
Expand All @@ -150,7 +155,6 @@ const render = async () => {
}
watch(props, async () => {
console.log('watcher')
await render()
})
</script>
Expand Down
4 changes: 1 addition & 3 deletions src/components/PlaylistGridItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ const isPlaylistDownloaded = computed(() => {
class="h-36 w-36 md:h-44 md:w-44 rounded-full border-gray-500 border-[3px] bg-gray-800 group-hover:scale-105 transition transform-gpu duration-300"
lineColor="#ffffff"
/>
<span
class="w-[90%] text-center text-md font-medium line-clamp-1 text-ellipsis break-words"
>
<span class="w-[90%] text-center text-md font-medium line-clamp-1 text-ellipsis break-words">
{{ item.name }}</span
>
</button>
Expand Down
21 changes: 21 additions & 0 deletions src/components/SettingsButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script setup lang="ts">
import { ArrowRightIcon } from '@heroicons/vue/24/outline'
interface SettingsButtonProps {
title: string
}
defineProps<SettingsButtonProps>()
const emit = defineEmits(['click'])
</script>

<template>
<button
@click="emit('click')"
class="flex w-full justify-between items-center p-4 bg-gray-700 hover:bg-gray-600 rounded-xl transform-gpu duration-300"
>
<span class="text-lg font-medium">{{ title }}</span>
<ArrowRightIcon class="w-6 h-6"></ArrowRightIcon>
</button>
</template>
2 changes: 1 addition & 1 deletion src/components/modals/AboutModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const emit = defineEmits<{
async function checkForUpdate() {
loader.showLoader('update')
await table.get("/update")
await table.get('/update')
loader.hideLoader('update')
toast.info('Update queued')
}
Expand Down
1 change: 0 additions & 1 deletion src/components/modals/AddItemToPlaylistModal.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script setup lang="ts">
import { type Pattern, default as useFilesStore } from '@/stores/files'
import { FormKit } from '@formkit/vue'
import { XMarkIcon } from '@heroicons/vue/24/outline'
import ModalHeader from './helpers/ModalHeader.vue'
import ModalTemplate from './helpers/ModalTemplate.vue'
Expand Down
14 changes: 0 additions & 14 deletions src/components/modals/AdvancedLightsSettingsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,3 @@ const lights = useTableLightsStore()
/>
</ModalTemplate>
</template>

<style>
.vue-swatches__container {
@apply border-[2px] border-gray-400;
}
.vue-swatches {
@apply !flex !justify-center !items-center;
}
.vue-swatches__trigger__wrapper {
@apply border-[2px] border-gray-400 rounded-xl;
}
</style>
2 changes: 1 addition & 1 deletion src/components/modals/DeleteConfirmationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const emit = defineEmits<{

<template>
<ModalTemplate border-color="red" @close="emit('close')">
<ModalHeader title="Are you sure?" @close="emit('close')"/>
<ModalHeader title="Are you sure?" @close="emit('close')" />
<div class="flex flex-col gap-8">
<span class="text-md font-medium w-full text-center">
Deleting '{{ itemName.trim() }}' cannot be undone
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/LightsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const emit = defineEmits<{
const effects = [
{ label: 'Solid', value: 0 },
{ label: 'Rainbow', value: 1 },
{ label: 'Motion Tracked', value: 2 }
{ label: 'Motion Tracked', value: 2 },
]
const lights = useTableLightsStore()
Expand Down
8 changes: 3 additions & 5 deletions src/components/modals/NewPlaylistModal.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script setup lang="ts">
import { VueFinalModal } from 'vue-final-modal'
import useFilesStore, { type Playlist } from '@/stores/files'
import { FormKit } from '@formkit/vue'
import { v4 as uuidv4 } from 'uuid'
import { XMarkIcon } from '@heroicons/vue/24/outline'
import { useToast } from 'vue-toast-notification'
import ModalTemplate from './helpers/ModalTemplate.vue'
import ModalHeader from './helpers/ModalHeader.vue'
Expand Down Expand Up @@ -33,9 +31,9 @@ const emit = defineEmits<{

<template>
<ModalTemplate @close="emit('close')">
<ModalHeader title="New Playlist" @close="emit('close')"/>
<ModalHeader title="New Playlist" @close="emit('close')" />
<FormKit type="form" @submit="formHandler" submit-label="Create">
<FormKit type="text" name="name" id="name" label="Playlist Name" validation="required" />
</FormKit>
<FormKit type="text" name="name" id="name" label="Playlist Name" validation="required" />
</FormKit>
</ModalTemplate>
</template>
2 changes: 1 addition & 1 deletion src/components/modals/OverplayConfirmationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const emit = defineEmits<{

<template>
<ModalTemplate @close="emit('close')">
<ModalHeader title="Wait!" @close="emit('close')"/>
<ModalHeader title="Wait!" @close="emit('close')" />
<span class="text-md text-medium"
>'{{ currentlyPlayingItemName }}' is already playing. Continuing will stop playback.</span
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/PatternModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const isCurrentlyPlayingThisPattern = computed(() => {
<div class="flex justify-center flex-col items-center">
<PatternPreview
:pattern="pattern"
mode="render"
mode="thumb"
class="md:h-80 md:w-80 w-[60vw] h-[60vw] rounded-full border-gray-500 border-[3px] bg-gray-800 group-hover:scale-105 transition transform-gpu duration-300"
lineColor="#ffffff"
/>
Expand Down
Loading

0 comments on commit bcafa4f

Please sign in to comment.