Created
March 1, 2022 04:43
-
-
Save cindywu/f9101ce37016095959d1e10fa1cc19fb to your computer and use it in GitHub Desktop.
arrows.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { nanoid } from 'nanoid' | |
| import { z } from 'zod' | |
| const LOCAL_STORAGE_KEY = 'trunk-mini.item-arrows' | |
| export const draftArrow = z.object({ | |
| type: z.literal(`arrow`), | |
| id: z.string(), | |
| created_at: z.string(), | |
| created_by: z.string(), | |
| front_item_id: z.string(), | |
| back_item_id: z.string(), | |
| content: z.string(), | |
| highlight: z.string(), | |
| official: z.boolean(), | |
| to: z.number(), | |
| from: z.number(), | |
| parent_item_id: z.string(), | |
| kind: z.string(), | |
| }); | |
| export type Arrow = z.infer<typeof draftArrow>; | |
| export function updateArrows(arrows: Arrow[]) { | |
| localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(arrows)) | |
| } | |
| export function randomArrow() { | |
| return { | |
| type: 'arrow', | |
| id: nanoid(), | |
| created_at: new Date().toISOString(), | |
| created_by: '', | |
| front_item_id: '', | |
| back_item_id: '', | |
| content: '<p></p>', | |
| highlight: '<p></p>', | |
| official: false, | |
| to: 0, | |
| from: 0, | |
| parent_item_id: '', | |
| kind: '', | |
| } as Arrow; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment