Make items links
This commit is contained in:
parent
fdae71b132
commit
cf3fb3e6ef
6 changed files with 39 additions and 54 deletions
|
@ -1,11 +1,15 @@
|
||||||
<template>
|
<template>
|
||||||
<div v-if="Object.keys(sourceItem.threads).length === 1 && '0' in sourceItem.threads" class="relative">
|
<div
|
||||||
<div
|
v-if="Object.keys(sourceItem.threads).length === 1 && '0' in sourceItem.threads"
|
||||||
|
class="relative"
|
||||||
|
:ref="isSelected(0) ? 'highlightedElement' : ''">
|
||||||
|
<a
|
||||||
|
draggable="false"
|
||||||
:style="style()"
|
:style="style()"
|
||||||
:ref="isSelected(0) ? 'highlightedElement' : ''"
|
class="block p-4 border-2 -mt-2px cursor-pointer bg-gray-200 border-gray-800 select-none relative z-20"
|
||||||
class="p-4 border-2 -mt-2px cursor-pointer bg-gray-200 border-gray-800 select-none relative z-20"
|
|
||||||
:class="isSelected(0) ? 'selected shadow-md -mx-2' : ''"
|
:class="isSelected(0) ? 'selected shadow-md -mx-2' : ''"
|
||||||
@click="select(0)"
|
:href="isSelected(0) ? baseUrl : `${baseUrl}/${item.source}/${item.sourceItem}/0`"
|
||||||
|
@click="e => openThread(e, 0)"
|
||||||
@mousedown="e => startDrag(e)"
|
@mousedown="e => startDrag(e)"
|
||||||
@touchstart="e => startDrag(e)">
|
@touchstart="e => startDrag(e)">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
|
@ -30,7 +34,7 @@
|
||||||
class="mt-4 text-sm text-yellow-600">
|
class="mt-4 text-sm text-yellow-600">
|
||||||
Snoozed until {{ new Date(item.threads[0].snoozedUntil).toLocaleString() }}
|
Snoozed until {{ new Date(item.threads[0].snoozedUntil).toLocaleString() }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</a>
|
||||||
<component :is="actionIndicators" />
|
<component :is="actionIndicators" />
|
||||||
</div>
|
</div>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
|
@ -51,18 +55,21 @@
|
||||||
</div>
|
</div>
|
||||||
<component :is="actionIndicators" />
|
<component :is="actionIndicators" />
|
||||||
</div>
|
</div>
|
||||||
<div v-for="(thread, id) in activeThreads" class="relative">
|
<div
|
||||||
<div
|
v-for="(thread, id) in activeThreads"
|
||||||
class="p-4 border-2 -mt-2px cursor-pointer bg-slate-300 border-gray-800 select-none relative z-20"
|
class="relative"
|
||||||
:ref="isSelected(id) ? 'highlightedElement' : ''"
|
:ref="isSelected(id) ? 'highlightedElement' : ''">
|
||||||
|
<a
|
||||||
|
class="block p-4 border-2 -mt-2px cursor-pointer bg-slate-300 border-gray-800 select-none relative z-20"
|
||||||
:class="isSelected(id) ? 'selected shadow-md -mx-2 thread' : ''"
|
:class="isSelected(id) ? 'selected shadow-md -mx-2 thread' : ''"
|
||||||
:style="style(parseInt(id as unknown as string))"
|
:style="style(parseInt(id as unknown as string))"
|
||||||
@click="select(parseInt(id as unknown as string))"
|
:href="isSelected(id) ? baseUrl : `${baseUrl}/${item.source}/${item.sourceItem}/${id}`"
|
||||||
|
@click="e => openThread(e, id)"
|
||||||
@mousemove="drag"
|
@mousemove="drag"
|
||||||
@mousedown="e => startDrag(e, id as unknown as string)"
|
@mousedown="(e: MouseEvent | TouchEvent) => startDrag(e, id as unknown as string)"
|
||||||
@mouseup="endDrag"
|
@mouseup="endDrag"
|
||||||
@touchmove="drag"
|
@touchmove="drag"
|
||||||
@touchstart="e => startDrag(e, id as unknown as string)"
|
@touchstart="(e: MouseEvent | TouchEvent) => startDrag(e, id as unknown as string)"
|
||||||
@touchend="endDrag">
|
@touchend="endDrag">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<Avatar v-if="getContact(id)" v-bind="getContact(id)!" class="mr-2" />
|
<Avatar v-if="getContact(id)" v-bind="getContact(id)!" class="mr-2" />
|
||||||
|
@ -84,7 +91,7 @@
|
||||||
class="mt-4 text-sm text-yellow-600">
|
class="mt-4 text-sm text-yellow-600">
|
||||||
Snoozed until {{ new Date(thread.snoozedUntil).toLocaleString() }}
|
Snoozed until {{ new Date(thread.snoozedUntil).toLocaleString() }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</a>
|
||||||
<component :is="actionIndicators" />
|
<component :is="actionIndicators" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -94,6 +101,7 @@
|
||||||
import { faCheck, faClockRotateLeft } from '@fortawesome/free-solid-svg-icons';
|
import { faCheck, faClockRotateLeft } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
import type { Item, ItemThread, ThreadRef } from "../state";
|
import type { Item, ItemThread, ThreadRef } from "../state";
|
||||||
import { items, sources } from '../state';
|
import { items, sources } from '../state';
|
||||||
import { parseString } from '../utils';
|
import { parseString } from '../utils';
|
||||||
|
@ -103,10 +111,10 @@ const props = defineProps<{
|
||||||
item: Item;
|
item: Item;
|
||||||
selectedThread?: ThreadRef;
|
selectedThread?: ThreadRef;
|
||||||
showSnoozed?: boolean;
|
showSnoozed?: boolean;
|
||||||
|
baseUrl: string;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emits = defineEmits<{
|
const emits = defineEmits<{
|
||||||
select: [thread: number];
|
|
||||||
snoozeItem: [thread: number];
|
snoozeItem: [thread: number];
|
||||||
deselect: [];
|
deselect: [];
|
||||||
}>();
|
}>();
|
||||||
|
@ -119,6 +127,8 @@ const activeThreads = computed(() => Object.keys(props.item.threads).reduce((acc
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<number, ItemThread>));
|
}, {} as Record<number, ItemThread>));
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const dragging = ref(false);
|
const dragging = ref(false);
|
||||||
const dragged = ref(false);
|
const dragged = ref(false);
|
||||||
const draggingX = ref(0);
|
const draggingX = ref(0);
|
||||||
|
@ -214,12 +224,6 @@ function endDrag(e: MouseEvent | TouchEvent) {
|
||||||
window.onpointerleave = null;
|
window.onpointerleave = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function select(thread: number) {
|
|
||||||
if (!dragged.value) {
|
|
||||||
emits("select", thread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteItem() {
|
function deleteItem() {
|
||||||
const index = items.value.findIndex(item => item.source === props.item.source && item.sourceItem === props.item.sourceItem);
|
const index = items.value.findIndex(item => item.source === props.item.source && item.sourceItem === props.item.sourceItem);
|
||||||
const newItems = items.value.slice();
|
const newItems = items.value.slice();
|
||||||
|
@ -232,6 +236,15 @@ function deleteItem() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openThread(e: MouseEvent | TouchEvent, index: number) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!dragged.value) {
|
||||||
|
router.push(
|
||||||
|
isSelected(index) ? props.baseUrl :
|
||||||
|
`${props.baseUrl}/${props.item.source}/${props.item.sourceItem}/${index}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const actionIndicators = () => <div class={{
|
const actionIndicators = () => <div class={{
|
||||||
absolute: true,
|
absolute: true,
|
||||||
"top-0": true,
|
"top-0": true,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
:item="item"
|
:item="item"
|
||||||
:selected-thread="selectedThread"
|
:selected-thread="selectedThread"
|
||||||
:show-snoozed="showSnoozed"
|
:show-snoozed="showSnoozed"
|
||||||
@select="thread => emits('selectItem', item.source, item.sourceItem, thread)"
|
:base-url="baseUrl"
|
||||||
@snoozeItem="thread => emits('snoozeItem', item.source, item.sourceItem, thread)"
|
@snoozeItem="thread => emits('snoozeItem', item.source, item.sourceItem, thread)"
|
||||||
@deselect="emits('deselect')" />
|
@deselect="emits('deselect')" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -24,5 +24,6 @@ defineProps<{
|
||||||
items: StateItem[];
|
items: StateItem[];
|
||||||
selectedThread?: ThreadRef;
|
selectedThread?: ThreadRef;
|
||||||
showSnoozed?: boolean;
|
showSnoozed?: boolean;
|
||||||
|
baseUrl: string;
|
||||||
}>();
|
}>();
|
||||||
</script>
|
</script>
|
|
@ -9,7 +9,7 @@
|
||||||
:items="showSnoozed ? category.snoozedItems : category.activeItems"
|
:items="showSnoozed ? category.snoozedItems : category.activeItems"
|
||||||
:selected-thread="showThread ? selectedItem : undefined"
|
:selected-thread="showThread ? selectedItem : undefined"
|
||||||
:show-snoozed="showSnoozed"
|
:show-snoozed="showSnoozed"
|
||||||
@select-item="selectItem"
|
:base-url="baseUrl"
|
||||||
@snooze-item="snoozeItem"
|
@snooze-item="snoozeItem"
|
||||||
@deselect="close" />
|
@deselect="close" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -67,7 +67,6 @@ const {
|
||||||
snoozingItem,
|
snoozingItem,
|
||||||
snoozing,
|
snoozing,
|
||||||
threadTitle,
|
threadTitle,
|
||||||
selectItem,
|
|
||||||
snoozeItem,
|
snoozeItem,
|
||||||
close,
|
close,
|
||||||
stopSnoozing,
|
stopSnoozing,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<Item v-for="item in items"
|
<Item v-for="item in items"
|
||||||
:item="item"
|
:item="item"
|
||||||
:selected-thread="showThread ? selectedItem : undefined"
|
:selected-thread="showThread ? selectedItem : undefined"
|
||||||
@select="thread => selectItem(item.sourceItem, thread)"
|
base-url="/source"
|
||||||
@snoozeItem="thread => snoozeItem(sourceId, item.sourceItem, thread)"
|
@snoozeItem="thread => snoozeItem(sourceId, item.sourceItem, thread)"
|
||||||
@deselect="close" />
|
@deselect="close" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -90,19 +90,6 @@ const items = computed(() => Object.keys(source.value.items).map(item => {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
function selectItem(sourceItem: number, thread: number) {
|
|
||||||
const p = route.params;
|
|
||||||
const sourceItemInt = parseInt(Array.isArray(p.sourceItem) ? p.sourceItem[0] : p.sourceItem);
|
|
||||||
const threadInt = parseInt(Array.isArray(p.thread) ? p.thread[0] : p.thread);
|
|
||||||
if (sourceItem === sourceItemInt && thread === threadInt) {
|
|
||||||
close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
router.push(`${baseUrl.value}/${sourceItem}/${thread}`);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
showThread,
|
showThread,
|
||||||
selectedItem,
|
selectedItem,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<Item v-for="item in unsortedItems"
|
<Item v-for="item in unsortedItems"
|
||||||
:item="item"
|
:item="item"
|
||||||
:selected-thread="showThread ? selectedItem : undefined"
|
:selected-thread="showThread ? selectedItem : undefined"
|
||||||
@select="thread => selectItem(item.source, item.sourceItem, thread)"
|
:base-url="baseUrl"
|
||||||
@snoozeItem="thread => snoozeItem(item.source, item.sourceItem, thread)"
|
@snoozeItem="thread => snoozeItem(item.source, item.sourceItem, thread)"
|
||||||
@deselect="close" />
|
@deselect="close" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -51,7 +51,6 @@ const {
|
||||||
snoozingItem,
|
snoozingItem,
|
||||||
snoozing,
|
snoozing,
|
||||||
threadTitle,
|
threadTitle,
|
||||||
selectItem,
|
|
||||||
snoozeItem,
|
snoozeItem,
|
||||||
close,
|
close,
|
||||||
stopSnoozing,
|
stopSnoozing,
|
||||||
|
|
|
@ -106,19 +106,6 @@ export function setupSelectedThread(baseUrl: Ref<string>, route: RouteLocationNo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectItem(source: number, sourceItem: number, thread: number) {
|
|
||||||
const p = route.params;
|
|
||||||
const sourceInt = parseInt(Array.isArray(p.source) ? p.source[0] : p.source);
|
|
||||||
const sourceItemInt = parseInt(Array.isArray(p.sourceItem) ? p.sourceItem[0] : p.sourceItem);
|
|
||||||
const threadInt = parseInt(Array.isArray(p.thread) ? p.thread[0] : p.thread);
|
|
||||||
if (source === sourceInt && sourceItem === sourceItemInt && thread === threadInt) {
|
|
||||||
close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
router.push(`${baseUrl.value}/${source}/${sourceItem}/${thread}`);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function snoozeItem(source: number, sourceItem: number, thread: number) {
|
function snoozeItem(source: number, sourceItem: number, thread: number) {
|
||||||
snoozingItem.value = { source, sourceItem, thread };
|
snoozingItem.value = { source, sourceItem, thread };
|
||||||
snoozing.value = true;
|
snoozing.value = true;
|
||||||
|
@ -150,7 +137,6 @@ export function setupSelectedThread(baseUrl: Ref<string>, route: RouteLocationNo
|
||||||
snoozingItem,
|
snoozingItem,
|
||||||
snoozing,
|
snoozing,
|
||||||
threadTitle,
|
threadTitle,
|
||||||
selectItem,
|
|
||||||
snoozeItem,
|
snoozeItem,
|
||||||
close,
|
close,
|
||||||
stopSnoozing,
|
stopSnoozing,
|
||||||
|
|
Loading…
Add table
Reference in a new issue