feat: add snapshot to /edit/profile and /edit/member/:id
This commit is contained in:
		
							parent
							
								
									3442f7a518
								
							
						
					
					
						commit
						c866cbb939
					
				
					 2 changed files with 105 additions and 2 deletions
				
			
		|  | @ -36,7 +36,7 @@ | |||
|   import EditableName from "../../EditableName.svelte"; | ||||
|   import EditablePronouns from "../../EditablePronouns.svelte"; | ||||
|   import ErrorAlert from "$lib/components/ErrorAlert.svelte"; | ||||
|   import type { PageData } from "./$types"; | ||||
|   import type { PageData, Snapshot } from "./$types"; | ||||
|   import { addToast, delToast } from "$lib/toast"; | ||||
|   import { memberNameRegex } from "$lib/api/regex"; | ||||
|   import { charCount, renderMarkdown } from "$lib/utils"; | ||||
|  | @ -372,6 +372,56 @@ | |||
|   const toggleDeleteOpen = () => (deleteOpen = !deleteOpen); | ||||
|   let deleteName = ""; | ||||
|   let deleteError: APIError | null = null; | ||||
| 
 | ||||
|   interface SnapshotData { | ||||
|     bio: string; | ||||
|     name: string; | ||||
|     display_name: string; | ||||
|     links: string[]; | ||||
|     names: FieldEntry[]; | ||||
|     pronouns: Pronoun[]; | ||||
|     fields: Field[]; | ||||
|     flags: PrideFlag[]; | ||||
|     unlisted: boolean; | ||||
| 
 | ||||
|     avatar: string | null; | ||||
|     newName: string; | ||||
|     newPronouns: string; | ||||
|     newLink: string; | ||||
|   } | ||||
| 
 | ||||
|   export const snapshot: Snapshot<SnapshotData> = { | ||||
|     capture: () => ({ | ||||
|       bio, | ||||
|       name, | ||||
|       display_name, | ||||
|       links, | ||||
|       names, | ||||
|       pronouns, | ||||
|       fields, | ||||
|       flags, | ||||
|       unlisted, | ||||
|       avatar, | ||||
|       newName, | ||||
|       newPronouns, | ||||
|       newLink, | ||||
|     }), | ||||
|     restore: (value) => { | ||||
|       bio = value.bio | ||||
|       name = value.name | ||||
|       display_name = value.display_name | ||||
|       links = value.links | ||||
|       names = value.names | ||||
|       pronouns = value.pronouns | ||||
|       fields = value.fields | ||||
|       flags = value.flags | ||||
|       unlisted = value.unlisted | ||||
|       avatar = value.avatar | ||||
|       newName = value.newName | ||||
|       newPronouns = value.newPronouns | ||||
|       newLink = value.newLink | ||||
|     }, | ||||
|   }; | ||||
| </script> | ||||
| 
 | ||||
| <svelte:head> | ||||
|  |  | |||
|  | @ -35,7 +35,7 @@ | |||
|   import EditablePronouns from "../EditablePronouns.svelte"; | ||||
|   import ErrorAlert from "$lib/components/ErrorAlert.svelte"; | ||||
|   import { addToast, delToast } from "$lib/toast"; | ||||
|   import type { PageData } from "./$types"; | ||||
|   import type { PageData, Snapshot } from "./$types"; | ||||
|   import { charCount, renderMarkdown } from "$lib/utils"; | ||||
|   import MarkdownHelp from "../MarkdownHelp.svelte"; | ||||
|   import prettyBytes from "pretty-bytes"; | ||||
|  | @ -378,6 +378,59 @@ | |||
|       delToast(toastId); | ||||
|     } | ||||
|   }; | ||||
| 
 | ||||
|   interface SnapshotData { | ||||
|     bio: string; | ||||
|     display_name: string; | ||||
|     member_title: string; | ||||
|     links: string[]; | ||||
|     names: FieldEntry[]; | ||||
|     pronouns: Pronoun[]; | ||||
|     fields: Field[]; | ||||
|     flags: PrideFlag[]; | ||||
|     list_private: boolean; | ||||
|     custom_preferences: CustomPreferences; | ||||
| 
 | ||||
|     avatar: string | null; | ||||
|     newName: string; | ||||
|     newPronouns: string; | ||||
|     newLink: string; | ||||
|   } | ||||
| 
 | ||||
|   export const snapshot: Snapshot<SnapshotData> = { | ||||
|     capture: () => ({ | ||||
|       bio, | ||||
|       display_name, | ||||
|       member_title, | ||||
|       links, | ||||
|       names, | ||||
|       pronouns, | ||||
|       fields, | ||||
|       flags, | ||||
|       list_private, | ||||
|       custom_preferences, | ||||
|       avatar, | ||||
|       newName, | ||||
|       newPronouns, | ||||
|       newLink, | ||||
|     }), | ||||
|     restore: (value) => { | ||||
|       bio = value.bio; | ||||
|       display_name = value.display_name; | ||||
|       member_title = value.member_title; | ||||
|       links = value.links; | ||||
|       names = value.names; | ||||
|       pronouns = value.pronouns; | ||||
|       fields = value.fields; | ||||
|       flags = value.flags; | ||||
|       list_private = value.list_private; | ||||
|       custom_preferences = value.custom_preferences; | ||||
|       avatar = value.avatar; | ||||
|       newName = value.newName; | ||||
|       newPronouns = value.newPronouns; | ||||
|       newLink = value.newLink; | ||||
|     }, | ||||
|   }; | ||||
| </script> | ||||
| 
 | ||||
| <svelte:head> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue