• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EcrituresNumeriques / stylo / 15066626824

16 May 2025 10:41AM UTC coverage: 37.574% (-0.02%) from 37.594%
15066626824

Pull #1517

github

web-flow
Merge e05a1c169 into 607ffe7f9
Pull Request #1517: Mise à jour vers react-router@7

549 of 776 branches covered (70.75%)

Branch coverage included in aggregate %.

13 of 373 new or added lines in 28 files covered. (3.49%)

5 existing lines in 4 files now uncovered.

5319 of 14841 relevant lines covered (35.84%)

2.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/front/src/components/Annotate.jsx
1
import React, { useEffect, useMemo } from 'react'
×
NEW
2
import { useParams } from 'react-router'
×
3
import { Helmet } from 'react-helmet'
×
4

5
import Loading from './molecules/Loading.jsx'
×
6

7
import { useStyloExportPreview } from '../hooks/stylo-export.js'
×
8

9
import { toYaml } from './Write/metadata/yaml.js'
×
10
import useFetchData from '../hooks/graphql.js'
×
11
import { applicationConfig } from '../config.js'
×
12

13
import { getArticle } from './Article.graphql'
×
14
import { getCorpus } from './corpus/Corpus.graphql'
×
15

16
import './Annotate.scss'
×
17

18
const strategies = new Map([
×
19
  [
×
20
    'article',
×
21
    {
×
22
      query({ id, version, workspaceId }) {
×
23
        const hasVersion = Boolean(version)
×
24

25
        return {
×
26
          query: getArticle,
×
27
          variables: {
×
28
            id,
×
29
            version: hasVersion ? version : 'dummy',
×
30
            hasVersion,
×
31
          },
×
32
        }
×
33
      },
×
34
      mapContent(data) {
×
35
        const root = data?.article?.workingVersion ?? data?.version
×
36
        return {
×
37
          md_content: root?.md,
×
38
          yaml_content: root?.yaml,
×
39
          bib_content: root?.bib,
×
40
        }
×
41
      },
×
42
      title(data) {
×
43
        const root = data?.article?.workingVersion ?? data?.version
×
44
        return root.title ?? root.name
×
45
      },
×
46
    },
×
47
  ],
×
48
  [
×
49
    'corpus',
×
50
    {
×
51
      query({ id, workspaceId }) {
×
52
        return {
×
53
          query: getCorpus,
×
54
          variables: {
×
55
            includeWorkingVersion: true,
×
56
            includeArticles: true,
×
57
            filter: {
×
58
              corpusId: id,
×
59
              workspaceId,
×
60
            },
×
61
          },
×
62
        }
×
63
      },
×
64
      mapContent(data) {
×
65
        return data?.corpus?.at(0)?.articles?.reduce(
×
66
          (obj, { article }, index) => ({
×
67
            md_content: obj.md_content + '\n\n\n' + article.workingVersion.md,
×
68
            yaml_content:
×
69
              index === 0
×
70
                ? toYaml(data.corpus.medatada) +
×
71
                  '\n\n---\n\n' +
×
72
                  article.workingVersion.yaml
×
73
                : obj.yaml_content +
×
74
                  '\n\n---\n\n' +
×
75
                  article.workingVersion.yaml,
×
76
            bib_content:
×
77
              obj.bib_content + '\n\n---\n\n' + article.workingVersion.bib,
×
78
          }),
×
79
          {
×
80
            md_content: '',
×
81
            yaml_content: '',
×
82
            bib_content: '',
×
83
          }
×
84
        )
×
85
      },
×
86
      title(data) {
×
87
        return data?.corpus?.at(0).name
×
88
      },
×
89
    },
×
90
  ],
×
91
])
×
92

93
export default function Annotate({ strategy: strategyId }) {
×
94
  const { id, version, workspaceId } = useParams()
×
95
  const { canonicalBaseUrl } = applicationConfig
×
96
  const canonicalUrl = canonicalBaseUrl
×
97
    ? `${canonicalBaseUrl}/api/v1/${
×
98
        strategyId === 'article'
×
99
          ? version
×
100
            ? 'htmlVersion'
×
101
            : 'htmlArticle'
×
102
          : 'htmlBook'
×
103
      }/${version ?? id}?preview=true`
×
104
    : null
×
105

106
  const strategy = useMemo(
×
107
    () => strategies.get(strategyId),
×
108
    [id, version, strategyId]
×
109
  )
×
110

111
  if (!strategy) {
×
112
    throw Error('Unknown query mapping. Cannot preview this content.')
×
113
  }
×
114

115
  useEffect(() => {
×
116
    globalThis.hypothesisConfig = function hypothesisConfig() {
×
117
      return {
×
118
        // enableExperimentalNewNoteButton: true,
119
        openSidebar: true,
×
120
        // theme: 'clean',
121
        // contentReady: Promise
122
        /*branding: {
123
          appBackgroundColor: 'white',
124
          ctaBackgroundColor: 'rgba(3, 11, 16, 1)',
125
          ctaTextColor: '#eee',
126
          selectionFontFamily: 'helvetica, arial, sans serif'
127
        }*/
128
      }
×
129
    }
×
130

131
    const script = document.createElement('script')
×
132
    script.src = 'https://hypothes.is/embed.js'
×
133
    script.async = true
×
134
    document.body.appendChild(script)
×
135

136
    return () => document.body.removeChild(script)
×
137
  }, [])
×
138

139
  const { data, isLoading: isDataLoading } = useFetchData(
×
140
    strategy.query({ id, version, workspaceId }),
×
141
    {
×
142
      revalidateOnFocus: false,
×
143
      revalidateOnReconnect: false,
×
144
    }
×
145
  )
×
146

147
  const { html: __html, isLoading: isPreviewLoading } = useStyloExportPreview({
×
148
    ...strategy.mapContent(data),
×
149
    with_toc: true,
×
150
    with_nocite: true,
×
151
    with_link_citations: true,
×
152
  })
×
153

154
  const isLoading = useMemo(
×
155
    () => isPreviewLoading || isDataLoading,
×
156
    [isPreviewLoading, isDataLoading]
×
157
  )
×
158

159
  if (isLoading) {
×
160
    return <Loading />
×
161
  }
×
162

163
  return (
×
164
    <>
×
165
      <Helmet>
×
166
        <meta name="robots" content="noindex, nofollow" />
×
167
        <title>{strategy.title(data)}</title>
×
168
        {canonicalUrl && <link rel="canonical" href={canonicalUrl} />}
×
169
      </Helmet>
×
170

171
      <section dangerouslySetInnerHTML={{ __html }} />
×
172
    </>
×
173
  )
174
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc