Set new chat settings via URI
This commit is contained in:
		
							parent
							
								
									86211b0910
								
							
						
					
					
						commit
						85c5587a9f
					
				| 
						 | 
					@ -1,13 +1,19 @@
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
  import { querystring } from 'svelte-spa-router'
 | 
					  import { querystring } from 'svelte-spa-router'
 | 
				
			||||||
  import { addChat } from './Storage.svelte'
 | 
					  import { addChat, setChatSettingValueByKey } from './Storage.svelte'
 | 
				
			||||||
  import { replace } from 'svelte-spa-router'
 | 
					  import { replace } from 'svelte-spa-router'
 | 
				
			||||||
  import { getProfile } from './Profiles.svelte'
 | 
					  import { getProfile } from './Profiles.svelte'
 | 
				
			||||||
 | 
					  import { getChatDefaults } from './Settings.svelte'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Create the new chat instance then redirect to it
 | 
					  // Create the new chat instance then redirect to it
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const urlParams: URLSearchParams = new URLSearchParams($querystring)
 | 
					  const urlParams: URLSearchParams = new URLSearchParams($querystring)
 | 
				
			||||||
  const chatId = urlParams.has('p') ? addChat(getProfile(urlParams.get('p') || '')) : addChat()
 | 
					  const chatId = urlParams.has('p') ? addChat(getProfile(urlParams.get('p') || '')) : addChat()
 | 
				
			||||||
 | 
					  Object.keys(getChatDefaults()).forEach(k => {
 | 
				
			||||||
 | 
					    if (urlParams.has(k)) {
 | 
				
			||||||
 | 
					      setChatSettingValueByKey(chatId, k as any, urlParams.get(k))
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  replace(`/chat/${chatId}`)
 | 
					  replace(`/chat/${chatId}`)
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue