Skip to content

Commit eb489af

Browse files
committed
feat(toast): added toast notifications
added toast notifications for controls to better notify users that action was taken.
1 parent 75b7a46 commit eb489af

File tree

6 files changed

+51
-2
lines changed

6 files changed

+51
-2
lines changed

.wxt/types/imports.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ declare global {
6161
const lazy: typeof import('solid-js')['lazy']
6262
const mapArray: typeof import('solid-js')['mapArray']
6363
const mergeProps: typeof import('solid-js')['mergeProps']
64+
const notification: typeof import('/Users/cmolisee/Documents/session-storage-hub/src/utils/utils')['notification']
6465
const observable: typeof import('solid-js')['observable']
6566
const on: typeof import('solid-js')['on']
6667
const onCleanup: typeof import('solid-js')['onCleanup']

package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@
100100
"@uiw/codemirror-theme-tokyo-night-storm": "^4.23.6",
101101
"@webext-core/messaging": "^2.1.0",
102102
"codemirror": "^6.0.1",
103-
"solid-js": "^1.9.3"
103+
"solid-js": "^1.9.3",
104+
"solid-toast": "^0.5.0"
104105
},
105106
"devDependencies": {
106107
"@semantic-release/changelog": "^6.0.3",

src/entrypoints/popup/popup.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import ViewGrid from '@/components/ViewGrid';
44
import { storage as wxtStorage } from '@wxt-dev/storage';
55
import Tooltip from '@/components/tooltip';
66
import { version } from '../../../package.json';
7+
import { Toaster } from 'solid-toast';
8+
import { notification } from '@/utils/utils';
79

810
function Popup() {
911
const { storage, setSessionStorageData, selectAllKeys, unselectAllKeys } = useStorage();
@@ -18,36 +20,44 @@ function Popup() {
1820
}
1921

2022
await extensionClipboard.setValue(dataToCopy)
23+
.then(() => notification('Session Storage Data Copied.'))
2124
.catch((error) => console.debug('Failed to set extensionClipboard:', error));
2225
}
2326

2427
const pasteCallback = async () => {
2528
const dataToPaste = await extensionClipboard.getValue()
29+
.then(() => notification('Session Storage Data Pasted.'))
2630
.catch((error) => console.debug('Failed to get extensionClipboard:', error));
2731

2832
await extensionMessenger.sendMessage('sendToBackground', dataToPaste)
33+
.then(() => notification('Session Storage on webpage has been updated.'))
2934
.catch((error) => console.debug(error));
3035
}
3136

3237
const addCallback = async () => {
3338
const newKey = new Date().getTime().toString();
3439
const dataToAdd = deepCopy(storage.sessionStorageData);
3540
Object.assign(dataToAdd, { [newKey]: '{}' });
41+
notification(`New key-value pair added with key: ${newKey}.`);
3642

3743
await extensionMessenger.sendMessage('sendToBackground', dataToAdd)
44+
.then(() => notification('Session Storage on webpage has been updated.'))
3845
.catch((error) => console.debug(error));
3946
}
4047

4148
const deleteCallback = async () => {
4249
const dataUpdate = deepCopy(storage.sessionStorageData);
50+
notification(`key: ${storage.activeKey} has been deleted.`);
4351
delete dataUpdate[storage.activeKey];
4452

4553
await extensionMessenger.sendMessage('sendToBackground', dataUpdate)
54+
.then(() => notification('Session Storage on webpage has been updated.'))
4655
.catch((error) => console.debug(error));
4756
}
4857

4958
const clearCallback = async () => {
5059
await extensionMessenger.sendMessage('sendToBackground', {})
60+
.then(() => notification('Session Storage has been cleared.'))
5161
.catch((error) => console.debug(error));
5262
}
5363

@@ -115,6 +125,7 @@ function Popup() {
115125
</div>
116126
</div>
117127
<ViewGrid />
128+
<Toaster />
118129
<div class={'flex m-1 justify-start text-[var(--borderColor)]'}>
119130
<div class={'cursor-default mr-4'}>
120131
{version}

src/hooks/useStorage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { IStorageContext, IStorageShape } from "@/types/hooks";
2+
import { notification } from "@/utils/utils";
23

34
const initialStorage: IStorageShape = {
45
sessionStorageData: {},
@@ -74,13 +75,15 @@ export const StorageProvider = (props: any) => {
7475
* Set selectedKeys in storage to array of all availalbe keys.
7576
*/
7677
const selectAllKeys = () => {
78+
notification('All keys selected.');
7779
setStore('selectedKeys', deepCopy(store.keys) );
7880
};
7981

8082
/**
8183
* Set selectedKeys in storage to empty array.
8284
*/
8385
const unselectAllKeys = () => {
86+
notification('All keys unselected.');
8487
setStore('selectedKeys', []);
8588
};
8689

src/utils/utils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import toast from "solid-toast";
2+
13
/**
24
* Merge css class strings together.
35
* Necessary for tailwind to properly build css since it cannot handle dynamic classes.
@@ -79,4 +81,26 @@ export function safeParse(obj: any, isLogging: boolean = false) {
7981
*/
8082
export function deepCopy(obj: any) {
8183
return safeParse(JSON.stringify(obj));
84+
}
85+
86+
/** Helper for displaying toast notifications. */
87+
export function notification(txt: string) {
88+
toast(txt, {
89+
duration: 3000,
90+
position: 'bottom-center',
91+
unmountDelay: 500,
92+
style: {
93+
'background-color': 'var(--specialTextColor)',
94+
'font-weight': 'bold',
95+
'color': 'var(--backgroundColor)'
96+
},
97+
iconTheme: {
98+
primary: '#fff',
99+
secondary: '#000',
100+
},
101+
ariaProps: {
102+
role: 'status',
103+
'aria-live': 'polite',
104+
},
105+
});
82106
}

0 commit comments

Comments
 (0)