Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
alert code
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLPircy committed Jun 1, 2024
1 parent 754be04 commit 0a66be1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/_components/_rhs/BetterIDEa.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import React, { useEffect, useState } from "react";
import {
useAlertStore,
useCodeStore,
useMessagesArrayStore,
usePidStore,
Expand All @@ -13,6 +14,7 @@ const BetterIDEa = () => {
const curCode = useCodeStore((state) => state.curCode);
const setMessArr = useMessagesArrayStore((state) => state.setMessArr);
const setCurPid = usePidStore((state) => state.setCurPid);
const setAlert = useAlertStore((state) => state.setAlert);
const [newMes, setNewMes] = useState("");

useEffect(() => {
Expand Down Expand Up @@ -61,6 +63,7 @@ const BetterIDEa = () => {
console.log("message new", "test\n", m);
// setNewMes(m);
if (m[0].Output.print) {
setAlert(true);
alert("You have new Message!");
}
}}
Expand Down
36 changes: 35 additions & 1 deletion app/_components/_rhs/MessagesDD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@ import React, { useState, useEffect } from "react";
import { brandLightText } from "../../_utils/colors";
import { getInbox } from "@betteridea/codecell";
import Image from "next/image";
import { useMessagesArrayStore, usePidStore } from "../../_store/store";
import {
useAlertStore,
useMessagesArrayStore,
usePidStore,
} from "../../_store/store";

const MessagesDD = () => {
const [mesToggle, setMesToggle] = useState(false);
const [notif, setNotif] = useState(false);
const messArr = useMessagesArrayStore((state) => state.messArr);
const curPid = usePidStore((state) => state.curPid);
const alert = useAlertStore((state) => state.alert);
const setAlert = useAlertStore((state) => state.setAlert);

useEffect(() => {
getInbox("1", true);
}, []);

useEffect(() => {
console.log("alert effecvt triggere", alert);
if (!mesToggle && alert) {
getInbox("1", true);
setNotif(true);
}
}, [alert]);

useEffect(() => {
if (mesToggle) {
setAlert(false);
}
}, [mesToggle]);

const stripAnsiCodes = (str: string) => {
return str?.replace(
Expand Down Expand Up @@ -55,6 +80,15 @@ const MessagesDD = () => {
className={`${mesToggle ? "rotate-180" : "rotate-0"}`}
/>
)}
{notif && (
<Image
src="/alert.png"
width={15}
height={21}
alt="dd"
// className={`${mesToggle ? "rotate-180" : "rotate-0"}`}
/>
)}
</div>
{curPid && (
<Image
Expand Down
9 changes: 9 additions & 0 deletions app/_store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ interface PidState {
setCurPid: (newPid: string) => void;
}

interface AlertState {
alert: boolean;
setAlert: (newAlert: boolean) => void;
}

export const useTutorialStore = create<TutorialState>()((set) => ({
curTutorial: "GET Request",
// increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
Expand All @@ -39,3 +44,7 @@ export const usePidStore = create<PidState>()((set) => ({
curPid: "",
setCurPid: (newPid) => set({ curPid: newPid }),
}));
export const useAlertStore = create<AlertState>()((set) => ({
alert: false,
setAlert: (newAlert) => set({ alert: newAlert }),
}));
Binary file added public/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0a66be1

Please sign in to comment.