@mirai/core 0.1.76 → 0.1.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -22,7 +22,9 @@ const Notifications = () => {
|
|
|
22
22
|
const [, setTimestamp] = (0, _react.useState)();
|
|
23
23
|
const {
|
|
24
24
|
value: {
|
|
25
|
-
session
|
|
25
|
+
session: {
|
|
26
|
+
authorization
|
|
27
|
+
} = {}
|
|
26
28
|
}
|
|
27
29
|
} = (0, _dataSources.useStore)();
|
|
28
30
|
(0, _react.useEffect)(() => {
|
|
@@ -32,7 +34,7 @@ const Notifications = () => {
|
|
|
32
34
|
}, []);
|
|
33
35
|
(0, _react.useEffect)(() => {
|
|
34
36
|
queue = {};
|
|
35
|
-
}, [
|
|
37
|
+
}, [authorization]);
|
|
36
38
|
const handleAdd = notification => {
|
|
37
39
|
if (!notification) return;
|
|
38
40
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Core.Notifications.js","names":["EVENT_NAME","queue","Notifications","translate","useLocale","setTimestamp","useState","value","session","useStore","useEffect","Event","subscribe","handleAdd","unsubscribe","notification","success","warning","id","Date","getTime","Math","random","toFixed","visible","forceRender","setTimeout","parseMotion","handleClose","motionExpand","Theme","get","parseFloat","replace","keys","Object","style","notifications","sort","map","key","index","defaultMessage","props","styles","item","zIndex","length","displayName","propTypes"],"sources":["../src/Core.Notifications.jsx"],"sourcesContent":["import { Event, useStore } from '@mirai/data-sources';\nimport { useLocale } from '@mirai/locale';\nimport { Notification, styles, Theme, View } from '@mirai/ui';\nimport React, { useEffect, useState } from 'react';\n\nimport style from './Core.Notifications.module.css';\n\nconst EVENT_NAME = 'notification';\nlet queue = {};\n\nconst Notifications = () => {\n const { translate } = useLocale();\n const [, setTimestamp] = useState();\n const {\n value: { session },\n } = useStore();\n\n useEffect(() => {\n Event.subscribe(EVENT_NAME, handleAdd);\n return () => Event.unsubscribe(EVENT_NAME, handleAdd);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n queue = {};\n }, [
|
|
1
|
+
{"version":3,"file":"Core.Notifications.js","names":["EVENT_NAME","queue","Notifications","translate","useLocale","setTimestamp","useState","value","session","authorization","useStore","useEffect","Event","subscribe","handleAdd","unsubscribe","notification","success","warning","id","Date","getTime","Math","random","toFixed","visible","forceRender","setTimeout","parseMotion","handleClose","motionExpand","Theme","get","parseFloat","replace","keys","Object","style","notifications","sort","map","key","index","defaultMessage","props","styles","item","zIndex","length","displayName","propTypes"],"sources":["../src/Core.Notifications.jsx"],"sourcesContent":["import { Event, useStore } from '@mirai/data-sources';\nimport { useLocale } from '@mirai/locale';\nimport { Notification, styles, Theme, View } from '@mirai/ui';\nimport React, { useEffect, useState } from 'react';\n\nimport style from './Core.Notifications.module.css';\n\nconst EVENT_NAME = 'notification';\nlet queue = {};\n\nconst Notifications = () => {\n const { translate } = useLocale();\n const [, setTimestamp] = useState();\n const {\n value: { session: { authorization } = {} },\n } = useStore();\n\n useEffect(() => {\n Event.subscribe(EVENT_NAME, handleAdd);\n return () => Event.unsubscribe(EVENT_NAME, handleAdd);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n queue = {};\n }, [authorization]);\n\n const handleAdd = (notification) => {\n if (!notification) return;\n\n const { success, warning } = notification;\n const id = `${new Date().getTime()}:${Math.random().toFixed(8)}`;\n\n queue[id] = { ...notification, visible: false };\n forceRender();\n\n setTimeout(() => {\n queue[id].visible = true;\n forceRender();\n }, parseMotion());\n\n if (success || warning) setTimeout(() => handleClose(id), success ? 5000 : 10000);\n\n return;\n };\n\n const handleClose = (id) => {\n if (!queue[id]) return;\n\n setTimestamp(() => {\n queue[id].visible = false;\n\n setTimeout(() => {\n delete queue[id];\n forceRender();\n }, parseMotion());\n\n return new Date().getTime();\n });\n };\n\n const forceRender = () => setTimestamp(new Date().getTime());\n\n const parseMotion = () => {\n const { motionExpand = '0.3s' } = Theme.get();\n\n return parseFloat(motionExpand.replace('s')) * 1000;\n };\n\n const keys = Object.keys(queue);\n\n return (\n <View className={style.notifications}>\n {keys.sort().map((key, index) => {\n const { defaultMessage, id, visible = false, ...props } = queue[key];\n\n return (\n <Notification\n {...props}\n key={key}\n wide\n onClose={() => handleClose(key)}\n className={styles(style.item, visible && style.visible)}\n style={{ zIndex: keys.length - index }}\n >\n {translate({ id, defaultMessage })}\n </Notification>\n );\n })}\n </View>\n );\n};\n\nNotifications.displayName = 'core:components:Notifications';\n\nNotifications.propTypes = {};\n\nexport { Notifications };\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAEA;AAAoD;AAAA;AAAA;AAAA;AAEpD,MAAMA,UAAU,GAAG,cAAc;AACjC,IAAIC,KAAK,GAAG,CAAC,CAAC;AAEd,MAAMC,aAAa,GAAG,MAAM;EAC1B,MAAM;IAAEC;EAAU,CAAC,GAAG,IAAAC,iBAAS,GAAE;EACjC,MAAM,GAAGC,YAAY,CAAC,GAAG,IAAAC,eAAQ,GAAE;EACnC,MAAM;IACJC,KAAK,EAAE;MAAEC,OAAO,EAAE;QAAEC;MAAc,CAAC,GAAG,CAAC;IAAE;EAC3C,CAAC,GAAG,IAAAC,qBAAQ,GAAE;EAEd,IAAAC,gBAAS,EAAC,MAAM;IACdC,kBAAK,CAACC,SAAS,CAACb,UAAU,EAAEc,SAAS,CAAC;IACtC,OAAO,MAAMF,kBAAK,CAACG,WAAW,CAACf,UAAU,EAAEc,SAAS,CAAC;IACrD;EACF,CAAC,EAAE,EAAE,CAAC;EAEN,IAAAH,gBAAS,EAAC,MAAM;IACdV,KAAK,GAAG,CAAC,CAAC;EACZ,CAAC,EAAE,CAACQ,aAAa,CAAC,CAAC;EAEnB,MAAMK,SAAS,GAAIE,YAAY,IAAK;IAClC,IAAI,CAACA,YAAY,EAAE;IAEnB,MAAM;MAAEC,OAAO;MAAEC;IAAQ,CAAC,GAAGF,YAAY;IACzC,MAAMG,EAAE,GAAI,GAAE,IAAIC,I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