MCPcopy
hub / github.com/maxchehab/phelia / updateHome

Method updateHome

src/core/phelia.ts:272–331  ·  view source on GitHub ↗
(key: string)

Source from the content-addressed store, hash-verified

270 }
271
272 async updateHome(key: string) {
273 const rawMessageContainer = await Phelia.Storage.get(key);
274 if (!rawMessageContainer) {
275 throw TypeError(`Could not find a home app with key ${key}.`);
276 }
277
278 const container: PheliaMessageContainer = JSON.parse(rawMessageContainer);
279
280 /** A hook to create some state for a component */
281 function useState<t>(key: string): [t, (value: t) => void] {
282 return [
283 container.state[key],
284 (newState: t) => (container.state[key] = newState),
285 ];
286 }
287
288 /** A hook to create a modal for a component */
289 function useModal(): (title: string, props?: any) => Promise<void> {
290 return async () => null;
291 }
292
293 /** Run the onload callback */
294 await render(
295 React.createElement(this.homeComponent, {
296 useState,
297 useModal,
298 user: container.user,
299 }),
300 {
301 value: undefined,
302 event: { user: container.user },
303 type: "onupdate",
304 }
305 );
306
307 const home = await render(
308 React.createElement(this.homeComponent, {
309 useState,
310 useModal,
311 user: container.user,
312 })
313 );
314
315 await this.client.views.publish({
316 view: home,
317 user_id: container.user.id,
318 });
319
320 await Phelia.Storage.set(
321 container.viewID,
322 JSON.stringify({
323 message: JSON.stringify(home),
324 name: this.homeComponent.name,
325 state: container.state,
326 type: "home",
327 viewID: container.viewID,
328 user: container.user,
329 })

Callers

nothing calls this directly

Calls 1

renderFunction · 0.90

Tested by

no test coverage detected