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
DROP PROCEDURE IF EXISTS getLogsForModule; | |
DELIMITER $$ | |
CREATE PROCEDURE getLogsForModule(module VARCHAR(255)) | |
BEGIN | |
-- on doit passer par un concat car le nom d'une table doit être statique | |
SET @request = CONCAT("SELECT l.*, i.*, c.*, category_path(c.category) as category_path, u.* | |
FROM mdl_logstore_standard_log l | |
LEFT OUTER JOIN mdl_", module, " i ON i.id = l.objectid | |
LEFT OUTER JOIN mdl_course c ON c.id = l.courseid |
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
// Message.ts | |
export type TextMessage = { | |
text: string; | |
} | |
export type ImageMessage = { | |
mimeType: string; | |
url: string; | |
description: string; | |
} |
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
// Message.ts | |
export type Message = TextMessage | ImageMessage | AudioMessage; |
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 { Message } from ‘./Message’ | |
function renderMessage(message: Message) { | |
if (message.text) { | |
// ok we know it’s a TextMessage | |
return <TextComponent text={message.text} /> | |
} | |
if (message.url) { | |
// Problem! |
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
export type TextMessage = { | |
messageType: 'TEXT'; | |
... | |
} | |
export type ImageMessage = { | |
messageType: 'IMAGE'; | |
... | |
} |
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
function renderMessage(message: Message) { | |
if (message.messageType === 'TEXT') { | |
// message is typed as TextMessage here | |
return <TextComponent text={message.text} /> | |
} | |
if (message.messageType === 'IMAGE') { | |
// message is typed as ImageMessage here | |
return <ImageComponent url={message.url} description={message.description} /> | |
} |
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
// If this function returns true, TS will know the message variable is a TextMessage | |
function isText(message: Message): message is TextMessage { | |
return message.messageType === ‘TEXT’; | |
} | |
// Repeat for isImage and isAudio |
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
if (isText(message)) { | |
return <TextComponent text={message.text} /> | |
} |
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 { Option, fold } from ‘fp-ts/lib/Option`; | |
const user: Option<User> = … // ie. None | Some<User> | |
return fold( | |
() => <p>oops, no user!</p>, | |
(user: User) => <UserView user={user} />, | |
)(user); |
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
// Message.ts | |
function fold<R>( | |
onText: (message: TextMessage) => R, | |
onImage: (message: ImageMessage) => R, | |
onAudio: (message: AudioMessage) => R, | |
) => { | |
return (message: Message): R => { | |
switch (message.messageType) { | |
case ‘TEXT’: | |
return onText(message); |