Skip to content

Commit

Permalink
feat(Note): Show notification on note share
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruptein authored Jan 21, 2024
1 parent 09f4e03 commit 4ea74e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions client/src/core/components/toasts/SingleButtonToast.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
const emit = defineEmits(["close-toast"]);
const props = defineProps<{ text: string; onClick: () => Promise<void> }>();
const props = defineProps<{ text: string; buttonText?: string; onClick: () => Promise<void> }>();
async function action(): Promise<void> {
emit("close-toast");
Expand All @@ -11,7 +11,7 @@ async function action(): Promise<void> {
<template>
<div class="toast-container">
<span>{{ text }}</span>
<span class="action" @click.stop="action">USE</span>
<span class="action" @click.stop="action">{{ buttonText ?? "USE" }}</span>
</div>
</template>

Expand All @@ -24,6 +24,7 @@ async function action(): Promise<void> {
justify-content: space-between;
.action {
margin-left: 0.5rem;
padding: 5px;
background-color: white;
color: $vt-color-info;
Expand Down
26 changes: 25 additions & 1 deletion client/src/game/systems/notes/events.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
import { POSITION, useToast } from "vue-toastification";

import type { ApiNote, ApiNoteAccessEdit, ApiNoteSetBoolean, ApiNoteSetString, ApiNoteShape } from "../../../apiTypes";
import SingleButtonToastVue from "../../../core/components/toasts/SingleButtonToast.vue";
import { socket } from "../../api/socket";
import { getLocalId } from "../../id";

import { popoutNote } from "./ui";

import { noteSystem } from ".";

const toast = useToast();

socket.on("Notes.Set", async (notes: ApiNote[]) => {
for (const note of notes) await noteSystem.newNote(note, false);
});

socket.on("Note.Add", async (data: ApiNote) => await noteSystem.newNote(data, false));
socket.on("Note.Add", async (data: ApiNote) => {
await noteSystem.newNote(data, false);

toast.info(
{
component: SingleButtonToastVue,
props: {
text: `You were granted access to a note: ${data.title}`,
buttonText: "Open",
onClick: () => popoutNote(data.uuid),
},
},
{
position: POSITION.TOP_RIGHT,
timeout: 10_000,
},
);
});

socket.on("Note.Remove", (data: string) => noteSystem.removeNote(data, false));

Expand Down

0 comments on commit 4ea74e4

Please sign in to comment.