Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
tachib-akiko committed Jan 7, 2023
1 parent ab8a246 commit 382790e
Show file tree
Hide file tree
Showing 8 changed files with 3,423 additions and 20 deletions.
3,384 changes: 3,384 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
"vue-tsc": "^1.0.11",
"windicss": "^3.5.6"
}
}
}
2 changes: 2 additions & 0 deletions src/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function listenEvent(

if (!typeCode) return

// eslint-disable-next-line n/no-callback-literal
cb({
type: typeCode,
code: event.data.code,
Expand All @@ -61,6 +62,7 @@ export function listenEvent(
return () => window.removeEventListener("message", handler)
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getTypeCode(code: any) {
if (code.startsWith("success.")) return "success"
if (code.startsWith("loading.")) return "loading"
Expand Down
1 change: 1 addition & 0 deletions src/client/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function useEmbed(el: HTMLIFrameElement | Ref<HTMLIFrameElement>) {
const loading = ref(false)
const error = ref(false)

// eslint-disable-next-line functional/no-let
let cancel: (() => void) | null = null

if (!isRef(el)) el = ref(el)
Expand Down
1 change: 1 addition & 0 deletions src/composibles/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function useQuery<T>(
query: {
...route.query,
[name]: v === defaultValue || v === null ? undefined : v,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as unknown as any,
})
})
Expand Down
4 changes: 4 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars, functional/no-let
let FB:
| {
XFBML: {
parse: () => void
}
Event: {
// eslint-disable-next-line functional/no-method-signature
clear(): void
// eslint-disable-next-line functional/no-method-signature
unsubscribe(name?: string): void
// eslint-disable-next-line functional/no-method-signature
subscribe(name: string, cb: () => void)
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/logic/load-fb-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// eslint-disable-next-line functional/no-let
let sdkLoaded = false

export function loadFBSdk(lang: string, force?: boolean) {
if (force) {
sdkLoaded = false
window.FB?.Event.clear()
window.FB = undefined
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(window as unknown as any).FB?.Event.clear()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(window as unknown as any).FB = undefined
}

if (sdkLoaded) return
Expand Down
42 changes: 25 additions & 17 deletions src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@
data-width="100%"
/>

<Loader v-if="typeCode === 'loading'" :code="code" />
<Error v-if="typeCode === 'error'" :code="code" />
<Loader v-if="typeCode === 'loading'" :code="code!" />
<Error v-if="typeCode === 'error'" :code="code!" />
</template>

<script lang="ts" setup>
import { useEventListener } from "@vueuse/core"
import Error from "src/components/Error.vue"
import Loader from "src/components/Loader.vue"
import { useQuery } from "src/composibles/useQuery"
import { watch, ref, computed } from "vue"
import { loadFBSdk } from "src/logic/load-fb-sdk"
import { useNavigatorLanguage, useEventListener } from "@vueuse/core"
import {
Param_res__fb_set_value,
Param__req__fb_set_value,
import type {
CODES,
Param__emit__fb_embed,
Param_res__fb_set_value,
} from "src/constants"
import {
ERROR_CODES,
LOADING_CODES,
SET_VAL_CODES,
SUCCESS_CODES,
} from "src/constants"
import Loader from "src/components/Loader.vue"
import Error from "src/components/Error.vue"
import { loadFBSdk } from "src/logic/load-fb-sdk"
import { computed, ref, watch } from "vue"
const code = ref<CODES | null>(null)
const typeCode = computed<"success" | "loading" | "error" | null>(() => {
Expand Down Expand Up @@ -72,7 +75,7 @@ const numPosts = useQuery("num_posts", 10, (v) => {
if (Number.isNaN(n)) return
return n
}) //ref(10)
}) // ref(10)
const orderBy = useQuery<"time" | "reverse_time">(
"order_by",
"reverse_time",
Expand Down Expand Up @@ -108,7 +111,7 @@ function sendSetValFailed(prop: string) {
const res: Param_res__fb_set_value = {
type: "res::fb:set_value",
// prop,
code: ERROR_CODES.ERROR_INVALID_PROP,
code: SET_VAL_CODES.ERROR_INVALID_PROP,
data: prop,
}
;(window.parent || window.top)?.postMessage(res, origin.value)
Expand Down Expand Up @@ -139,6 +142,7 @@ useEventListener(
if (event.data?.type !== "req::fb:set_value") return
const { prop } = event.data
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const val = event.data.val as any
switch (prop) {
case "color_scheme":
Expand Down Expand Up @@ -198,12 +202,15 @@ watch(
return sendSetValFailed(ERROR_CODES.ERROR_PARAMS_HREF_NOT_EXISTS)
sendCodeState(LOADING_CODES.LOADING_LOADING_PLUGIN)
window.FB!.Event.unsubscribe("xfbml.render")
window.FB!.Event.subscribe("xfbml.render", () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion
;(window as unknown as any).FB!.Event.unsubscribe("xfbml.render")
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion
;(window as unknown as any).FB!.Event.subscribe("xfbml.render", () => {
sendCodeState(SUCCESS_CODES.SUCCESS_DONE)
})
window.FB!.XFBML.parse()
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion
;(window as unknown as any).FB!.XFBML.parse()
} catch (err) {
console.error("load FB SDK failed")
sendCodeState(ERROR_CODES.ERROR_LOAD_SDK_FAILED)
Expand Down Expand Up @@ -235,9 +242,10 @@ watch(
}
*/
watch([colorScheme, href /*, lazy*/, mobile, numPosts, orderBy], () => {
watch([colorScheme, href /*, lazy */, mobile, numPosts, orderBy], () => {
if (!href.value)
return sendSetValFailed(ERROR_CODES.ERROR_PARAMS_HREF_NOT_EXISTS)
window.FB?.XFBML.parse()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(window as unknown as any).FB?.XFBML.parse()
})
</script>

0 comments on commit 382790e

Please sign in to comment.