]> Repos - mime-chat/commitdiff
undo button - not functional yet but gives a good idea of what will happen
authorAndrew Gundersen <gundersena@xavier.edu>
Wed, 31 Mar 2021 13:41:13 +0000 (08:41 -0500)
committerAndrew Gundersen <gundersena@xavier.edu>
Wed, 31 Mar 2021 13:41:13 +0000 (08:41 -0500)
13 files changed:
session.json
src/background/helpers.ts
src/background/init.ts
src/background/session.ts
src/background/window.ts
src/components/message.vue
src/modules/emitter.ts
src/modules/message.ts
src/modules/messages.ts
src/modules/mitt.ts
src/types.ts [moved from src/types/message/index.ts with 90% similarity]
src/types/mitt/index.ts [deleted file]
window.json

index 3a10d11baf8c11c941aa705a0dbf34829262cbe3..688a9c46b1a2e68774a37ecc851beef57aa1bd06 100644 (file)
@@ -1 +1 @@
-{"key":"854fb3e1-9207-473d-82b8-b6385f47e895","newMessages":[]}
\ No newline at end of file
+{"key":"6cde67f6-6188-452d-a54e-9d38cabf2d63","newMessages":[]}
\ No newline at end of file
index a124c4484cf7a1d64a9e73c2b73fe553429c9451..bd3d2792e700700f157fb7f092732d0e77f06add 100644 (file)
@@ -1,6 +1,6 @@
 import fs from 'fs';
 import { backgroundMitt } from "@/modules/emitter";
-import { SessionState, WindowState } from "@/types/message"; 
+import { SessionState, WindowState } from "@/types"; 
 
 
 export const ipcEmit = (channel: string, payload: any) => {
index 69a2938cfed8ab7f9be68470af2931cf9ddf837e..5b16e8f1e141120d5103898f96376e78dfda7d42 100644 (file)
@@ -37,9 +37,11 @@ export function initApp(dev: boolean): void {
       main()
     });
 
+    // Must keep to ensure app doesn't quit on close.
     app.on("before-quit", () => {
     });
 
+    // Must keep to ensure app doesn't quit on close.
     app.on("window-all-closed", () => {
     });
 
index 5c5ebb26f5bbe7fd7f6abe3c5c167fcc39507bd9..35773c8e92cbc2f8e6a489954d4c9d70fe8e8841 100644 (file)
@@ -16,7 +16,7 @@ import useWebSockets from "@/modules/websockets";
 
 import { play } from "./audio";
 import { renderMessage } from "@/modules/message";
-import { AuthProtocol, SessionState, Profile } from "@/types/message"; 
+import { AuthProtocol, SessionState, Profile } from "@/types"; 
 
 let win = true;
 
index 33afcccc21da67aaca5cf28678d7252123131a52..b344e80861747ffb50824d81435d9e79ab05a1e5 100644 (file)
@@ -3,10 +3,9 @@
 import { BrowserWindow, ipcMain } from "electron";
 import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
 import { backgroundMitt } from '@/modules/emitter';
-import { RenderMessage, WindowState } from "@/types/message/index";
+import { RenderMessage, WindowState } from "@/types";
 import { loadWinState, saveToJson } from "./helpers";
 import * as path from "path";
-import fs from 'fs';
 
 interface IpcRendererPayload {
   endpoint: string;
index b24e9c16b1a33b0d920befcec9ec03dd61b2da94..41e039ee9123a5f2f00bfd7f848f72ac2165db37 100644 (file)
       class="messageBox"
     >
 
+      <!-- Render undo button for messages to friends. -->
+      <button 
+        v-if="undoOption === true"
+        class="undoButton"
+      >
+        undo
+      </button>
+
       <!-- message bubble -->
       <div
         class="bubble"
       </div>
 
       <!-- message context -->
-      <span v-if="message.isChild === 'last' || message.isChild === 'none'" class="context">
+      <span 
+        v-if="message.isChild === 'last' || message.isChild === 'none'"
+        class="context"
+        :class="{ 'context-undo-anim': undoOption }"
+      >
 
         <!-- Render Crimata icon or friend's initials. -->
         <div v-if="message.modifier == 'ai'" class="photo">
@@ -86,9 +98,9 @@
 
 <script lang='ts'>
 
- import {defineComponent, ref, onMounted} from 'vue';
- import { RenderMessage } from "@/types/message/index";
-
+ import { defineComponent, ref, onMounted, onBeforeUpdate } from 'vue';
+ import { clientRequest } from "@/modules/message";
+ import { useIpc } from "@/modules/ipc";
 
  export default defineComponent({
   name: "MessageItem",
 
     let addListener = false;
 
+    const undoOption = ref(false);
+
     const notify = ref(false)
     const isPlaying = ref(false);
 
+    const { post } = useIpc()
+
     if (!props.message.seen) {
+      console.log("MSG:Checking...")
 
       // newMessages always render with blue dot.
       if (props.message.newMessage) {
       }
     }
 
+    const onUndo = () => {
+      post("client-message", clientRequest("launch", {name: false}, "undo"))
+    }
+
     const onStopPlayback = (e: any) => {
       window.ipcRenderer.removeAllListeners("stop-playback-anim");
       isPlaying.value = false
     }
 
+    onBeforeUpdate(() => {
+
+      if (props.message.context.substring(0, 3) === 'To ') {
+        console.log("MSG:Applying undo anim")
+        undoOption.value = true;
+      }
+      
+    })
+
     onMounted(() => {
 
       // Listen for window focus event.
     })
 
     return {
+      onUndo,
       notify,
-      isPlaying
+      isPlaying,
+      undoOption
     }
   }
 
   }
 
   .messageBox {
+    position: relative;
+
     display: flex;
     flex-direction: column;
 
   }
 
   .context {
+    position: relative;
+
     display: flex;
     align-items: center;
 
     margin-top: 5px;
   }
 
+  .context-undo-anim {
+    animation-name: context-anim;
+    animation-duration: 3s;
+  }
+
+  @keyframes context-anim {
+    0%, 90% {
+      transform: translateX(-45px);
+    }
+    100% {
+      transform: translateX(0px);
+    }
+  }
+
   .photo {
     display: flex;
     justify-content: center;
     color: #357CA2;
   }
 
-</style>
\ No newline at end of file
+  .undoButton {
+    position: absolute;
+
+    bottom: 0px;
+    right: 0px;
+
+    opacity: 0;
+
+    border: none;
+    outline: none;
+
+    margin: 0px;
+    padding: 0px;
+
+    background-color: Transparent;
+
+    font-family: "SF Compact Display";
+    font-size: 12px;
+    font-weight: bold;
+    color: #9B9B9B;
+
+    animation-name: undo-anim;
+    animation-duration: 3s;
+}
+
+.undoButton:hover {
+  cursor: pointer;
+}
+
+@keyframes undo-anim {
+  0%, 90% {
+    opacity: 1;
+  }
+  100% {
+    opacity: 0;
+  }
+}
+
+</style>
+<!-- 
+      // If this is a message to a friend, we render undo button.
+      if (props.message.context.substring(0, 3) === 'To ') {
+        console.log("MSG:Applying undo anim")
+        undoOption.value = true;
+      } -->
\ No newline at end of file
index 14aa77fd0f5349f9ef297a5e038ad1a90569db3a..bc916935d23bb3effd7e0011fd495c9670fb1697 100644 (file)
@@ -1,4 +1,11 @@
 /* eslint-disable */
+
+import { Emitter } from "mitt";
+
+// Backend emitter
+
+type Mitt = Emitter;
+
 const EventEmitter = require('events');
 
 class BackgroundMitt extends EventEmitter { }
index 9601f952ef60591543ae5190926b382d288a8ac8..80be1dd17aeed84cfbc7e9568ed1218a014c691f 100644 (file)
@@ -1,4 +1,4 @@
-import { RenderMessage, ClientMessage, AuthRequest, LogoutRequest } from "@/types/message/index";
+import { RenderMessage, ClientMessage, ClientRequest, AuthRequest, LogoutRequest } from "@/types";
 import { v4 as uuidv4 } from 'uuid';
 
 function getTimeStamp(): number {  
@@ -31,6 +31,15 @@ export const clientMessage = (text: string, audio: string | boolean, uid: string
   }
 )
 
+export const clientRequest = (intent: string, params: object, epic: string | boolean): ClientRequest => (
+  {
+    intent: intent,
+    params: params,
+    epic: epic,
+    confidence: 1.0
+  }
+)
+
 export const authRequest = (key: boolean | string, usr: boolean | string, pwd: boolean | string): AuthRequest => (
   {
     key,
index 0b89aaa54e27fdb35b6987f20f757d491d3b60ab..1d2c4b4c5dfd8dd96039223ddfd68629706d128d 100644 (file)
@@ -1,6 +1,6 @@
 import { ref } from 'vue';
 import useScroll from "@/modules/scroll";
-import { RenderMessage, Annotation } from "@/types/message/index";
+import { RenderMessage, Annotation } from "@/types";
 
 const messages = ref(new Map());
 
index 9804d0b1b640e56cae21517eb6d15d90d4629a3f..4f3f4481fabd34549aa922522e6f186b65baedd5 100644 (file)
@@ -1,5 +1,9 @@
 import { inject } from "vue";
-import { Mitt } from "@/types/mitt/index";
+import { Emitter } from "mitt";
+
+// Frontend emitter
+
+type Mitt = Emitter;
 
 let emitter: Mitt;
 
similarity index 90%
rename from src/types/message/index.ts
rename to src/types.ts
index eaf38452a0dd670da31159bd96bc16beca42ffda..d1826eeae615391c09fa3f41eef1b6da97e6c03c 100644 (file)
@@ -18,6 +18,13 @@ export interface ClientMessage {
     uid: string;
 }
 
+export interface ClientRequest {
+    intent: string, 
+    params: object,
+    epic: string | boolean,
+    confidence: number
+}
+
 export interface SessionState {
     key: string | boolean;
     newMessages: RenderMessage[];
diff --git a/src/types/mitt/index.ts b/src/types/mitt/index.ts
deleted file mode 100644 (file)
index a1ba637..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-import { Emitter } from "mitt";
-
-export type Mitt = Emitter;
index 16e3948f94cce3ed163f12a9948c2ca3a581a48a..a91e61100d5f1b5dfed018ce1855c4e29faf1cc8 100644 (file)
@@ -1 +1 @@
-{"width":386,"height":815,"x":1720,"y":495}
\ No newline at end of file
+{"width":609,"height":721,"x":1376,"y":517}
\ No newline at end of file