11<script setup lang="ts">
22import { escapeLike , Zero } from ' @rocicorp/zero'
3- import { useQuery } from ' zero-vue'
4- import { computed , ref } from ' vue'
53import { decodeJwt } from ' jose'
64import Cookies from ' js-cookie'
5+ import { computed , ref } from ' vue'
6+ import { useQuery } from ' zero-vue'
77
8+ import { useInterval } from ' ~/composables/use-interval'
89import { randomMessage } from ' ~/db/data/test-data'
910import { schema } from ' ~/db/schema'
10- import { useInterval } from ' ~/composables/use-interval'
11- import { randInt } from ' ~/utils/rand'
1211import { formatDate } from ' ~/utils/date'
12+ import { randInt } from ' ~/utils/rand'
1313
1414const encodedJWT = Cookies .get (' jwt' )
1515const decodedJWT = encodedJWT && decodeJwt (encodedJWT )
@@ -52,7 +52,7 @@ const filteredMessages = useQuery(() => {
5252
5353const hasFilters = computed (() => filterUser .value || filterText .value )
5454
55- const deleteRandomMessage = () => {
55+ function deleteRandomMessage() {
5656 if (allMessages .value .length === 0 ) {
5757 return false
5858 }
@@ -62,12 +62,12 @@ const deleteRandomMessage = () => {
6262 return true
6363}
6464
65- const addRandomMessage = () => {
65+ function addRandomMessage() {
6666 z .mutate .message .insert (randomMessage (users .value , mediums .value ))
6767 return true
6868}
6969
70- const handleAction = () => {
70+ function handleAction() {
7171 if (action .value === ' add' ) {
7272 return addRandomMessage ()
7373 }
@@ -89,15 +89,16 @@ useInterval(
8989
9090const INITIAL_HOLD_DELAY_MS = 300
9191let holdTimer: number | null = null
92- const handleAddAction = () => {
92+ function handleAddAction() {
9393 addRandomMessage ()
9494 holdTimer = setTimeout (() => {
9595 action .value = ' add'
9696 }, INITIAL_HOLD_DELAY_MS )
9797}
9898
99- const handleRemoveAction = (e : MouseEvent | TouchEvent ) => {
99+ function handleRemoveAction(e : MouseEvent | TouchEvent ) {
100100 if (z .userID === ' anon' && ' shiftKey' in e && ! e .shiftKey ) {
101+ // eslint-disable-next-line no-alert
101102 alert (' You must be logged in to delete. Hold shift to try anyway.' )
102103 return
103104 }
@@ -108,7 +109,7 @@ const handleRemoveAction = (e: MouseEvent | TouchEvent) => {
108109 }, INITIAL_HOLD_DELAY_MS )
109110}
110111
111- const stopAction = () => {
112+ function stopAction() {
112113 if (holdTimer ) {
113114 clearTimeout (holdTimer )
114115 holdTimer = null
@@ -117,22 +118,24 @@ const stopAction = () => {
117118 action .value = undefined
118119}
119120
120- const editMessage = (e : MouseEvent , id : string , senderID : string , prev : string ) => {
121+ function editMessage(e : MouseEvent , id : string , senderID : string , prev : string ) {
121122 if (senderID !== z .userID && ! e .shiftKey ) {
123+ // eslint-disable-next-line no-alert
122124 alert (
123125 ' You aren\' t logged in as the sender of this message. Editing won\' t be permitted. Hold the shift key to try anyway.' ,
124126 )
125127 return
126128 }
129+
130+ // eslint-disable-next-line no-alert
127131 const body = prompt (' Edit message' , prev )
128132 z .mutate .message .update ({
129133 id ,
130134 body: body ?? prev ,
131135 })
132136}
133137
134- const jwt = Cookies .get (' jwt' )
135- const toggleLogin = async () => {
138+ async function toggleLogin() {
136139 if (z .userID === ' anon' ) {
137140 await fetch (' /api/login' )
138141 }
0 commit comments