import { Button, Heading, HStack, Input, VStack } from "@hope-ui/solid" import { Component, createSignal, For, onCleanup } from "solid-js" import { createStore, produce } from "solid-js/store" import { Dynamic } from "solid-js/web" import { useFetch, useT } from "~/hooks" import { PEmptyResp, PResp } from "~/types" import { handleRespWithNotifySuccess, handleRespWithoutNotify, notify, r, } from "~/utils" import { StringShow, ImageShow } from "./Show" export interface Message { type: string content: any } export const Shower: Record> = { string: StringShow, image: ImageShow, } export const Messenger = () => { const t = useT() notify.info(t("manage.messenger-tips")) const [toSend, setToSend] = createSignal("") const [getLoading, getR] = useFetch( (): PResp => r.post("/admin/message/get"), ) const [sendLoading, sendR] = useFetch( (): PEmptyResp => r.post("/admin/message/send", { message: toSend(), }), ) const [received, setReceived] = createStore([]) const get = async () => { const resp = await getR() handleRespWithoutNotify(resp, (msg) => { setReceived(produce((msgs) => msgs.push(msg))) }) } const send = async () => { const resp = await sendR() handleRespWithNotifySuccess(resp) } const getInterval = setInterval(get, 1000) onCleanup(() => clearInterval(getInterval)) return ( {t("manage.received_msgs")} {(item) => } setToSend(e.currentTarget.value)} /> ) } export default Messenger